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 e8c104f..de200cd 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -121,10 +121,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..ed91bbe 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}' 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' 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' 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}' defaults: _entity_form: 'taxonomy_term.container' requirements: _permission: 'administer forums' + forum_edit_forum: 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\OverviewForm' + requirements: + _permission: 'administer forums' diff --git a/core/modules/forum/lib/Drupal/forum/Form/OverviewForm.php b/core/modules/forum/lib/Drupal/forum/Form/OverviewForm.php new file mode 100644 index 0000000..f80deb2 --- /dev/null +++ b/core/modules/forum/lib/Drupal/forum/Form/OverviewForm.php @@ -0,0 +1,101 @@ +forumConfig = $config_factory->get('forum.settings'); + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc}. + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('plugin.manager.entity') + ); + } + + /** + * {@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); + + 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'], $this->forumConfig->get('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; + } + +}