You are here

public function BreadcrumbManagerConfigForm::buildForm in Breadcrumb Manager 8

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/BreadcrumbManagerConfigForm.php, line 60

Class

BreadcrumbManagerConfigForm
Class BreadcrumbManagerConfigForm.

Namespace

Drupal\breadcrumb_manager\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('breadcrumb_manager.config');
  $form['excluded_paths'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Excluded paths'),
    '#default_value' => $config
      ->get('excluded_paths') ?: 'search/*',
    '#description' => $this
      ->t('Enter a list of path that will not be affected by Breadcrumb Manager. You can use "*" as wildcard.'),
  ];
  $form['show_front'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show on front page'),
    '#default_value' => $config
      ->get('show_front'),
    '#description' => $this
      ->t('If checked, the breadcrumb will be shown even on front page.'),
  ];
  $form['show_home'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show "Home" breadcrumb link'),
    '#default_value' => $config
      ->get('show_home'),
    '#description' => $this
      ->t('Uncheck this option in order to omit Home link from breadcrumb. If you cannot see it even with this option, please check your frontend theme settings.'),
  ];
  $form['home'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Override "Home" label'),
    '#default_value' => $config
      ->get('home'),
    '#attributes' => [
      'placeholder' => 'Home',
    ],
    '#states' => [
      'visible' => [
        ':input[name="show_home"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
    '#description' => $this
      ->t('Enter text that will override default "Home" label link. Leave it empty to use "Home".'),
  ];
  $form['show_current'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show current page title at end'),
    '#default_value' => $config
      ->get('show_current'),
    '#description' => $this
      ->t('Uncheck this option in order to omit current page link from breadcrumb. If you cannot see it even with this option, please check your frontend theme settings.'),
  ];
  $form['show_current_as_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display last segment title as link'),
    '#default_value' => $config
      ->get('show_current_as_link'),
    '#description' => $this
      ->t('Check this option to display last item as a link. Otherwise it will be shown as plain text. If you cannot see it even with this option, please check your frontend theme settings.'),
  ];
  $form['show_fake_segments'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include fake segments'),
    '#default_value' => $config
      ->get('show_fake_segments'),
    '#description' => $this
      ->t('Include segments without route inside the breadcrumb.'),
  ];
  $form['resolvers'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Title resolvers'),
  ];
  $form['resolvers']['title_resolvers'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Description'),
      $this
        ->t('Enabled'),
      $this
        ->t('Weight'),
    ],
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'table-sort-weight',
      ],
    ],
  ];
  $definitions = $this->titleResolverManager
    ->getDefinitions();
  foreach ($definitions as $definition) {
    $form['resolvers']['title_resolvers'][$definition['id']] = [
      '#attributes' => [
        'class' => 'draggable',
      ],
      '#weight' => $definition['weight'],
      'name' => [
        '#markup' => $definition['label'],
      ],
      'description' => [
        '#markup' => $definition['description'],
      ],
      'enabled' => [
        '#title' => $this
          ->t('Enabled'),
        '#title_display' => 'invisible',
        '#type' => 'checkbox',
        '#default_value' => $definition['enabled'],
      ],
      'weight' => [
        '#type' => 'weight',
        '#title' => $this
          ->t('Weight for @title', [
          '@title' => $definition['weight'],
        ]),
        '#title_display' => 'invisible',
        '#default_value' => $definition['weight'],
        '#attributes' => [
          'class' => [
            'table-sort-weight',
          ],
        ],
      ],
    ];
  }
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save settings'),
    ],
  ];
  return $form;
}