You are here

public function SettingsForm::buildForm in Menu Breadcrumb 8

Same name and namespace in other branches
  1. 2.0.x src/Form/SettingsForm.php \Drupal\menu_breadcrumb\Form\SettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/SettingsForm.php, line 60

Class

SettingsForm

Namespace

Drupal\menu_breadcrumb\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('menu_breadcrumb.settings');
  $form['determine_menu'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable the Menu Breadcrumb module'),
    '#description' => $this
      ->t('Use menu the page belongs to, or the page for the taxonomy of which it is a member, for the breadcrumb. If unset, no breadcrumbs are generated or cached by this module and all settings below are ignored.'),
    '#default_value' => $config
      ->get('determine_menu'),
  ];
  $form['disable_admin_page'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable for admin pages'),
    '#description' => $this
      ->t('Do not build menu-based breadcrumbs for admin pages.'),
    '#default_value' => $config
      ->get('disable_admin_page'),
  ];
  $form['append_current_page'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Append current page to breadcrumb'),
    '#description' => $this
      ->t('If current page is on a menu, include it in the breadcrumb trail.'),
    '#default_value' => $config
      ->get('append_current_page'),
  ];
  $form['current_page_as_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show current page as link'),
    '#description' => $this
      ->t('Set TRUE if the current page in the breadcrumb trail should be a link (otherwise it will be plain text).'),
    '#default_value' => $config
      ->get('current_page_as_link'),
    '#states' => [
      'visible' => [
        ':input[name="append_current_page"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['stop_on_first_match'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Stop on the first matching'),
    '#description' => $this
      ->t('End the breadcrumb trail when the first matching found in the menu.'),
    '#default_value' => $config
      ->get('stop_on_first_match'),
  ];
  $form['append_member_page'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Attach taxonomy member page to breadcrumb'),
    '#description' => $this
      ->t('This option affects breadcrumb display when the current page is a member of a taxonomy whose term is on a menu with "Taxonomy Attachment" selected, when it "attaches" to the menu-based breadcrumbs of that taxonomy term. In this case that term\'s menu title will show as a link regardless of the "current page" options above. Set this option TRUE to also show the current ("attached") <i>page</i> title as the final breadcrumb.'),
    '#default_value' => $config
      ->get('append_member_page'),
  ];
  $form['member_page_as_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show attached current page as link'),
    '#description' => $this
      ->t('Set TRUE to show the attached final breadcrumb as a link (otherwise it will be plain text).'),
    '#default_value' => $config
      ->get('member_page_as_link'),
    '#states' => [
      'visible' => [
        ':input[name="append_member_page"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['remove_home'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Remove "Home" link'),
    '#default_value' => $config
      ->get('remove_home'),
    '#description' => $this
      ->t('Regardless of option settings, this module always checks if the first breadcrumb is also the &lt;front&gt; page. Without this option set, it will always replace the link for that node- or view- based path of the &lt;front&gt; page (e.g., /node/1 or /node) with a link to the site home. Set this option TRUE to <i>delete</i> the &lt;front&gt; breadcrumb rather than replacing it.'),
  ];
  $form['add_home'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add "Home" link'),
    '#default_value' => $config
      ->get('add_home'),
    '#description' => $this
      ->t('If TRUE will add a link to the &lt;front&gt; page if it doesn\'t already begin the breadcrumb trail: ensuring that the first breadcrumb of every page is the site home. If both "add" and "remove" are set, when displaying the &lt;front&gt; page and its menu children the "remove" option will take precedence.'),
  ];
  $form['front_title'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Home title'),
    '#default_value' => $config
      ->get('front_title'),
    '#options' => [
      0 => $this
        ->t('Use "Home" as title'),
      1 => $this
        ->t('Uses the site name from the configuration settings: if this option is not set, a translated value for "Home" will be used.'),
      2 => $this
        ->t('Use title menu parent'),
    ],
  ];
  $form['exclude_empty_url'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Exclude menu items with empty URLs'),
    '#description' => $this
      ->t('If TRUE, menu items whose Link fields resolves to an empty string (like in the case "&lt;none&gt;" was used) will not be included in the breadcrumb trail.'),
    '#default_value' => $config
      ->get('exclude_empty_url'),
  ];
  $form['exclude_disabled_menu_items'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Exclude disabled menu items'),
    '#description' => $this
      ->t('If TRUE, menu items that are disabled will not be included in the breadcrumb trail.'),
    '#default_value' => $config
      ->get('exclude_disabled_menu_items'),
  ];
  $form['derived_active_trail'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Derive MenuActiveTrail from RouteMatch'),
    '#description' => $this
      ->t('If FALSE, the injected @menu.active_trail service will be used. If you have a multilingual site with unusually large menus, see <a target="_blank" href="https://www.drupal.org/project/menu_breadcrumb/issues/3083028">issue 3083028</a>.'),
    '#default_value' => $config
      ->get('derived_active_trail'),
  ];
  $form['include_exclude'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Enable / Disable Menus'),
    '#description' => $this
      ->t('<b>Order of operation:</b> The breadcrumb will be generated from the first match it finds: "Enabled" to look for the current item on the menu, then "Taxonomy Attachment" to look for its taxonomy term. Re-order the list to change the priority of each menu.<br><b>Language Handling:</b> If set, skip this menu when the defined menu language does not match the current content language: recommended setting when you use a separate menu per language. This has no effect on taxonomy attachment.'),
  ];
  $form['include_exclude']['note_about_navigation'] = [
    '#markup' => '<p class="description">' . $this
      ->t("Note: If none of the selected menus contain an item for a given page, Drupal will look in the 'Navigation' menu by default, even if it is 'disabled' here.") . '</p>',
  ];

  // Orderable list of menu selections.
  $form['include_exclude']['menu_breadcrumb_menus'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Menu'),
      $this
        ->t('Enabled'),
      $this
        ->t('Taxonomy Attachment'),
      $this
        ->t('Language Handling'),
      $this
        ->t('Weight'),
    ],
    '#empty' => $this
      ->t('There are no menus yet.'),
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'menus-order-weight',
      ],
    ],
  ];
  foreach ($this
    ->getSortedMenus() as $menu_name => $menu_config) {
    $form['include_exclude']['menu_breadcrumb_menus'][$menu_name] = [
      '#attributes' => [
        'class' => [
          'draggable',
        ],
      ],
      '#weight' => $menu_config['weight'],
      'title' => [
        '#plain_text' => $menu_config['label'],
      ],
      'enabled' => [
        '#type' => 'checkbox',
        '#default_value' => $menu_config['enabled'],
      ],
      'taxattach' => [
        '#type' => 'checkbox',
        '#default_value' => $menu_config['taxattach'],
      ],
      'langhandle' => [
        '#type' => 'checkbox',
        '#default_value' => $menu_config['langhandle'],
      ],
      'weight' => [
        '#type' => 'weight',
        '#default_value' => $menu_config['weight'],
        '#attributes' => [
          'class' => [
            'menus-order-weight',
          ],
        ],
      ],
    ];
  }
  return parent::buildForm($form, $form_state);
}