You are here

public function DisplayPluginBase::optionLink in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::optionLink()

Returns a link to a section of a form.

Because forms may be split up into sections, this provides an easy URL to exactly the right section. Don't override this.

Overrides DisplayPluginInterface::optionLink

1 call to DisplayPluginBase::optionLink()
DisplayPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Provide a form to edit options for this plugin.

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 1018

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function optionLink($text, $section, $class = '', $title = '') {
  if (!trim($text)) {
    $text = $this
      ->t('Broken field');
  }
  if (!empty($class)) {
    $text = new FormattableMarkup('<span>@text</span>', [
      '@text' => $text,
    ]);
  }
  if (empty($title)) {
    $title = $text;
  }
  return Link::fromTextAndUrl($text, Url::fromRoute('views_ui.form_display', [
    'js' => 'nojs',
    'view' => $this->view->storage
      ->id(),
    'display_id' => $this->display['id'],
    'type' => $section,
  ], [
    'attributes' => [
      'class' => [
        'views-ajax-link',
        $class,
      ],
      'title' => $title,
      'id' => Html::getUniqueId('views-' . $this->display['id'] . '-' . $section),
    ],
  ]))
    ->toString();
}