You are here

public function CustomTag::buildOptionsForm in Views Custom Cache Tags 8

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

File

src/Plugin/views/cache/CustomTag.php, line 54
Contains \Drupal\views_custom_cache_tag\Plugin\views\cache\CustomTag.

Class

CustomTag
Simple caching of query results for Views displays.

Namespace

Drupal\views_custom_cache_tag\Plugin\views\cache

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['custom_tag'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Custom tag list'),
    '#description' => $this
      ->t('Custom tag list, separated by new lines. Caching based on custom cache tag must be manually cleared using custom code.'),
    '#default_value' => $this->options['custom_tag'],
  );

  // Setup the tokens for fields.
  $optgroup_arguments = (string) t('Arguments');
  foreach ($this->view->display_handler
    ->getHandlers('argument') as $arg => $handler) {
    $options[$optgroup_arguments]["{{ arguments.{$arg} }}"] = $this
      ->t('@argument title', array(
      '@argument' => $handler
        ->adminLabel(),
    ));
    $options[$optgroup_arguments]["{{ raw_arguments.{$arg} }}"] = $this
      ->t('@argument input', array(
      '@argument' => $handler
        ->adminLabel(),
    ));
  }

  // We have some options, so make a list.
  if (!empty($options)) {
    $output['description'] = [
      '#markup' => '<p>' . $this
        ->t("The following replacement tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.") . '</p>',
    ];
    foreach (array_keys($options) as $type) {
      if (!empty($options[$type])) {
        $items = array();
        foreach ($options[$type] as $key => $value) {
          $items[] = $key . ' == ' . $value;
        }
        $item_list = array(
          '#theme' => 'item_list',
          '#items' => $items,
        );
        $output['list'] = $item_list;
      }
    }
    $form['tokens'] = $output;
  }
}