/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $enabled_link = Link::fromTextAndUrl(t('enabled'), Url::fromRoute('system.modules_list')); $form['#attached']['library'][] = 'system/drupal.system'; $form['exclude_node_title_search'] = ['#type' => 'checkbox', '#title' => $this->t('Remove node title from search pages'), '#description' => $this->t('Select if you wish to remove title from search pages. You need to have Search module @link.', ['@link' => $enabled_link]), '#default_value' => $this->excludeNodeTitleManager->isSearchExcluded(), '#disabled' => !\Drupal::moduleHandler()->moduleExists('search')]; $form['content_type'] = ['#type' => 'fieldset', '#title' => $this->t('Exclude title by content types'), '#description' => $this->t('Define title excluding settings for each content type.'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE]; foreach ($this->bundleInfo->getBundleInfo('node') as $node_type => $node_type_info) { $form['#attached']['drupalSettings']['exclude_node_title']['content_types'][$node_type] = $node_type_info['label']; $form['content_type'][$node_type]['content_type_value'] = ['#type' => 'select', '#title' => $node_type_info['label'], '#default_value' => $this->excludeNodeTitleManager->getBundleExcludeMode($node_type), '#options' => ['none' => $this->t('None'), 'all' => $this->t('All nodes...'), 'user' => $this->t('User defined nodes...')]]; $entity_view_modes = $this->entityDisplayRepository->getViewModes('node'); $modes = []; foreach ($entity_view_modes as $view_mode_name => $view_mode_info) { $modes[$view_mode_name] = $view_mode_info['label']; } $modes += ['nodeform' => $this->t('Node form')]; switch ($form['content_type'][$node_type]['content_type_value']['#default_value']) { case 'all': $title = $this->t('Exclude title from all nodes in the following view modes:'); break; case 'user defined': $title = $this->t('Exclude title from user defined nodes in the following view modes:'); break; default: $title = $this->t('Exclude from:'); } $form['content_type'][$node_type]['content_type_modes'] = ['#type' => 'checkboxes', '#title' => $title, '#default_value' => $this->excludeNodeTitleManager->getExcludedViewModes($node_type), '#options' => $modes, '#states' => ['invisible' => ['select[name="content_type[' . $node_type . '][content_type_value]"]' => ['value' => 'none']]]]; } $form['#attached']['library'][] = 'exclude_node_title/drupal.exclude_node_title.admin'; return parent::buildForm($form, $form_state); }