diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc deleted file mode 100644 index 962e84d..0000000 --- a/core/modules/forum/forum.admin.inc +++ /dev/null @@ -1,60 +0,0 @@ -get('vocabulary'); - $vocabulary = entity_load('taxonomy_vocabulary', $vid); - // @todo temporary, will be fixed in http://drupal.org/node/1974210. - $overview = OverviewTerms::create(Drupal::getContainer()); - $form = $overview->buildForm($form, $form_state, $vocabulary); - - foreach (element_children($form['terms']) as $key) { - if (isset($form['terms'][$key]['#term'])) { - $term = $form['terms'][$key]['#term']; - $form['terms'][$key]['term']['#href'] = 'forum/' . $term->id(); - unset($form['terms'][$key]['operations']['#links']['delete']); - if (!empty($term->forum_container->value)) { - $form['terms'][$key]['operations']['#links']['edit']['title'] = t('edit container'); - $form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term->id(); - // We don't want the redirect from the link so we can redirect the - // delete action. - unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); - } - else { - $form['terms'][$key]['operations']['#links']['edit']['title'] = t('edit forum'); - $form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term->id(); - // We don't want the redirect from the link so we can redirect the - // delete action. - unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); - } - } - } - - // Remove the alphabetical reset. - unset($form['actions']['reset_alphabetical']); - - // The form needs to have submit and validate handlers set explicitly. - // Use the existing taxonomy overview submit handler. - $form['#submit'] = array(array($overview, 'submitForm')); - $form['terms']['#empty'] = t('No containers or forums available. Add container or Add forum.', array('@container' => url('admin/structure/forum/add/container'), '@forum' => url('admin/structure/forum/add/forum'))); - return $form; -} diff --git a/core/modules/forum/forum.local_actions.yml b/core/modules/forum/forum.local_actions.yml new file mode 100644 index 0000000..9f571aa --- /dev/null +++ b/core/modules/forum/forum.local_actions.yml @@ -0,0 +1,11 @@ +forum_add_forum_local_action: + route_name: forum_add_forum + title: 'Add forum' + appears_on: + - forum_overview + +forum_add_container_local_action: + route_name: forum_add_container + title: 'Add container' + appears_on: + - forum_overview diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 0f076c4..320d6aa 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -94,7 +94,6 @@ function forum_theme() { ), 'forum_form' => array( 'render element' => 'form', - 'file' => 'forum.admin.inc', ), ); } @@ -116,27 +115,12 @@ function forum_menu() { $items['admin/structure/forum'] = array( 'title' => 'Forums', 'description' => 'Control forum hierarchy settings.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('forum_overview'), - 'access arguments' => array('administer forums'), - 'file' => 'forum.admin.inc', + 'route_name' => 'forum_overview', ); $items['admin/structure/forum/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/structure/forum/add/container'] = array( - 'title' => 'Add container', - 'tab_parent' => 'admin/structure/forum', - 'route_name' => 'forum_add_container', - 'type' => MENU_LOCAL_ACTION, - ); - $items['admin/structure/forum/add/forum'] = array( - 'tab_parent' => 'admin/structure/forum', - 'title' => 'Add forum', - 'route_name' => 'forum_add_forum', - 'type' => MENU_LOCAL_ACTION, - ); $items['admin/structure/forum/settings'] = array( 'title' => 'Settings', 'weight' => 100, @@ -152,6 +136,10 @@ function forum_menu() { 'title' => 'Edit forum', 'route_name' => 'forum_edit_forum', ); + $items['admin/structure/forum/delete/forum/%taxonomy_term'] = array( + 'title' => 'Delete forum', + 'route_name' => 'forum_delete', + ); return $items; } @@ -214,18 +202,6 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) { } /** - * Implements hook_menu_local_tasks_alter(). - * - * Remove the 'Add Forum' and 'Add container' local tasks on the delete form. - */ -function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) { - if ($root_path == 'admin/structure/forum' && !empty($router_item['map'][3]) && - $router_item['map'][3] == 'delete') { - $data = array(); - } -} - -/** * Implements hook_entity_info(). */ function forum_entity_info(&$info) { diff --git a/core/modules/forum/forum.routing.yml b/core/modules/forum/forum.routing.yml index 954e04a..4268919 100644 --- a/core/modules/forum/forum.routing.yml +++ b/core/modules/forum/forum.routing.yml @@ -1,7 +1,7 @@ forum_delete: - pattern: 'admin/structure/forum/delete/forum/{taxonomy_term}' + pattern: '/admin/structure/forum/delete/forum/{taxonomy_term}' defaults: - _form: 'Drupal\forum\Form\DeleteForm' + _form: '\Drupal\forum\Form\DeleteForm' requirements: _permission: 'administer forums' @@ -15,38 +15,48 @@ forum_settings: forum_index: pattern: '/forum' defaults: - _content: 'Drupal\forum\Controller\ForumController::forumIndex' + _content: '\Drupal\forum\Controller\ForumController::forumIndex' requirements: _permission: 'access content' forum_page: pattern: '/forum/{taxonomy_term}' defaults: - _content: 'Drupal\forum\Controller\ForumController::forumPage' + _content: '\Drupal\forum\Controller\ForumController::forumPage' requirements: _permission: 'access content' forum_add_container: - pattern: 'admin/structure/forum/add/container' + pattern: '/admin/structure/forum/add/container' defaults: - _content: 'Drupal\forum\Controller\ForumController::addContainer' + _content: '\Drupal\forum\Controller\ForumController::addContainer' requirements: _permission: 'administer forums' + forum_add_forum: - pattern: 'admin/structure/forum/add/forum' + pattern: '/admin/structure/forum/add/forum' defaults: - _content: 'Drupal\forum\Controller\ForumController::addForum' + _content: '\Drupal\forum\Controller\ForumController::addForum' requirements: _permission: 'administer forums' + forum_edit_container: - pattern: 'admin/structure/forum/edit/container/{taxonomy_term}' + pattern: '/admin/structure/forum/edit/container/{taxonomy_term}' defaults: _entity_form: 'taxonomy_term.container' requirements: _permission: 'administer forums' + forum_edit_forum: - pattern: 'admin/structure/forum/edit/forum/{taxonomy_term}' + pattern: '/admin/structure/forum/edit/forum/{taxonomy_term}' defaults: _entity_form: 'taxonomy_term.forum' requirements: _permission: 'administer forums' + +forum_overview: + pattern: '/admin/structure/forum' + defaults: + _form: '\Drupal\forum\Form\Overview' + requirements: + _permission: 'administer forums' diff --git a/core/modules/forum/lib/Drupal/forum/Form/Overview.php b/core/modules/forum/lib/Drupal/forum/Form/Overview.php new file mode 100644 index 0000000..64a3e2d --- /dev/null +++ b/core/modules/forum/lib/Drupal/forum/Form/Overview.php @@ -0,0 +1,113 @@ +entityManager = $entity_manager; + $this->urlGenerator = $url_generator; + } + + /** + * {@inheritdoc}. + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('entity.manager'), + $container->get('module_handler'), + $container->get('url_generator') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'forum_overview'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $forum_config = $this->configFactory->get('forum.settings'); + $vid = $forum_config->get('vocabulary'); + $vocabulary = $this->entityManager->getStorageController('taxonomy_vocabulary')->load($vid); + if (!$vocabulary) { + throw new NotFoundHttpException(); + } + + // Build base taxonomy term overview. + $form = parent::buildForm($form, $form_state, $vocabulary); + + foreach (element_children($form['terms']) as $key) { + if (isset($form['terms'][$key]['#term'])) { + $term = $form['terms'][$key]['#term']; + $form['terms'][$key]['term']['#href'] = 'forum/' . $term->id(); + unset($form['terms'][$key]['operations']['#links']['delete']); + if (!empty($term->forum_container->value)) { + $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit container'); + $form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term->id(); + // We don't want the redirect from the link so we can redirect the + // delete action. + unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); + } + else { + $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit forum'); + $form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term->id(); + // We don't want the redirect from the link so we can redirect the + // delete action. + unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); + } + } + } + + // Remove the alphabetical reset. + unset($form['actions']['reset_alphabetical']); + + // The form needs to have submit and validate handlers set explicitly. + // Use the existing taxonomy overview submit handler. + $form['#submit'] = array(array($this, 'submitForm')); + $form['terms']['#empty'] = $this->t('No containers or forums available. Add container or Add forum.', array('@container' => $this->urlGenerator->generateFromPath('admin/structure/forum/add/container'), '@forum' => $this->urlGenerator->generateFromPath('admin/structure/forum/add/forum'))); + return $form; + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php index d79af40..0b1b519 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php @@ -23,7 +23,7 @@ class OverviewTerms extends FormBase { * * @var \Drupal\Core\Config\Config */ - protected $config; + protected $configFactory; /** * The module handler service. @@ -41,7 +41,7 @@ class OverviewTerms extends FormBase { * The module handler service. */ public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { - $this->config = $config_factory->get('taxonomy.settings'); + $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; } @@ -87,7 +87,7 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ $page = $this->getRequest()->query->get('page') ?: 0; // Number of terms per page. - $page_increment = $this->config->get('terms_per_page_admin'); + $page_increment = $this->configFactory->get('taxonomy.settings')->get('terms_per_page_admin'); // Elements shown on this page. $page_entries = 0; // Elements at the root level before this page.