You are here

public function Link::buildOptionsForm in Views link area 8

Provide a form to edit options for this plugin.

Overrides TokenizeAreaPluginBase::buildOptionsForm

File

src/Plugin/views/area/Link.php, line 113

Class

Link
Views area Link handler.

Namespace

Drupal\views_linkarea\Plugin\views\area

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['link_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link text'),
    '#default_value' => $this->options['link_text'],
    '#description' => $this
      ->t('The text to use for the link. May use tokens.'),
    '#required' => TRUE,
  ];
  $form['path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link path'),
    '#default_value' => $this->options['path'],
    '#description' => $this
      ->t('The Drupal path, Drupal URI, or absolute URL for this link. Drupal URIs include the entity: and route: schemes. You may append a query string and fragment. You may use token replacements.'),
    '#maxlength' => 255,
  ];
  $form['output_as_action'] = [
    '#title' => $this
      ->t('Output as action'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['output_as_action'],
    '#description' => $this
      ->t('Outputs the link as an "action button", themed like the links in the "Primary admin actions" block.'),
  ];
  $form['destination'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include destination'),
    '#default_value' => $this->options['destination'],
    '#description' => $this
      ->t('Include a "destination" parameter in the link to return the user to the original view upon completing the link action.'),
  ];
  $form['replace_spaces'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace spaces with dashes'),
    '#default_value' => $this->options['replace_spaces'],
  ];
  $form['external'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('External server URL'),
    '#default_value' => $this->options['external'],
    '#description' => $this
      ->t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
  ];
  $form['path_case'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Transform the case'),
    '#description' => $this
      ->t('When printing URL paths, how to transform the case of the filter value.'),
    '#options' => [
      'none' => $this
        ->t('No transform'),
      'upper' => $this
        ->t('Upper case'),
      'lower' => $this
        ->t('Lower case'),
      'ucfirst' => $this
        ->t('Capitalize first letter'),
      'ucwords' => $this
        ->t('Capitalize each word'),
    ],
    '#default_value' => $this->options['path_case'],
  ];
  $form['link_class'] = [
    '#title' => $this
      ->t('Link class'),
    '#type' => 'textfield',
    '#default_value' => $this->options['link_class'],
    '#description' => $this
      ->t('The CSS class to apply to the link. May use tokens.'),
  ];
  $form['alt'] = [
    '#title' => $this
      ->t('Title text'),
    '#type' => 'textfield',
    '#default_value' => $this->options['alt'],
    '#description' => $this
      ->t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link. May use tokens.'),
  ];
  $form['rel'] = [
    '#title' => $this
      ->t('Rel Text'),
    '#type' => 'textfield',
    '#default_value' => $this->options['rel'],
    '#description' => $this
      ->t('Include Rel attribute for use in lightbox2 or other javascript utility. May use tokens.'),
  ];
  $form['prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Prefix'),
    '#default_value' => $this->options['prefix'],
    '#description' => $this
      ->t('Any text to display before this link. You may include HTML and tokens.'),
  ];
  $form['suffix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Suffix'),
    '#default_value' => $this->options['suffix'],
    '#description' => $this
      ->t('Any text to display after this link. You may include HTML and tokens.'),
  ];
  $form['target'] = [
    '#title' => $this
      ->t('Target'),
    '#type' => 'textfield',
    '#default_value' => $this->options['target'],
    '#description' => $this
      ->t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used. May use tokens."),
  ];
  $form['advanced_opts'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced Options'),
    '#weight' => 50,
  ];
  $form['absolute'] = [
    '#fieldset' => 'advanced_opts',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use absolute path'),
    '#default_value' => $this->options['absolute'],
    '#description' => $this
      ->t('Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.'),
  ];
  $form['rewrite_output'] = [
    '#fieldset' => 'advanced_opts',
    '#type' => 'textarea',
    '#title' => $this
      ->t('Rewrite output'),
    '#default_value' => $this->options['rewrite_output'],
    '#description' => $this
      ->t('Use this to output whatever HTML you want with the link created usable via the token {{views_linkarea}}. Global tokens available as well.'),
  ];
  $form['access_denied_text'] = [
    '#fieldset' => 'advanced_opts',
    '#type' => 'textarea',
    '#title' => $this
      ->t('Content when access is denied'),
    '#default_value' => $this->options['access_denied_text'],
    '#description' => $this
      ->t('Use this to output whatever you want to display when access to the link is denied to the user. Tokens allowed.'),
  ];
  $form['language'] = [
    '#fieldset' => 'advanced_opts',
    '#type' => 'radios',
    '#title' => $this
      ->t('Language'),
    '#default_value' => $this->options['language'],
    '#options' => [
      '**auto**' => $this
        ->t('Current language'),
    ] + $this
      ->listLanguages(LanguageInterface::STATE_ALL | LanguageInterface::STATE_SITE_DEFAULT, [
      $this->options['language'],
    ]),
  ];
  if (!$this->languageManager
    ->isMultilingual()) {
    $form['language']['#description'] = $this
      ->t('This will not take effect until you turn on multilingual capabilities');
  }
}