diff --git a/core/modules/forum/forum.routing.yml b/core/modules/forum/forum.routing.yml index fcf86b0..4d046bf 100644 --- a/core/modules/forum/forum.routing.yml +++ b/core/modules/forum/forum.routing.yml @@ -43,6 +43,6 @@ forum_edit_forum: forum_overview: pattern: '/admin/structure/forum' defaults: - _form: '\Drupal\forum\Form\OverviewForm' + _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..4b8939e --- /dev/null +++ b/core/modules/forum/lib/Drupal/forum/Form/Overview.php @@ -0,0 +1,113 @@ +forumConfig = $config_factory->get('forum.settings'); + $this->entityManager = $entity_manager; + $this->urlGenerator = $url_generator; + } + + /** + * {@inheritdoc}. + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('plugin.manager.entity'), + $container->get('module_handler'), + $container->get('url_generator') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'forum_overview'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $vid = $this->forumConfig->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 = $this->forumConfig->get('containers'); + foreach (element_children($form) 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(), $this->forumConfig->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/forum/lib/Drupal/forum/Form/OverviewForm.php b/core/modules/forum/lib/Drupal/forum/Form/OverviewForm.php deleted file mode 100644 index 2aa34c9..0000000 --- a/core/modules/forum/lib/Drupal/forum/Form/OverviewForm.php +++ /dev/null @@ -1,106 +0,0 @@ -config = $config_factory->get('taxonomy.settings'); - $this->forumConfig = $config_factory->get('forum.settings'); - $this->entityManager = $entity_manager; - $this->moduleHandler = $module_handler; - } - - /** - * {@inheritdoc}. - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('plugin.manager.entity'), - $container->get('module_handler') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormID() { - return 'forum_overview'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state) { - $vid = $this->forumConfig->get('vocabulary'); - $vocabularies = $this->entityManager->getStorageController('taxonomy_vocabulary')->load(array($vid)); - $vocabulary = isset($vocabularies[$vid]) ? $vocabularies[$vid] : FALSE; - if (!$vocabulary) { - throw new NotFoundHttpException(); - } - - // Build base taxonomy term overview. - $form = parent::buildForm($form, $form_state, $vocabulary); - - $containers = $this->forumConfig->get('containers'); - foreach (element_children($form) as $key) { - if (isset($form[$key]['#term'])) { - $term = $form[$key]['#term']; - $form[$key]['view']['#href'] = 'forum/' . $term['tid']; - unset($form[$key]['operations']['#links']['delete']); - if (in_array($form[$key]['#term']['tid'], $containers)) { - $form[$key]['operations']['#links']['edit']['title'] = $this->t('edit container'); - $form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term['tid']; - // We don't want the redirect from the link so we can redirect the - // delete action. - unset($form[$key]['operations']['#links']['edit']['query']['destination']); - } - else { - $form[$key]['operations']['#links']['edit']['title'] = $this->t('edit forum'); - $form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term['tid']; - // We don't want the redirect from the link so we can redirect the - // delete action. - unset($form[$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. - $form['#theme'] = 'taxonomy_overview_terms'; - $form['#submit'] = array(array($this, 'submitForm')); - $form['#empty_text'] = $this->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; - } - -}