You are here

public function BaseUrl::buildOptionsForm in Views base url 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/BaseUrl.php \Drupal\views_base_url\Plugin\views\field\BaseUrl::buildOptionsForm()

Default options form that provides the label widget that all fields should have.

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/BaseUrl.php, line 78

Class

BaseUrl
A handler to output site's base url.

Namespace

Drupal\views_base_url\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $form['show_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display as link'),
    '#description' => $this
      ->t('Show base URL as link. You can create a custom link using this option.'),
    '#default_value' => $this->options['show_link'],
  ];
  $form['show_link_options'] = [
    '#type' => 'container',
    '#states' => [
      'invisible' => [
        ':input[type=checkbox][name="options[show_link]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['show_link_options']['link_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link path'),
    '#description' => $this
      ->t('Drupal path for this link. The base url will be prepended to this path. If nothing provided then base url will appear as link.'),
    '#default_value' => $this->options['show_link_options']['link_path'],
  ];
  $form['show_link_options']['link_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link text'),
    '#description' => $this
      ->t('Link text. If nothing provided then link path will appear as link text.'),
    '#default_value' => $this->options['show_link_options']['link_text'],
  ];
  $form['show_link_options']['link_class'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link class'),
    '#description' => $this
      ->t('CSS class to be applied to this link.'),
    '#default_value' => $this->options['show_link_options']['link_class'],
  ];
  $form['show_link_options']['link_title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link title'),
    '#description' => $this
      ->t('Title attribute for this link.'),
    '#default_value' => $this->options['show_link_options']['link_title'],
  ];
  $form['show_link_options']['link_rel'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link rel'),
    '#description' => $this
      ->t('Rel attribute for this link.'),
    '#default_value' => $this->options['show_link_options']['link_rel'],
  ];
  $form['show_link_options']['link_fragment'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Fragment'),
    '#description' => $this
      ->t('Provide the ID with which you want to create fragment link.'),
    '#default_value' => $this->options['show_link_options']['link_fragment'],
  ];
  $form['show_link_options']['link_query'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link query'),
    '#description' => $this
      ->t('Attach queries to the link. If there are multiple queries separate them using a space. For eg: %example1 OR %example2', [
      '%example1' => 'destination=node/add/page',
      '%example2' => 'destination=node/add/page q=some/page',
    ]),
    '#default_value' => $this->options['show_link_options']['link_query'],
  ];
  $form['show_link_options']['link_target'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link target'),
    '#description' => $this
      ->t('Target attribute for this link.'),
    '#default_value' => $this->options['show_link_options']['link_target'],
  ];

  // This construct uses 'hidden' and not markup because process doesn't
  // run. It also has an extra div because the dependency wants to hide
  // the parent in situations like this, so we need a second div to
  // make this work.
  $form['show_link_options']['help'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Replacement patterns'),
    '#value' => $this
      ->getReplacementTokens(),
  ];
  parent::buildOptionsForm($form, $form_state);
}