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 Drupal\taxonomy\VocabularyInterface;
12 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15 * Provides forum overview form for the forum vocabulary.
19 class Overview extends OverviewTerms {
22 * Entity manager Service Object.
24 * @var \Drupal\Core\Entity\EntityManagerInterface
26 protected $entityManager;
29 * Constructs a \Drupal\forum\Form\OverviewForm object.
31 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
32 * The module handler service.
33 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
34 * The entity manager service.
36 public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) {
37 parent::__construct($module_handler, $entity_manager);
38 $this->entityManager = $entity_manager;
44 public function getFormId() {
45 return 'forum_overview';
51 public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL) {
52 $forum_config = $this->config('forum.settings');
53 $vid = $forum_config->get('vocabulary');
54 $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($vid);
56 throw new NotFoundHttpException();
59 // Build base taxonomy term overview.
60 $form = parent::buildForm($form, $form_state, $vocabulary);
62 foreach (Element::children($form['terms']) as $key) {
63 if (isset($form['terms'][$key]['#term'])) {
64 /** @var \Drupal\taxonomy\TermInterface $term */
65 $term = $form['terms'][$key]['#term'];
66 $form['terms'][$key]['term']['#url'] = Url::fromRoute('forum.page', ['taxonomy_term' => $term->id()]);
68 if (!empty($term->forum_container->value)) {
69 $title = $this->t('edit container');
70 $url = Url::fromRoute('entity.taxonomy_term.forum_edit_container_form', ['taxonomy_term' => $term->id()]);
73 $title = $this->t('edit forum');
74 $url = Url::fromRoute('entity.taxonomy_term.forum_edit_form', ['taxonomy_term' => $term->id()]);
77 // Re-create the operations column and add only the edit link.
78 $form['terms'][$key]['operations'] = [
79 '#type' => 'operations',
91 // Remove the alphabetical reset.
92 unset($form['actions']['reset_alphabetical']);
94 // Use the existing taxonomy overview submit handler.
95 $form['terms']['#empty'] = $this->t('No containers or forums available. <a href=":container">Add container</a> or <a href=":forum">Add forum</a>.', [
96 ':container' => $this->url('forum.add_container'),
97 ':forum' => $this->url('forum.add_forum'),