diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 081768d..6753f28 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -167,7 +167,7 @@ function aggregator_menu() { $items['aggregator/categories/%aggregator_category/categorize'] = array( 'title' => 'Categorize', 'type' => MENU_LOCAL_TASK, - 'route_name' => 'aggregator_page_category_form', + 'route_name' => 'aggregator_categorize_category_form', ); $items['aggregator/categories/%aggregator_category/configure'] = array( 'title' => 'Configure', @@ -192,11 +192,8 @@ function aggregator_menu() { ); $items['aggregator/sources/%aggregator_feed/categorize'] = array( 'title' => 'Categorize', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('aggregator_page_source_form', 2), - 'access arguments' => array('administer news feeds'), + 'route_name' => 'aggregator_categorize_feed_form', 'type' => MENU_LOCAL_TASK, - 'file' => 'aggregator.pages.inc', ); $items['aggregator/sources/%aggregator_feed/configure'] = array( 'title' => 'Configure', diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 9192196..20b145f 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -30,23 +30,6 @@ function aggregator_page_source(Feed $feed) { } /** - * Form constructor to show all items captured from a feed. - * - * @param $feed - * The feed for which to list all of the aggregated items. - * - * @return string - * The rendered list of items for the feed. - * - * @see aggregator_menu() - * @see aggregator_page_source() - * @ingroup forms - */ -function aggregator_page_source_form($form, $form_state, $feed) { - return aggregator_page_source($feed); -} - -/** * Form constructor to list items aggregated in a category. * * @param $category @@ -127,111 +110,17 @@ function aggregator_load_feed_items($type, $data = NULL, $limit = 20) { * The rendered list of items for the feed. */ function _aggregator_page_list($items, $op, $feed_source = '') { - if (user_access('administer news feeds') && ($op == 'categorize')) { - // Get form data. - $build = aggregator_categorize_items($items, $feed_source); - } - else { - // Assemble output. - $build = array( - '#type' => 'container', - '#attributes' => array('class' => array('aggregator-wrapper')), - ); - $build['feed_source'] = is_array($feed_source) ? $feed_source : array('#markup' => $feed_source); - if ($items) { - $build['items'] = entity_view_multiple($items, 'default'); - $build['pager'] = array('#theme' => 'pager'); - } - } - - return $build; -} - -/** - * Form constructor to build the page list form. - * - * @param array $items - * An array of the feed items. - * @param string $feed_source - * (optional) The feed source URL. Defaults to an empty string. - * - * @return array - * An array of FAPI elements. - * - * @see aggregator_categorize_items_submit() - * @see theme_aggregator_categorize_items() - * @ingroup forms - */ -function aggregator_categorize_items($items, $feed_source = '') { - $form['#submit'][] = 'aggregator_categorize_items_submit'; - $form['feed_source'] = array( - '#value' => $feed_source, - ); - $categories = array(); - $done = FALSE; - - $form['items'] = array( - '#type' => 'table', - '#header' => array('', t('Categorize')), + // Assemble output. + $build = array( + '#type' => 'container', + '#attributes' => array('class' => array('aggregator-wrapper')), ); - if ($items && $form_items = entity_view_multiple($items, 'default')) { - foreach (element_children($form_items) as $iid) { - $categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid', array(':iid' => $iid)); - $selected = array(); - foreach ($categories_result as $category) { - if (!$done) { - $categories[$category->cid] = check_plain($category->title); - } - if ($category->iid) { - $selected[] = $category->cid; - } - } - $done = TRUE; - $form['items'][$iid]['item'] = $form_items[$iid]; - $form['items'][$iid]['categories'] = array( - '#type' => config('aggregator.settings')->get('source.category_selector'), - '#default_value' => $selected, - '#options' => $categories, - '#size' => 10, - '#multiple' => TRUE, - '#parents' => array('categories', $iid), - ); - } + $build['feed_source'] = is_array($feed_source) ? $feed_source : array('#markup' => $feed_source); + if ($items) { + $build['items'] = entity_view_multiple($items, 'default'); + $build['pager'] = array('#theme' => 'pager'); } - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save categories')); - $form['pager'] = array('#theme' => 'pager'); - - return $form; -} - -/** - * Form submission handler for aggregator_categorize_items(). - */ -function aggregator_categorize_items_submit($form, &$form_state) { - if (!empty($form_state['values']['categories'])) { - foreach ($form_state['values']['categories'] as $iid => $selection) { - db_delete('aggregator_category_item') - ->condition('iid', $iid) - ->execute(); - $insert = db_insert('aggregator_category_item')->fields(array('iid', 'cid')); - $has_values = FALSE; - foreach ($selection as $cid) { - if ($cid && $iid) { - $has_values = TRUE; - $insert->values(array( - 'iid' => $iid, - 'cid' => $cid, - )); - } - } - if ($has_values) { - $insert->execute(); - } - } - } - drupal_set_message(t('The categories have been saved.')); + return $build; } /** diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 6612a2a..76f534e 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -68,9 +68,17 @@ aggregator_categories: requirements: _access_aggregator_categories: 'TRUE' -aggregator_page_category_form: - pattern: '/aggregator/categories/{category}/categorize' +aggregator_categorize_category_form: + pattern: '/aggregator/categories/{cid}/categorize' defaults: - _form: '\Drupal\aggregator\Form\AggregatorCategoryForm' + _form: '\Drupal\aggregator\Form\CategorizeCategoryForm' + requirements: + _permission: 'administer news feeds' + +aggregator_categorize_feed_form: + pattern: '/aggregator/sources/{aggregator_feed}/categorize' + defaults: + _form: '\Drupal\aggregator\Form\CategorizeFeedForm' + entity_type: 'aggregator_feed' requirements: _permission: 'administer news feeds' diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeCategoryForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeCategoryForm.php new file mode 100644 index 0000000..4bc7c9e --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeCategoryForm.php @@ -0,0 +1,30 @@ +storageController->loadByCategory($cid); + return $this->prepareFormItems($items); + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFeedForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFeedForm.php new file mode 100644 index 0000000..6f29b60 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFeedForm.php @@ -0,0 +1,32 @@ +storageController->loadByFeed($aggregator_feed->id()); + return $this->prepareFormItems($items, $aggregator_feed); + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategoryForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFormBase.php similarity index 89% rename from core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategoryForm.php rename to core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFormBase.php index c98066f..267d30d 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/AggregatorCategoryForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategorizeFormBase.php @@ -7,6 +7,7 @@ namespace Drupal\aggregator\Form; +use Drupal\aggregator\ItemInterface; use Drupal\aggregator\ItemStorageControllerInterface; use Drupal\Component\Utility\String; use Drupal\Core\Config\Config; @@ -17,9 +18,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a form to allow items to be categorized. + * Provides a base form to allow items to be categorized. */ -class AggregatorCategoryForm implements FormInterface, ControllerInterface { +abstract class CategorizeFormBase implements FormInterface, ControllerInterface { /** * The Render controller. @@ -60,7 +61,6 @@ class AggregatorCategoryForm implements FormInterface, ControllerInterface { * The aggregator config. * @param \Drupal\aggregator\ItemStorageControllerInterface $storage_controller * The aggregator item storage controller. - * @internal param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler The module handler.* The module handler. */ public function __construct(EntityRenderControllerInterface $render_controller, Connection $database, Config $config, ItemStorageControllerInterface $storage_controller) { $this->renderController = $render_controller; @@ -82,19 +82,20 @@ public static function create(ContainerInterface $container) { } /** - * {@inheritdoc} + * Prepares a list of items to be displayed in a form. + * + * @param \Drupal\aggregator\ItemInterface[] $items + * An array of items. + * @param \Drupal\aggregator\FeedInterface|null $feed + * (optional) The feed we are displaying. + * + * @return array + * A form builder array. */ - public function getFormID() { - return 'aggregator_category_form'; - } + protected function prepareFormItems($items, $feed = NULL) { - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state, $category = NULL) { - $items = $this->storageController->loadByCategory($category); $form['feed_source'] = array( - '#value' => '', + '#value' => $feed, ); $categories = array(); $done = FALSE; @@ -139,11 +140,6 @@ public function buildForm(array $form, array &$form_state, $category = NULL) { return $form; } - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - } /** * {@inheritdoc} @@ -174,4 +170,10 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message(t('The categories have been saved.')); } + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + } + }