Commit d7d1dfa9 authored by alexpott's avatar alexpott

Issue #2578433 by longwave, hussainweb:...

Issue #2578433 by longwave, hussainweb: \Drupal\views\Plugin\views\filter\FieldList uses undefined function
parent 60b75a2d
# Schema for the views plugins of the Field module.
views.argument.field_list:
type: views.argument.numeric
label: 'List field name'
mapping:
human:
type: boolean
label: 'Display list value as human readable'
views.argument.field_list_string:
type: views.argument.string
label: 'List field name'
mapping:
human:
type: boolean
label: 'Display list value as human readable'
views.filter.field_list:
type: views.filter.many_to_one
label: 'List field'
views.relationship.entity_reverse:
type: views_relationship
label: 'Reverse entity reference'
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\argument\FieldList.
*/
namespace Drupal\views\Plugin\views\argument;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\argument\NumericArgument;
/**
* Argument handler for list field to show the human readable name in the
* summary.
*
* @ingroup views_argument_handlers
*
* @ViewsArgument("field_list")
*/
class FieldList extends NumericArgument {
use AllowedTagsXssTrait;
/**
* Stores the allowed values of this field.
*
* @var array
*/
var $allowed_values = NULL;
/**
* Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
$field_storage = $field_storage_definitions[$this->definition['field_name']];
$this->allowed_values = options_allowed_values($field_storage);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['summary']['contains']['human'] = array('default' => FALSE);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['summary']['human'] = array(
'#title' => $this->t('Display list value as human readable'),
'#type' => 'checkbox',
'#default_value' => $this->options['summary']['human'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
),
),
);
}
public function summaryName($data) {
$value = $data->{$this->name_alias};
// If the list element has a human readable name show it,
if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
return FieldFilteredMarkup::create($this->allowed_values[$value]);
}
// else fallback to the key.
else {
return $value;
}
}
}
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\argument\ListString.
*/
namespace Drupal\views\Plugin\views\argument;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\argument\StringArgument;
/**
* Argument handler for list field to show the human readable name in the
* summary.
*
* @ingroup views_argument_handlers
*
* @ViewsArgument("field_list_string")
*/
class ListString extends StringArgument {
use AllowedTagsXssTrait;
/**
* Stores the allowed values of this field.
*
* @var array
*/
var $allowed_values = NULL;
/**
* Overrides \Drupal\views\Plugin\views\argument\StringArgument::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
$field_storage = $field_storage_definitions[$this->definition['field_name']];
$this->allowed_values = options_allowed_values($field_storage);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['summary']['contains']['human'] = array('default' => FALSE);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['summary']['human'] = array(
'#title' => $this->t('Display list value as human readable'),
'#type' => 'checkbox',
'#default_value' => $this->options['summary']['human'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
),
),
);
}
public function summaryName($data) {
$value = $data->{$this->name_alias};
// If the list element has a human readable name show it,
if (isset($this->allowed_values[$value]) && !empty($this->options['summary']['human'])) {
$value = $this->allowed_values[$value];
}
return FieldFilteredMarkup::create($this->caseTransform($value, $this->options['case']));
}
}
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\filter\FieldList.
*/
namespace Drupal\views\Plugin\views\filter;
/**
* Filter handler which uses list-fields as options.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("field_list")
*/
class FieldList extends ManyToOne {
public function getValueOptions() {
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
$field_storage = $field_storage_definitions[$this->definition['field_name']];
$this->valueOptions = list_allowed_values($field_storage);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment