You are here

class BreadcrumbManagerConfigForm in Breadcrumb Manager 8

Class BreadcrumbManagerConfigForm.

Hierarchy

Expanded class hierarchy of BreadcrumbManagerConfigForm

1 string reference to 'BreadcrumbManagerConfigForm'
breadcrumb_manager.routing.yml in ./breadcrumb_manager.routing.yml
breadcrumb_manager.routing.yml

File

src/Form/BreadcrumbManagerConfigForm.php, line 14

Namespace

Drupal\breadcrumb_manager\Form
View source
class BreadcrumbManagerConfigForm extends ConfigFormBase {

  /**
   * The Breadcrumb Title Resolver Plugin Manager.
   *
   * @var \Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolverManager
   */
  protected $titleResolverManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, BreadcrumbTitleResolverManager $title_resolver_manager) {
    parent::__construct($config_factory);
    $this->titleResolverManager = $title_resolver_manager;
  }
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('plugin.manager.breadcrumb_title_resolver'));
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'breadcrumb_manager.config',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'breadcrumb_manager_config_form';
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $this
      ->config('breadcrumb_manager.config')
      ->set('excluded_paths', trim($form_state
      ->getValue('excluded_paths')))
      ->set('show_front', $form_state
      ->getValue('show_front'))
      ->set('show_home', $form_state
      ->getValue('show_home'))
      ->set('home', $form_state
      ->getValue('home'))
      ->set('show_current', $form_state
      ->getValue('show_current'))
      ->set('show_current_as_link', $form_state
      ->getValue('show_current_as_link'))
      ->set('show_fake_segments', $form_state
      ->getValue('show_fake_segments'))
      ->set('title_resolvers', $form_state
      ->getValue('title_resolvers'))
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BreadcrumbManagerConfigForm::$titleResolverManager protected property The Breadcrumb Title Resolver Plugin Manager.
BreadcrumbManagerConfigForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
BreadcrumbManagerConfigForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
BreadcrumbManagerConfigForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
BreadcrumbManagerConfigForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
BreadcrumbManagerConfigForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
BreadcrumbManagerConfigForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
BreadcrumbManagerConfigForm::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase::__construct
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.