3 namespace Drupal\forum\Form;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Render\Element;
9 use Drupal\taxonomy\Form\OverviewTerms;
10 use Drupal\Core\Extension\ModuleHandlerInterface;
11 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14 * Provides forum overview form for the forum vocabulary.
16 class Overview extends OverviewTerms {
19 * Entity manager Service Object.
21 * @var \Drupal\Core\Entity\EntityManagerInterface
23 protected $entityManager;
26 * Constructs a \Drupal\forum\Form\OverviewForm object.
28 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
29 * The module handler service.
30 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
31 * The entity manager service.
33 public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) {
34 parent::__construct($module_handler, $entity_manager);
35 $this->entityManager = $entity_manager;
41 public function getFormId() {
42 return 'forum_overview';
48 public function buildForm(array $form, FormStateInterface $form_state) {
49 $forum_config = $this->config('forum.settings');
50 $vid = $forum_config->get('vocabulary');
51 $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($vid);
53 throw new NotFoundHttpException();
56 // Build base taxonomy term overview.
57 $form = parent::buildForm($form, $form_state, $vocabulary);
59 foreach (Element::children($form['terms']) as $key) {
60 if (isset($form['terms'][$key]['#term'])) {
61 $term = $form['terms'][$key]['#term'];
62 $form['terms'][$key]['term']['#url'] = Url::fromRoute('forum.page', ['taxonomy_term' => $term->id()]);
63 unset($form['terms'][$key]['operations']['#links']['delete']);
64 $route_parameters = $form['terms'][$key]['operations']['#links']['edit']['url']->getRouteParameters();
65 if (!empty($term->forum_container->value)) {
66 $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit container');
67 $form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('entity.taxonomy_term.forum_edit_container_form', $route_parameters);
70 $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit forum');
71 $form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('entity.taxonomy_term.forum_edit_form', $route_parameters);
73 // We don't want the redirect from the link so we can redirect the
75 unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
79 // Remove the alphabetical reset.
80 unset($form['actions']['reset_alphabetical']);
82 // Use the existing taxonomy overview submit handler.
83 $form['terms']['#empty'] = $this->t('No containers or forums available. <a href=":container">Add container</a> or <a href=":forum">Add forum</a>.', [
84 ':container' => $this->url('forum.add_container'),
85 ':forum' => $this->url('forum.add_forum')