You are here

class ViewsMenuLinkForm in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php \Drupal\views\Plugin\Menu\Form\ViewsMenuLinkForm

Provides a form to edit Views menu links.

This provides the feature to edit the title and description, in contrast to the default menu link form.

Hierarchy

Expanded class hierarchy of ViewsMenuLinkForm

See also

\Drupal\views\Plugin\Menu\ViewsMenuLink

1 string reference to 'ViewsMenuLinkForm'
views.links.menu.yml in core/modules/views/views.links.menu.yml
core/modules/views/views.links.menu.yml

File

core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php, line 21
Contains \Drupal\views\Plugin\Menu\Form\ViewsMenuLinkForm.

Namespace

Drupal\views\Plugin\Menu\Form
View source
class ViewsMenuLinkForm extends MenuLinkDefaultForm {

  /**
   * The edited views menu link.
   *
   * @var \Drupal\views\Plugin\Menu\ViewsMenuLink
   */
  protected $menuLink;

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

    // Put the title field first.
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Title'),
      // @todo Ensure that the view is not loaded with a localized title.
      //   https://www.drupal.org/node/2309507
      '#default_value' => $this->menuLink
        ->getTitle(),
      '#weight' => -10,
    );
    $form['description'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Description'),
      '#description' => $this
        ->t('Shown when hovering over the menu link.'),
      // @todo Ensure that the view is not loaded with a localized description.
      //   https://www.drupal.org/node/2309507
      '#default_value' => $this->menuLink
        ->getDescription(),
      '#weight' => -5,
    );
    $form += parent::buildConfigurationForm($form, $form_state);
    $form['info']['#weight'] = -8;
    $form['path']['#weight'] = -7;
    $view = $this->menuLink
      ->loadView();
    $id = $view->storage
      ->id();
    $label = $view->storage
      ->label();
    if ($this->moduleHandler
      ->moduleExists('views_ui')) {
      $message = $this
        ->t('This link is provided by the Views module. The path can be changed by editing the view <a href=":url">@label</a>', array(
        ':url' => \Drupal::url('entity.view.edit_form', array(
          'view' => $id,
        )),
        '@label' => $label,
      ));
    }
    else {
      $message = $this
        ->t('This link is provided by the Views module from view %label.', array(
        '%label' => $label,
      ));
    }
    $form['info']['#title'] = $message;
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function extractFormValues(array &$form, FormStateInterface $form_state) {
    $definition = parent::extractFormValues($form, $form_state);
    $definition['title'] = $form_state
      ->getValue('title');
    $definition['description'] = $form_state
      ->getValue('description');
    return $definition;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MenuLinkDefaultForm::$menuLinkManager protected property The menu link manager.
MenuLinkDefaultForm::$menuParentSelector protected property The parent form selector service.
MenuLinkDefaultForm::$moduleData protected property The module data from system_get_info().
MenuLinkDefaultForm::$moduleHandler protected property The module handler service.
MenuLinkDefaultForm::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
MenuLinkDefaultForm::setMenuLinkInstance public function Injects the menu link plugin instance. Overrides MenuLinkFormInterface::setMenuLinkInstance
MenuLinkDefaultForm::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
MenuLinkDefaultForm::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
MenuLinkDefaultForm::__construct public function Constructs a new \Drupal\Core\Menu\Form\MenuLinkDefaultForm.
StringTranslationTrait::$stringTranslation protected property The string translation service.
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.
ViewsMenuLinkForm::$menuLink protected property The edited views menu link. Overrides MenuLinkDefaultForm::$menuLink
ViewsMenuLinkForm::buildConfigurationForm public function Form constructor. Overrides MenuLinkDefaultForm::buildConfigurationForm
ViewsMenuLinkForm::extractFormValues public function Extracts a plugin definition from form values. Overrides MenuLinkDefaultForm::extractFormValues