Commit e18109e2 authored by webchick's avatar webchick
Browse files

Issue #1974210 by disasm, larowlan: Convert admin/structure/forum to a Controller.

parent 79abddbe
<?php
/**
* @file
* Administrative page callbacks for the Forum module.
*/
use Drupal\taxonomy\Form\OverviewTerms;
use Drupal\taxonomy\Entity\Term;
/**
* Form constructor for the forum overview form.
*
* Returns a form for controlling the hierarchy of existing forums and
* containers.
*
* @see forum_menu()
* @ingroup forms
*/
function forum_overview($form, &$form_state) {
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
$config = Drupal::config('forum.settings');
$vid = $config->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. <a href="@container">Add container</a> or <a href="@forum">Add forum</a>.', array('@container' => url('admin/structure/forum/add/container'), '@forum' => url('admin/structure/forum/add/forum')));
return $form;
}
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
......@@ -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;
}
......@@ -213,18 +201,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().
*/
......
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'
<?php
/**
* @file
* Contains \Drupal\forum\Form\OverviewForm.
*/
namespace Drupal\forum\Form;
use Drupal\taxonomy\Form\OverviewTerms;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides forum overview form for the forum vocabulary.
*/
class Overview extends OverviewTerms {
/**
* Entity manager Service Object.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Constructs a \Drupal\forum\Form\OverviewForm object.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager service.
* @param \Drupal\Core\Extension\ModuleHandlerInteface $module_handler
* The module handler service.
*/
public function __construct(ConfigFactory $config_factory, EntityManager $entity_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($config_factory, $module_handler);
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}.
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.manager'),
$container->get('module_handler')
);
}
/**
* {@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. <a href="@container">Add container</a> or <a href="@forum">Add forum</a>.', array(
'@container' => $this->getUrlGenerator()->generateFromPath('admin/structure/forum/add/container'),
'@forum' => $this->urlGenerator->generateFromPath('admin/structure/forum/add/forum')
));
return $form;
}
}
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment