trait CshsTaxonomyIndex in Client-side Hierarchical Select 8
Same name and namespace in other branches
- 8.3 src/Plugin/views/filter/CshsTaxonomyIndex.php \Drupal\cshs\Plugin\views\filter\CshsTaxonomyIndex
- 8.2 src/Plugin/views/filter/CshsTaxonomyIndex.php \Drupal\cshs\Plugin\views\filter\CshsTaxonomyIndex
Common implementation for "CshsTaxonomyIndex" plugin.
Hierarchy
- trait \Drupal\cshs\Plugin\views\filter\CshsTaxonomyIndex uses CshsOptionsFromHelper
File
- src/
Plugin/ views/ filter/ CshsTaxonomyIndex.php, line 18
Namespace
Drupal\cshs\Plugin\views\filterView source
trait CshsTaxonomyIndex {
use CshsOptionsFromHelper;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : self {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
\assert($instance instanceof self);
$instance->entityRepository = $container
->get('entity.repository');
return $instance;
}
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) : void {
$options['value'] = isset($options['value']) ? (array) $options['value'] : [];
parent::init($view, $display, $options);
}
/**
* {@inheritdoc}
*/
public function defineOptions() : array {
$options = parent::defineOptions();
foreach (static::defaultSettings() + [
'type' => CshsElement::ID,
] as $option => $value) {
$options[$option] = [
'default' => $value,
];
}
return $options;
}
/**
* {@inheritdoc}
*/
public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) : void {
parent::buildExtraOptionsForm($form, $form_state);
$form['type']['#options'] += [
CshsElement::ID => $this
->t('Client-side Hierarchical Select'),
];
}
/**
* {@inheritdoc}
*/
public function buildExposeForm(&$form, FormStateInterface $form_state) : void {
parent::buildExposeForm($form, $form_state);
if (CshsElement::ID === $this->options['type']) {
// Disable the "multiple" option in the exposed form settings.
$form['expose']['multiple']['#access'] = FALSE;
$form += $this
->settingsForm($form, $form_state);
}
}
/**
* {@inheritdoc}
*/
public function valueForm(&$form, FormStateInterface $form_state) : void {
parent::valueForm($form, $form_state);
if ($this->options['limit'] && $this
->getVocabulary() === NULL) {
$form['markup'] = [
'#type' => 'item',
'#markup' => $this
->t('An invalid vocabulary is selected. Please change it in the options.'),
];
}
elseif (CshsElement::ID === $this->options['type']) {
$form['value'] = \array_merge($form['value'], $this
->formElement(), [
'#multiple' => FALSE,
'#default_value' => (array) $form['value']['#default_value'],
]);
}
}
/**
* {@inheritdoc}
*/
public function getSettings() : array {
return $this->options;
}
/**
* {@inheritdoc}
*/
public function getSetting($key) {
return $this->options[$key] ?? NULL;
}
/**
* {@inheritdoc}
*/
protected function getVocabularyStorage() : VocabularyStorageInterface {
return $this->vocabularyStorage;
}
/**
* {@inheritdoc}
*/
protected function getTermStorage() : TermStorageInterface {
return $this->termStorage;
}
/**
* {@inheritdoc}
*/
public function getVocabulary() : ?VocabularyInterface {
return $this->vocabularyStorage
->load($this->options['vid']);
}
/**
* Returns the views filter configuration schema.
*
* @return array
* The config schema, provided in addition to the parent implementation.
*
* @see taxonomy.views.schema.yml
* @see \cshs_config_schema_info_alter()
*/
public static function getConfigSchema() : array {
return [
'save_lineage' => [
'type' => 'boolean',
'label' => 'Save lineage',
],
'force_deepest' => [
'type' => 'boolean',
'label' => 'Force selection of deepest level',
],
'parent' => [
'type' => 'integer',
'label' => 'Parent',
],
'level_labels' => [
'type' => 'string',
'label' => 'Labels per hierarchy-level',
],
'hierarchy_depth' => [
'type' => 'integer',
'label' => 'Hierarchy depth',
],
'required_depth' => [
'type' => 'integer',
'label' => 'Required depth',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CshsOptionsFromHelper:: |
public static | function | Defines the default settings for this plugin. | |
CshsOptionsFromHelper:: |
public | function | Returns the form for a single widget. | |
CshsOptionsFromHelper:: |
private | function | Collects the options. | |
CshsOptionsFromHelper:: |
private | function | Returns translated labels with escaped markup. | |
CshsOptionsFromHelper:: |
public | function | Returns a form to configure settings. | |
CshsOptionsFromHelper:: |
public | function | Returns a short summary for the settings. | |
CshsOptionsFromHelper:: |
public | function | Validates the settings form. | |
CshsTaxonomyIndex:: |
public | function | ||
CshsTaxonomyIndex:: |
public | function | ||
CshsTaxonomyIndex:: |
public static | function | ||
CshsTaxonomyIndex:: |
public | function | ||
CshsTaxonomyIndex:: |
public static | function | Returns the views filter configuration schema. | |
CshsTaxonomyIndex:: |
public | function |
Returns the value of a setting, or its default value if absent. Overrides CshsOptionsFromHelper:: |
|
CshsTaxonomyIndex:: |
public | function |
Returns the array of settings, including defaults for missing settings. Overrides CshsOptionsFromHelper:: |
|
CshsTaxonomyIndex:: |
protected | function |
Returns storage of the "taxonomy_term" entities. Overrides TaxonomyStorages:: |
|
CshsTaxonomyIndex:: |
public | function |
Returns the taxonomy vocabulary to work with. Overrides CshsOptionsFromHelper:: |
|
CshsTaxonomyIndex:: |
protected | function |
Returns storage of the "taxonomy_vocabulary" entities. Overrides TaxonomyStorages:: |
|
CshsTaxonomyIndex:: |
public | function | ||
CshsTaxonomyIndex:: |
public | function | ||
TaxonomyStorages:: |
protected | property | An instance of the "entity.repository" service. | |
TaxonomyStorages:: |
protected | property | An instance of the "entity_type.manager" service. | |
TaxonomyStorages:: |
private | property | The state of whether content translation should be used. | |
TaxonomyStorages:: |
private | function | Returns the entity storage. | |
TaxonomyStorages:: |
protected | function | Returns the entity translation to be used in the given context. | |
TaxonomyStorages:: |
protected | function | Returns the state of whether content translation needed. |