Issue #2072249 by tim.plunkett: Modernize aggregator.module forms.

8.0.x
webchick 2013-08-28 00:08:01 -07:00
parent 334703ac2b
commit 94f609ea16
7 changed files with 91 additions and 117 deletions

View File

@ -7,6 +7,7 @@
namespace Drupal\aggregator;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityFormControllerNG;
use Drupal\Core\Language\Language;
@ -16,24 +17,24 @@ use Drupal\Core\Language\Language;
class FeedFormController extends EntityFormControllerNG {
/**
* Overrides Drupal\Core\Entity\EntityFormController::form().
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$feed = $this->entity;
$period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
$period[AGGREGATOR_CLEAR_NEVER] = t('Never');
$period[AGGREGATOR_CLEAR_NEVER] = $this->t('Never');
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#title' => $this->t('Title'),
'#default_value' => $feed->label(),
'#maxlength' => 255,
'#description' => t('The name of the feed (or the name of the website providing the feed).'),
'#description' => $this->t('The name of the feed (or the name of the website providing the feed).'),
'#required' => TRUE,
);
$form['langcode'] = array(
'#title' => t('Language'),
'#title' => $this->t('Language'),
'#type' => 'language_select',
'#default_value' => $feed->language()->id,
'#languages' => Language::STATE_ALL,
@ -41,23 +42,23 @@ class FeedFormController extends EntityFormControllerNG {
$form['url'] = array(
'#type' => 'url',
'#title' => t('URL'),
'#title' => $this->t('URL'),
'#default_value' => $feed->url->value,
'#maxlength' => NULL,
'#description' => t('The fully-qualified URL of the feed.'),
'#description' => $this->t('The fully-qualified URL of the feed.'),
'#required' => TRUE,
);
$form['refresh'] = array('#type' => 'select',
'#title' => t('Update interval'),
'#title' => $this->t('Update interval'),
'#default_value' => $feed->refresh->value,
'#options' => $period,
'#description' => t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
'#description' => $this->t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
);
$form['block'] = array('#type' => 'select',
'#title' => t('News items in block'),
'#title' => $this->t('News items in block'),
'#default_value' => $feed->block->value,
'#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
'#description' => t("Drupal can make a block with the most recent news items of this feed. You can <a href=\"@block-admin\">configure blocks</a> to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in this feed's block. If you choose '0' this feed's block will be disabled.", array('@block-admin' => url('admin/structure/block'))),
'#description' => $this->t("Drupal can make a block with the most recent news items of this feed. You can <a href=\"@block-admin\">configure blocks</a> to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in this feed's block. If you choose '0' this feed's block will be disabled.", array('@block-admin' => url('admin/structure/block'))),
);
// Handling of categories.
@ -65,7 +66,7 @@ class FeedFormController extends EntityFormControllerNG {
$values = array();
$categories = db_query('SELECT c.cid, c.title FROM {aggregator_category} c ORDER BY title');
foreach ($categories as $category) {
$options[$category->cid] = check_plain($category->title);
$options[$category->cid] = String::checkPlain($category->title);
if (!empty($feed->categories) && in_array($category->cid, array_keys($feed->categories))) {
$values[] = $category->cid;
}
@ -74,10 +75,10 @@ class FeedFormController extends EntityFormControllerNG {
if ($options) {
$form['category'] = array(
'#type' => 'checkboxes',
'#title' => t('Categorize news items'),
'#title' => $this->t('Categorize news items'),
'#default_value' => $values,
'#options' => $options,
'#description' => t('New feed items are automatically filed in the checked categories.'),
'#description' => $this->t('New feed items are automatically filed in the checked categories.'),
);
}
@ -85,7 +86,7 @@ class FeedFormController extends EntityFormControllerNG {
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::validate().
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state) {
$feed = $this->buildEntity($form, $form_state);
@ -99,17 +100,17 @@ class FeedFormController extends EntityFormControllerNG {
foreach ($result as $item) {
if (strcasecmp($item->title, $feed->label()) == 0) {
form_set_error('title', t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
form_set_error('title', $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
}
if (strcasecmp($item->url, $feed->url->value) == 0) {
form_set_error('url', t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->url->value)));
form_set_error('url', $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->url->value)));
}
}
parent::validate($form, $form_state);
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
* {@inheritdoc}
*/
public function save(array $form, array &$form_state) {
$feed = $this->entity;
@ -121,7 +122,7 @@ class FeedFormController extends EntityFormControllerNG {
}
$feed->save();
if ($insert) {
drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $feed->label())));
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label())));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator';
}
@ -130,13 +131,13 @@ class FeedFormController extends EntityFormControllerNG {
}
}
else {
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $feed->label()), WATCHDOG_NOTICE, l(t('view'), 'admin/config/services/aggregator'));
drupal_set_message(t('The feed %feed has been added.', array('%feed' => $feed->label())));
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $feed->label()), WATCHDOG_NOTICE, l($this->t('view'), 'admin/config/services/aggregator'));
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label())));
}
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::delete().
* {@inheritdoc}
*/
public function delete(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/config/services/aggregator/delete/feed/' . $this->entity->id();

View File

@ -9,25 +9,14 @@ namespace Drupal\aggregator\Form;
use Drupal\aggregator\CategoryStorageControllerInterface;
use Drupal\block\Plugin\Type\BlockManager;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a form for configuring aggregator categories.
*/
class CategoryAdminForm implements FormInterface, ControllerInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection.
*/
protected $database;
class CategoryAdminForm extends FormBase {
/**
* The module handler.
@ -43,13 +32,6 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
*/
protected $categoryStorageController;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The block manager.
*
@ -60,8 +42,6 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
/**
* Creates a new CategoryForm object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\aggregator\CategoryStorageControllerInterface $category_storage_controller
@ -69,8 +49,7 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
* @param \Drupal\block\Plugin\Type\BlockManager $block_manager
* (optional) The block manager. Used if block module is enabled.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, CategoryStorageControllerInterface $category_storage_controller, BlockManager $block_manager = NULL) {
$this->database = $database;
public function __construct(ModuleHandlerInterface $module_handler, CategoryStorageControllerInterface $category_storage_controller, BlockManager $block_manager = NULL) {
$this->moduleHandler = $module_handler;
$this->categoryStorageController = $category_storage_controller;
$this->blockManager = $block_manager;
@ -85,7 +64,6 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
$block_manager = $container->get('plugin.manager.block');
}
return new static(
$container->get('database'),
$container->get('module_handler'),
$container->get('aggregator.category.storage'),
$block_manager
@ -102,30 +80,29 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $cid = NULL, Request $request = NULL) {
$this->request = $request;
public function buildForm(array $form, array &$form_state, $cid = NULL) {
$category = $this->categoryStorageController->load($cid);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#title' => $this->t('Title'),
'#default_value' => isset($category->title) ? $category->title : '',
'#maxlength' => 64,
'#required' => TRUE,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#title' => $this->t('Description'),
'#default_value' => isset($category->description) ? $category->description : '',
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#value' => $this->t('Save'),
);
if (!empty($category->cid)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#value' => $this->t('Delete'),
);
$form['cid'] = array('#type' => 'hidden', '#value' => $category->cid);
}
@ -137,7 +114,7 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
if ($form_state['values']['op'] == t('Save')) {
if ($form_state['values']['op'] == $this->t('Save')) {
// Check for duplicate titles.
$title = $form_state['values']['title'];
if (isset($form_state['values']['cid'])) {
@ -148,7 +125,7 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
$unique = $this->categoryStorageController->isUnique($title);
}
if (!$unique) {
form_set_error('title', t('A category named %category already exists. Enter a unique title.', array('%category' => $title)));
form_set_error('title', $this->t('A category named %category already exists. Enter a unique title.', array('%category' => $title)));
}
}
}
@ -165,7 +142,7 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
$title = $form_state['values']['title'];
// Redirect to a confirm delete form.
if ($form_state['values']['op'] == t('Delete')) {
if ($form_state['values']['op'] == $this->t('Delete')) {
$cid = $form_state['values']['cid'];
$form_state['redirect'] = 'admin/config/services/aggregator/delete/category/' . $cid;
return;
@ -175,8 +152,8 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
if (!empty($form_state['values']['cid'])) {
$cid = $form_state['values']['cid'];
$this->categoryStorageController->update((object) $form_state['values']);
drupal_set_message(t('The category %category has been updated.', array('%category' => $title)));
if (preg_match('/^\/admin/', $this->request->getPathInfo())) {
drupal_set_message($this->t('The category %category has been updated.', array('%category' => $title)));
if (preg_match('/^\/admin/', $this->getRequest()->getPathInfo())) {
$form_state['redirect'] = 'admin/config/services/aggregator/';
}
else {
@ -188,8 +165,8 @@ class CategoryAdminForm implements FormInterface, ControllerInterface {
// Insert the category.
$cid = $this->categoryStorageController->save((object) $form_state['values']);
watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/config/services/aggregator'));
drupal_set_message(t('The category %category has been added.', array('%category' => $title)));
watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l($this->t('view'), 'admin/config/services/aggregator'));
drupal_set_message($this->t('The category %category has been added.', array('%category' => $title)));
$this->updateMenuLink('insert', $link_path . $cid, $title);

View File

@ -79,7 +79,7 @@ class CategoryDeleteForm extends ConfirmFormBase implements ControllerInterface
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the category %title?', array('%title' => $this->category->title));
return $this->t('Are you sure you want to delete the category %title?', array('%title' => $this->category->title));
}
/**
@ -100,14 +100,14 @@ class CategoryDeleteForm extends ConfirmFormBase implements ControllerInterface
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('This will delete the aggregator category, the menu item for this category, and any related category blocks.');
return $this->t('This will delete the aggregator category, the menu item for this category, and any related category blocks.');
}
/**
@ -145,7 +145,7 @@ class CategoryDeleteForm extends ConfirmFormBase implements ControllerInterface
// Make sure there is no active block for this category.
$this->deleteBlocks($cid);
watchdog('aggregator', 'Category %category deleted.', array('%category' => $title));
drupal_set_message(t('The category %category has been deleted.', array('%category' => $title)));
drupal_set_message($this->t('The category %category has been deleted.', array('%category' => $title)));
if (preg_match('/^\/admin/', $this->getRequest()->getPathInfo())) {
$form_state['redirect'] = 'admin/config/services/aggregator/';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedDeleteForm.
@ -17,7 +18,7 @@ class FeedDeleteForm extends EntityNGConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the feed %feed?', array('%feed' => $this->entity->label()));
return $this->t('Are you sure you want to delete the feed %feed?', array('%feed' => $this->entity->label()));
}
/**
@ -31,7 +32,7 @@ class FeedDeleteForm extends EntityNGConfirmFormBase {
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
return $this->t('Delete');
}
/**
@ -40,7 +41,7 @@ class FeedDeleteForm extends EntityNGConfirmFormBase {
public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator';
}

View File

@ -18,7 +18,7 @@ class FeedItemsRemoveForm extends EntityNGConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $this->entity->label()));
return $this->t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $this->entity->label()));
}
/**
@ -32,7 +32,7 @@ class FeedItemsRemoveForm extends EntityNGConfirmFormBase {
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Remove items');
return $this->t('Remove items');
}
/**

View File

@ -7,11 +7,11 @@
namespace Drupal\aggregator\Form;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\aggregator\FeedStorageControllerInterface;
use Drupal\Component\Utility\Url;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Guzzle\Http\Exception\RequestException;
use Guzzle\Http\Exception\BadResponseException;
@ -20,7 +20,7 @@ use Guzzle\Http\Client;
/**
* Imports feeds from OPML.
*/
class OpmlFeedAdd implements ControllerInterface, FormInterface {
class OpmlFeedAdd extends FormBase {
/**
* The database connection object.
@ -37,11 +37,11 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
protected $queryFactory;
/**
* The entity manager.
* The feed storage.
*
* @var \Drupal\Core\Entity\EntityManager
* @var \Drupal\aggregator\FeedStorageControllerInterface
*/
protected $entityManager;
protected $feedStorage;
/**
* The HTTP client to fetch the feed data with.
@ -53,19 +53,19 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
/**
* Constructs a database object.
*
* @param \Drupal\Core\Database\Connection; $database
* @param \Drupal\Core\Database\Connection $database
* The database object.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query object.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
* @param \Guzzle\Http\Client
* @param \Drupal\aggregator\FeedStorageControllerInterface $feed_storage
* The feed storage.
* @param \Guzzle\Http\Client $http_client
* The Guzzle HTTP client.
*/
public function __construct(Connection $database, QueryFactory $query_factory, EntityManager $entity_manager, Client $http_client) {
public function __construct(Connection $database, QueryFactory $query_factory, FeedStorageControllerInterface $feed_storage, Client $http_client) {
$this->database = $database;
$this->queryFactory = $query_factory;
$this->entityManager = $entity_manager;
$this->feedStorage = $feed_storage;
$this->httpClient = $http_client;
}
@ -76,7 +76,7 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
return new static(
$container->get('database'),
$container->get('entity.query'),
$container->get('plugin.manager.entity'),
$container->get('plugin.manager.entity')->getStorageController('aggregator_feed'),
$container->get('http_default_client')
);
}
@ -97,28 +97,28 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
$form['upload'] = array(
'#type' => 'file',
'#title' => t('OPML File'),
'#description' => t('Upload an OPML file containing a list of feeds to be imported.'),
'#title' => $this->t('OPML File'),
'#description' => $this->t('Upload an OPML file containing a list of feeds to be imported.'),
);
$form['remote'] = array(
'#type' => 'url',
'#title' => t('OPML Remote URL'),
'#title' => $this->t('OPML Remote URL'),
'#maxlength' => 1024,
'#description' => t('Enter the URL of an OPML file. This file will be downloaded and processed only once on submission of the form.'),
'#description' => $this->t('Enter the URL of an OPML file. This file will be downloaded and processed only once on submission of the form.'),
);
$form['refresh'] = array(
'#type' => 'select',
'#title' => t('Update interval'),
'#title' => $this->t('Update interval'),
'#default_value' => 3600,
'#options' => $period,
'#description' => t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
'#description' => $this->t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))),
);
$form['block'] = array(
'#type' => 'select',
'#title' => t('News items in block'),
'#title' => $this->t('News items in block'),
'#default_value' => 5,
'#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
'#description' => t("Drupal can make a block with the most recent news items of a feed. You can <a href=\"@block-admin\">configure blocks</a> to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in a feed's block. If you choose '0' these feeds' blocks will be disabled.", array('@block-admin' => url('admin/structure/block'))),
'#description' => $this->t("Drupal can make a block with the most recent news items of a feed. You can <a href=\"@block-admin\">configure blocks</a> to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in a feed's block. If you choose '0' these feeds' blocks will be disabled.", array('@block-admin' => url('admin/structure/block'))),
);
// Handling of categories.
@ -126,15 +126,15 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
if ($options) {
$form['category'] = array(
'#type' => 'checkboxes',
'#title' => t('Categorize news items'),
'#title' => $this->t('Categorize news items'),
'#options' => $options,
'#description' => t('New feed items are automatically filed in the checked categories.'),
'#description' => $this->t('New feed items are automatically filed in the checked categories.'),
);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
'#value' => $this->t('Import'),
);
return $form;
@ -146,7 +146,7 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
public function validateForm(array &$form, array &$form_state) {
// If both fields are empty or filled, cancel.
if (empty($form_state['values']['remote']) == empty($_FILES['files']['name']['upload'])) {
form_set_error('remote', t('You must <em>either</em> upload a file or enter a URL.'));
form_set_error('remote', $this->t('You must <em>either</em> upload a file or enter a URL.'));
}
}
@ -154,7 +154,6 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$data = '';
$validators = array('file_validate_extensions' => array('opml xml'));
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
$data = file_get_contents($file->getFileUri());
@ -168,27 +167,27 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
catch (BadResponseException $e) {
$response = $e->getResponse();
watchdog('aggregator', 'Failed to download OPML file due to "%error".', array('%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()), WATCHDOG_WARNING);
drupal_set_message(t('Failed to download OPML file due to "%error".', array('%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase())));
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase())));
return;
}
catch (RequestException $e) {
watchdog('aggregator', 'Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()), WATCHDOG_WARNING);
drupal_set_message(t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
return;
}
}
$feeds = $this->parseOpml($data);
if (empty($feeds)) {
drupal_set_message(t('No new feed has been added.'));
drupal_set_message($this->t('No new feed has been added.'));
return;
}
// @todo Move this functionality to a processor.
foreach ($feeds as $feed) {
// Ensure URL is valid.
if (!valid_url($feed['url'], TRUE)) {
drupal_set_message(t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
if (!Url::isValid($feed['url'], TRUE)) {
drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
continue;
}
@ -200,28 +199,24 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
$ids = $query
->condition($condition)
->execute();
$result = $this->entityManager
->getStorageController('aggregator_feed')
->loadMultiple($ids);
$result = $this->feedStorage->loadMultiple($ids);
foreach ($result as $old) {
if (strcasecmp($old->label(), $feed['title']) == 0) {
drupal_set_message(t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
drupal_set_message($this->t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
continue 2;
}
if (strcasecmp($old->url->value, $feed['url']) == 0) {
drupal_set_message(t('A feed with the URL %url already exists.', array('%url' => $old->url->value)), 'warning');
drupal_set_message($this->t('A feed with the URL %url already exists.', array('%url' => $old->url->value)), 'warning');
continue 2;
}
}
$new_feed = $this->entityManager
->getStorageController('aggregator_feed')
->create(array(
'title' => $feed['title'],
'url' => $feed['url'],
'refresh' => $form_state['values']['refresh'],
'block' => $form_state['values']['block'],
));
$new_feed = $this->feedStorage->create(array(
'title' => $feed['title'],
'url' => $feed['url'],
'refresh' => $form_state['values']['refresh'],
'block' => $form_state['values']['block'],
));
$new_feed->categories = $form_state['values']['category'];
$new_feed->save();
}
@ -240,7 +235,7 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
* @param $opml
* The complete contents of an OPML document.
*
* @return
* @return array
* An array of feeds, each an associative array with a "title" and a "url"
* element, or NULL if the OPML document failed to be parsed. An empty array
* will be returned if the document is valid but contains no feeds, as some

View File

@ -24,14 +24,14 @@ class SettingsForm extends SystemConfigFormBase {
/**
* The aggregator plugin managers.
*
* @var array
* @var \Drupal\aggregator\Plugin\AggregatorPluginManager[]
*/
protected $managers = array();
/**
* The instantiated plugin instances that have configuration forms.
*
* @var array
* @var \Drupal\Core\Plugin\PluginFormInterface[]
*/
protected $configurableInstances = array();