diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc deleted file mode 100644 index 332f11c..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 (in_array($form['terms'][$key]['#term']->id(), $config->get('containers'))) { - $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.module b/core/modules/forum/forum.module index 1ed6ac3..c2879a5 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', ), ); } @@ -121,10 +120,7 @@ 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', diff --git a/core/modules/forum/forum.routing.yml b/core/modules/forum/forum.routing.yml index fe816f0..4d046bf 100644 --- a/core/modules/forum/forum.routing.yml +++ b/core/modules/forum/forum.routing.yml @@ -1,36 +1,48 @@ 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' + forum_settings: pattern: '/admin/structure/forum/settings' defaults: _form: '\Drupal\forum\ForumSettingsForm' requirements: _permission: 'administer forums' + 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..b9a2c59 --- /dev/null +++ b/core/modules/forum/lib/Drupal/forum/Form/Overview.php @@ -0,0 +1,114 @@ +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); + + $containers = $forum_config->get('containers'); + 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 (in_array($form['terms'][$key]['#term']->id(), $forum_config->get('containers'))) { + $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.