View source
<?php
namespace Drupal\views\Plugin\views\argument;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\HandlerBase;
use Drupal\views\Views;
abstract class ArgumentPluginBase extends HandlerBase implements CacheableDependencyInterface {
var $validator = NULL;
var $argument = NULL;
var $value = NULL;
var $name_table;
var $name_field;
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
if (!empty($this->definition['name field'])) {
$this->name_field = $this->definition['name field'];
}
if (!empty($this->definition['name table'])) {
$this->name_table = $this->definition['name table'];
}
}
public function isException($arg = NULL) {
if (!isset($arg)) {
$arg = isset($this->argument) ? $this->argument : NULL;
}
return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg;
}
public function exceptionTitle() {
if (empty($this->options['exception']['title_enable'])) {
return $this
->getTitle();
}
return $this->options['exception']['title'];
}
public function needsStylePlugin() {
$info = $this
->defaultActions($this->options['default_action']);
$validate_info = $this
->defaultActions($this->options['validate']['fail']);
return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['default_action'] = array(
'default' => 'ignore',
);
$options['exception'] = array(
'contains' => array(
'value' => array(
'default' => 'all',
),
'title_enable' => array(
'default' => FALSE,
),
'title' => array(
'default' => 'All',
),
),
);
$options['title_enable'] = array(
'default' => FALSE,
);
$options['title'] = array(
'default' => '',
);
$options['default_argument_type'] = array(
'default' => 'fixed',
);
$options['default_argument_options'] = array(
'default' => array(),
);
$options['default_argument_skip_url'] = array(
'default' => FALSE,
);
$options['summary_options'] = array(
'default' => array(),
);
$options['summary'] = array(
'contains' => array(
'sort_order' => array(
'default' => 'asc',
),
'number_of_records' => array(
'default' => 0,
),
'format' => array(
'default' => 'default_summary',
),
),
);
$options['specify_validation'] = array(
'default' => FALSE,
);
$options['validate'] = array(
'contains' => array(
'type' => array(
'default' => 'none',
),
'fail' => array(
'default' => 'not found',
),
),
);
$options['validate_options'] = array(
'default' => array(),
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$argument_text = $this->view->display_handler
->getArgumentText();
$form['#pre_render'][] = array(
get_class($this),
'preRenderMoveArgumentOptions',
);
$form['description'] = array(
'#markup' => $argument_text['description'],
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'class' => array(
'description',
),
),
);
$form['no_argument'] = array(
'#type' => 'details',
'#title' => $argument_text['filter value not present'],
'#open' => TRUE,
);
$form['no_argument']['clearfix'] = array(
'#weight' => 1000,
'#markup' => '<div class="clearfix"></div>',
);
$form['default_action'] = array(
'#title' => $this
->t('Default actions'),
'#title_display' => 'invisible',
'#type' => 'radios',
'#process' => array(
array(
$this,
'processContainerRadios',
),
),
'#default_value' => $this->options['default_action'],
'#fieldset' => 'no_argument',
);
$form['exception'] = array(
'#type' => 'details',
'#title' => $this
->t('Exceptions'),
'#fieldset' => 'no_argument',
);
$form['exception']['value'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Exception value'),
'#size' => 20,
'#default_value' => $this->options['exception']['value'],
'#description' => $this
->t('If this value is received, the filter will be ignored; i.e, "all values"'),
);
$form['exception']['title_enable'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Override title'),
'#default_value' => $this->options['exception']['title_enable'],
);
$form['exception']['title'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Override title'),
'#title_display' => 'invisible',
'#size' => 20,
'#default_value' => $this->options['exception']['title'],
'#description' => $this
->t('Override the view and other argument titles. You may use Twig syntax in this field as well as the "arguments" and "raw_arguments" arrays.'),
'#states' => array(
'visible' => array(
':input[name="options[exception][title_enable]"]' => array(
'checked' => TRUE,
),
),
),
);
$options = array();
$defaults = $this
->defaultActions();
$validate_options = array();
foreach ($defaults as $id => $info) {
$options[$id] = $info['title'];
if (empty($info['default only'])) {
$validate_options[$id] = $info['title'];
}
if (!empty($info['form method'])) {
$this
->{$info['form method']}($form, $form_state);
}
}
$form['default_action']['#options'] = $options;
$form['argument_present'] = array(
'#type' => 'details',
'#title' => $argument_text['filter value present'],
'#open' => TRUE,
);
$form['title_enable'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Override title'),
'#default_value' => $this->options['title_enable'],
'#fieldset' => 'argument_present',
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Provide title'),
'#title_display' => 'invisible',
'#default_value' => $this->options['title'],
'#description' => $this
->t('Override the view and other argument titles. You may use Twig syntax in this field.'),
'#states' => array(
'visible' => array(
':input[name="options[title_enable]"]' => array(
'checked' => TRUE,
),
),
),
'#fieldset' => 'argument_present',
);
$output = $this
->getTokenHelp();
$form['token_help'] = [
'#type' => 'details',
'#title' => $this
->t('Replacement patterns'),
'#value' => $output,
'#states' => [
'visible' => [
[
':input[name="options[title_enable]"]' => [
'checked' => TRUE,
],
],
[
':input[name="options[exception][title_enable]"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['specify_validation'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Specify validation criteria'),
'#default_value' => $this->options['specify_validation'],
'#fieldset' => 'argument_present',
);
$form['validate'] = array(
'#type' => 'container',
'#fieldset' => 'argument_present',
);
$form['validate']['type'] = array(
'#type' => 'select',
'#title' => $this
->t('Validator'),
'#default_value' => static::encodeValidatorId($this->options['validate']['type']),
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array(
'checked' => TRUE,
),
),
),
);
$plugins = Views::pluginManager('argument_validator')
->getDefinitions();
foreach ($plugins as $id => $info) {
if (!empty($info['no_ui'])) {
continue;
}
$valid = TRUE;
if (!empty($info['type'])) {
$valid = FALSE;
if (empty($this->definition['validate type'])) {
continue;
}
foreach ((array) $info['type'] as $type) {
if ($type == $this->definition['validate type']) {
$valid = TRUE;
break;
}
}
}
if ($valid) {
$plugin = $this
->getPlugin('argument_validator', $id);
if ($plugin) {
if ($plugin
->access() || $this->options['validate']['type'] == $id) {
$sanitized_id = static::encodeValidatorId($id);
$form['validate']['options'][$sanitized_id] = array(
'#prefix' => '<div id="edit-options-validate-options-' . $sanitized_id . '-wrapper">',
'#suffix' => '</div>',
'#type' => 'item',
'#input' => TRUE,
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array(
'checked' => TRUE,
),
':input[name="options[validate][type]"]' => array(
'value' => $sanitized_id,
),
),
),
'#id' => 'edit-options-validate-options-' . $sanitized_id,
'#default_value' => array(),
);
$plugin
->buildOptionsForm($form['validate']['options'][$sanitized_id], $form_state);
$validate_types[$sanitized_id] = $info['title'];
}
}
}
}
asort($validate_types);
$form['validate']['type']['#options'] = $validate_types;
$form['validate']['fail'] = array(
'#type' => 'select',
'#title' => $this
->t('Action to take if filter value does not validate'),
'#default_value' => $this->options['validate']['fail'],
'#options' => $validate_options,
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array(
'checked' => TRUE,
),
),
),
'#fieldset' => 'argument_present',
);
}
protected function getTokenHelp() {
$output = [];
foreach ($this->view->display_handler
->getHandlers('argument') as $arg => $handler) {
$options[(string) t('Arguments')]["{{ arguments.{$arg} }}"] = $this
->t('@argument title', array(
'@argument' => $handler
->adminLabel(),
));
$options[(string) t('Arguments')]["{{ raw_arguments.{$arg} }}"] = $this
->t('@argument input', array(
'@argument' => $handler
->adminLabel(),
));
}
if (!empty($options)) {
$output[] = [
'#markup' => '<p>' . $this
->t("The following replacement tokens are available for this argument.") . '</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[] = $item_list;
}
}
}
return $output;
}
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$option_values =& $form_state
->getValue('options');
if (empty($option_values)) {
return;
}
$default_id = $option_values['default_argument_type'];
$plugin = $this
->getPlugin('argument_default', $default_id);
if ($plugin) {
$plugin
->validateOptionsForm($form['argument_default'][$default_id], $form_state, $option_values['argument_default'][$default_id]);
}
$summary_id = $option_values['summary']['format'];
$plugin = $this
->getPlugin('style', $summary_id);
if ($plugin) {
$plugin
->validateOptionsForm($form['summary']['options'][$summary_id], $form_state, $option_values['summary']['options'][$summary_id]);
}
$sanitized_id = $option_values['validate']['type'];
$validate_id = static::decodeValidatorId($sanitized_id);
$plugin = $this
->getPlugin('argument_validator', $validate_id);
if ($plugin) {
$plugin
->validateOptionsForm($form['validate']['options'][$default_id], $form_state, $option_values['validate']['options'][$sanitized_id]);
}
}
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$option_values =& $form_state
->getValue('options');
if (empty($option_values)) {
return;
}
$default_id = $option_values['default_argument_type'];
$plugin = $this
->getPlugin('argument_default', $default_id);
if ($plugin) {
$options =& $option_values['argument_default'][$default_id];
$plugin
->submitOptionsForm($form['argument_default'][$default_id], $form_state, $options);
$option_values['default_argument_options'] = $options;
}
$summary_id = $option_values['summary']['format'];
$plugin = $this
->getPlugin('style', $summary_id);
if ($plugin) {
$options =& $option_values['summary']['options'][$summary_id];
$plugin
->submitOptionsForm($form['summary']['options'][$summary_id], $form_state, $options);
$option_values['summary_options'] = $options;
}
if (empty($option_values['specify_validation'])) {
$option_values['validate']['type'] = 'none';
$option_values['validate']['options'] = [
'none' => [],
];
$option_values['validate']['fail'] = 'not found';
}
$sanitized_id = $option_values['validate']['type'];
$option_values['validate']['type'] = $validate_id = static::decodeValidatorId($sanitized_id);
$plugin = $this
->getPlugin('argument_validator', $validate_id);
if ($plugin) {
$options =& $option_values['validate']['options'][$sanitized_id];
$plugin
->submitOptionsForm($form['validate']['options'][$sanitized_id], $form_state, $options);
$option_values['validate_options'] = $options;
}
if (empty($option_values['title_enable'])) {
$option_values['title'] = '';
}
}
protected function defaultActions($which = NULL) {
$defaults = array(
'ignore' => array(
'title' => $this
->t('Display all results for the specified field'),
'method' => 'defaultIgnore',
),
'default' => array(
'title' => $this
->t('Provide default value'),
'method' => 'defaultDefault',
'form method' => 'defaultArgumentForm',
'has default argument' => TRUE,
'default only' => TRUE,
),
'not found' => array(
'title' => $this
->t('Hide view'),
'method' => 'defaultNotFound',
'hard fail' => TRUE,
),
'summary' => array(
'title' => $this
->t('Display a summary'),
'method' => 'defaultSummary',
'form method' => 'defaultSummaryForm',
'style plugin' => TRUE,
),
'empty' => array(
'title' => $this
->t('Display contents of "No results found"'),
'method' => 'defaultEmpty',
),
'access denied' => array(
'title' => $this
->t('Display "Access Denied"'),
'method' => 'defaultAccessDenied',
),
);
if ($this->view->display_handler
->hasPath()) {
$defaults['not found']['title'] = $this
->t('Show "Page not found"');
}
if ($which) {
if (!empty($defaults[$which])) {
return $defaults[$which];
}
}
else {
return $defaults;
}
}
public function defaultArgumentForm(&$form, FormStateInterface $form_state) {
$plugins = Views::pluginManager('argument_default')
->getDefinitions();
$options = array();
$form['default_argument_skip_url'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Skip default argument for view URL'),
'#default_value' => $this->options['default_argument_skip_url'],
'#description' => $this
->t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.'),
);
$form['default_argument_type'] = array(
'#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
'#suffix' => '</div>',
'#type' => 'select',
'#id' => 'edit-options-default-argument-type',
'#title' => $this
->t('Type'),
'#default_value' => $this->options['default_argument_type'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'default',
),
),
),
'#argument_option' => 'default',
);
foreach ($plugins as $id => $info) {
if (!empty($info['no_ui'])) {
continue;
}
$plugin = $this
->getPlugin('argument_default', $id);
if ($plugin) {
if ($plugin
->access() || $this->options['default_argument_type'] == $id) {
$form['argument_default']['#argument_option'] = 'default';
$form['argument_default'][$id] = array(
'#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
'#suffix' => '</div>',
'#id' => 'edit-options-argument-default-options-' . $id,
'#type' => 'item',
'#input' => TRUE,
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'default',
),
':input[name="options[default_argument_type]"]' => array(
'value' => $id,
),
),
),
'#default_value' => array(),
);
$options[$id] = $info['title'];
$plugin
->buildOptionsForm($form['argument_default'][$id], $form_state);
}
}
}
asort($options);
$form['default_argument_type']['#options'] = $options;
}
public function defaultSummaryForm(&$form, FormStateInterface $form_state) {
$style_plugins = Views::pluginManager('style')
->getDefinitions();
$summary_plugins = array();
$format_options = array();
foreach ($style_plugins as $key => $plugin) {
if (isset($plugin['display_types']) && in_array('summary', $plugin['display_types'])) {
$summary_plugins[$key] = $plugin;
$format_options[$key] = $plugin['title'];
}
}
$form['summary'] = array(
'#argument_option' => 'summary',
);
$form['summary']['sort_order'] = array(
'#type' => 'radios',
'#title' => $this
->t('Sort order'),
'#options' => array(
'asc' => $this
->t('Ascending'),
'desc' => $this
->t('Descending'),
),
'#default_value' => $this->options['summary']['sort_order'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'summary',
),
),
),
);
$form['summary']['number_of_records'] = array(
'#type' => 'radios',
'#title' => $this
->t('Sort by'),
'#default_value' => $this->options['summary']['number_of_records'],
'#options' => array(
0 => $this
->getSortName(),
1 => $this
->t('Number of records'),
),
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'summary',
),
),
),
);
$form['summary']['format'] = array(
'#type' => 'radios',
'#title' => $this
->t('Format'),
'#options' => $format_options,
'#default_value' => $this->options['summary']['format'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'summary',
),
),
),
);
foreach ($summary_plugins as $id => $info) {
$plugin = $this
->getPlugin('style', $id);
if (!$plugin
->usesOptions()) {
continue;
}
if ($plugin) {
$form['summary']['options'][$id] = array(
'#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
'#suffix' => '</div>',
'#id' => 'edit-options-summary-options-' . $id,
'#type' => 'item',
'#input' => TRUE,
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array(
'value' => 'summary',
),
':input[name="options[summary][format]"]' => array(
'value' => $id,
),
),
),
'#default_value' => array(),
);
$options[$id] = $info['title'];
$plugin
->buildOptionsForm($form['summary']['options'][$id], $form_state);
}
}
}
public function defaultAction($info = NULL) {
if (!isset($info)) {
$info = $this
->defaultActions($this->options['default_action']);
}
if (!$info) {
return FALSE;
}
if (!empty($info['method args'])) {
return call_user_func_array(array(
&$this,
$info['method'],
), $info['method args']);
}
else {
return $this
->{$info['method']}();
}
}
public function validateFail() {
$info = $this
->defaultActions($this->options['validate']['fail']);
return $this
->defaultAction($info);
}
public function defaultIgnore() {
return TRUE;
}
protected function defaultNotFound() {
$this->view->build_info['fail'] = TRUE;
return FALSE;
}
public function defaultAccessDenied() {
$this->view->build_info['denied'] = TRUE;
return FALSE;
}
public function defaultEmpty() {
$this->view->built = TRUE;
$this->view->executed = TRUE;
$this->view->result = array();
return FALSE;
}
protected function defaultDefault() {
return TRUE;
}
function hasDefaultArgument() {
$info = $this
->defaultActions($this->options['default_action']);
return !empty($info['has default argument']);
}
public function getDefaultArgument() {
$plugin = $this
->getPlugin('argument_default');
if ($plugin) {
return $plugin
->getArgument();
}
}
public function processSummaryArguments(&$args) {
if ($this->options['validate']['type'] != 'none') {
if (isset($this->validator) || ($this->validator = $this
->getPlugin('argument_validator'))) {
$this->validator
->processSummaryArguments($args);
}
}
}
protected function defaultSummary() {
$this->view->build_info['summary'] = TRUE;
$this->view->build_info['summary_level'] = $this->options['id'];
$this->view->style_plugin = Views::pluginManager("style")
->createInstance($this->options['summary']['format']);
$this->view->style_plugin
->init($this->view, $this->displayHandler, $this->options['summary_options']);
$this->query
->clearFields();
$this
->summaryQuery();
$by = $this->options['summary']['number_of_records'] ? 'num_records' : NULL;
$this
->summarySort($this->options['summary']['sort_order'], $by);
$this->view->build_sort = FALSE;
return TRUE;
}
protected function summaryQuery() {
$this
->ensureMyTable();
$this->base_alias = $this->query
->addField($this->tableAlias, $this->realField);
$this
->summaryNameField();
return $this
->summaryBasics();
}
protected function summaryNameField() {
if (isset($this->name_table)) {
if ($this->tableAlias != $this->name_table) {
$j = HandlerBase::getTableJoin($this->name_table, $this->table);
if ($j) {
$join = clone $j;
$join->leftTable = $this->tableAlias;
$this->name_table_alias = $this->query
->addTable($this->name_table, $this->relationship, $join);
}
}
else {
$this->name_table_alias = $this->query
->ensureTable($this->name_table, $this->relationship);
}
}
else {
$this->name_table_alias = $this->tableAlias;
}
if (isset($this->name_field)) {
$this->name_alias = $this->query
->addField($this->name_table_alias, $this->name_field);
}
else {
$this->name_alias = $this->base_alias;
}
}
public function summaryBasics($count_field = TRUE) {
$distinct = $this->view->display_handler
->getOption('distinct') && empty($this->query->no_distinct);
$count_alias = $this->query
->addField($this->view->storage
->get('base_table'), $this->view->storage
->get('base_field'), 'num_records', array(
'count' => TRUE,
'distinct' => $distinct,
));
$this->query
->addGroupBy($this->name_alias);
if ($count_field) {
$this->query
->setCountField($this->tableAlias, $this->realField);
}
$this->count_alias = $count_alias;
}
public function summarySort($order, $by = NULL) {
$this->query
->addOrderBy(NULL, NULL, $order, !empty($by) ? $by : $this->name_alias);
}
public function summaryArgument($data) {
return $data->{$this->base_alias};
}
public function summaryName($data) {
$value = $data->{$this->name_alias};
if (empty($value) && !empty($this->definition['empty field name'])) {
$value = $this->definition['empty field name'];
}
return $value;
}
public function query($group_by = FALSE) {
$this
->ensureMyTable();
$this->query
->addWhere(0, "{$this->tableAlias}.{$this->realField}", $this->argument);
}
function title() {
return $this->argument;
}
public function getTitle() {
if (isset($this->validated_title)) {
return $this->validated_title;
}
else {
return $this
->title();
}
}
public function validateArgument($arg) {
if (isset($this->argument_validated)) {
return $this->argument_validated;
}
if ($this
->isException($arg)) {
return $this->argument_validated = TRUE;
}
$plugin = $this
->getPlugin('argument_validator');
return $this->argument_validated = $plugin
->validateArgument($arg);
}
public function validateMenuArgument($arg) {
$validate_info = $this
->defaultActions($this->options['validate']['fail']);
if (empty($validate_info['hard fail'])) {
return TRUE;
}
$rc = $this
->validateArgument($arg);
$validate_info = $this
->defaultActions($this->options['validate']['fail']);
if (empty($validate_info['hard fail'])) {
return TRUE;
}
return $rc;
}
public function setArgument($arg) {
$this->argument = $arg;
return $this
->validateArgument($arg);
}
public function getValue() {
if (isset($this->argument)) {
return $this->argument;
}
$value = NULL;
$position = 0;
foreach ($this->view->argument as $id => $argument) {
if ($id == $this->options['id']) {
break;
}
$position++;
}
$arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL;
$this->position = $position;
$argument = clone $this;
if (!isset($arg) && $argument
->hasDefaultArgument()) {
$arg = $argument
->getDefaultArgument();
$this->is_default = TRUE;
}
if ($argument
->setArgument($arg)) {
$value = $argument->argument;
}
unset($argument);
return $value;
}
public function getPlugin($type = 'argument_default', $name = NULL) {
$options = array();
switch ($type) {
case 'argument_default':
if (!isset($this->options['default_argument_type'])) {
return;
}
$plugin_name = $this->options['default_argument_type'];
$options_name = 'default_argument_options';
break;
case 'argument_validator':
if (!isset($this->options['validate']['type'])) {
return;
}
$plugin_name = $this->options['validate']['type'];
$options_name = 'validate_options';
break;
case 'style':
if (!isset($this->options['summary']['format'])) {
return;
}
$plugin_name = $this->options['summary']['format'];
$options_name = 'summary_options';
}
if (!$name) {
$name = $plugin_name;
}
if ($name == $plugin_name) {
$options = isset($this->options[$options_name]) ? $this->options[$options_name] : [];
}
$plugin = Views::pluginManager($type)
->createInstance($name);
if ($plugin) {
$plugin
->init($this->view, $this->displayHandler, $options);
if ($type !== 'style') {
$plugin
->setArgument($this);
}
return $plugin;
}
}
public function getSortName() {
return $this
->t('Default sort', array(), array(
'context' => 'Sort order',
));
}
public static function processContainerRadios($element) {
if (count($element['#options']) > 0) {
foreach ($element['#options'] as $key => $choice) {
$element += array(
$key => array(),
);
$parents_for_id = array_merge($element['#parents'], array(
$key,
));
$element[$key] += array(
'#type' => 'radio',
'#title' => $choice,
'#return_value' => $key,
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
$element[$key . '_options'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'views-admin-dependent',
),
),
);
}
}
return $element;
}
public static function preRenderMoveArgumentOptions($form) {
foreach (Element::children($form) as $key) {
$element = $form[$key];
if (!empty($element['#argument_option'])) {
$container_name = $element['#argument_option'] . '_options';
if (isset($form['no_argument']['default_action'][$container_name])) {
$form['no_argument']['default_action'][$container_name][$key] = $element;
}
unset($form[$key]);
}
}
return $form;
}
public static function encodeValidatorId($id) {
return str_replace(':', '---', $id);
}
public static function decodeValidatorId($id) {
return str_replace('---', ':', $id);
}
protected function unpackArgumentValue($force_int = FALSE) {
$break = static::breakString($this->argument, $force_int);
$this->value = $break->value;
$this->operator = $break->operator;
}
public function getCacheMaxAge() {
$max_age = Cache::PERMANENT;
if (($plugin = $this
->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
$max_age = Cache::mergeMaxAges($max_age, $plugin
->getCacheMaxAge());
}
if (($plugin = $this
->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) {
$max_age = Cache::mergeMaxAges($max_age, $plugin
->getCacheMaxAge());
}
if (($plugin = $this
->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) {
$max_age = Cache::mergeMaxAges($max_age, $plugin
->getCacheMaxAge());
}
return $max_age;
}
public function getCacheContexts() {
$contexts = [];
$contexts[] = 'url';
if (($plugin = $this
->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
$contexts = Cache::mergeContexts($contexts, $plugin
->getCacheContexts());
}
if (($plugin = $this
->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) {
$contexts = Cache::mergeContexts($contexts, $plugin
->getCacheContexts());
}
if (($plugin = $this
->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) {
$contexts = Cache::mergeContexts($contexts, $plugin
->getCacheContexts());
}
return $contexts;
}
public function getCacheTags() {
$tags = [];
if (($plugin = $this
->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
$tags = Cache::mergeTags($tags, $plugin
->getCacheTags());
}
if (($plugin = $this
->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) {
$tags = Cache::mergeTags($tags, $plugin
->getCacheTags());
}
if (($plugin = $this
->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) {
$tags = Cache::mergeTags($tags, $plugin
->getCacheTags());
}
return $tags;
}
public function calculateDependencies() {
$dependencies = [];
if (($argument_default = $this
->getPlugin('argument_default')) && $argument_default instanceof DependentPluginInterface) {
$dependencies = NestedArray::mergeDeep($dependencies, $argument_default
->calculateDependencies());
}
if (($argument_validator = $this
->getPlugin('argument_validator')) && $argument_validator instanceof DependentPluginInterface) {
$dependencies = NestedArray::mergeDeep($dependencies, $argument_validator
->calculateDependencies());
}
if (($style = $this
->getPlugin('style')) && $style instanceof DependentPluginInterface) {
$dependencies = NestedArray::mergeDeep($dependencies, $style
->calculateDependencies());
}
return $dependencies;
}
}