class DefaultFilter in Typed Data API enhancements 8
A data filter providing a default value if no value is set.
Plugin annotation
@DataFilter(
id = "default",
label = @Translation("Applies a default value if there is no value."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\typed_data\DataFilterBase implements DataFilterInterface uses StringTranslationTrait, TypedDataTrait
- class \Drupal\typed_data\Plugin\TypedDataFilter\DefaultFilter
- class \Drupal\typed_data\DataFilterBase implements DataFilterInterface uses StringTranslationTrait, TypedDataTrait
Expanded class hierarchy of DefaultFilter
File
- src/
Plugin/ TypedDataFilter/ DefaultFilter.php, line 18
Namespace
Drupal\typed_data\Plugin\TypedDataFilterView source
class DefaultFilter extends DataFilterBase {
/**
* {@inheritdoc}
*/
public function filter(DataDefinitionInterface $definition, $value, array $arguments, BubbleableMetadata $bubbleable_metadata = NULL) {
return isset($value) ? $value : $arguments[0];
}
/**
* {@inheritdoc}
*/
public function canFilter(DataDefinitionInterface $definition) {
return is_subclass_of($definition
->getClass(), StringInterface::class);
}
/**
* {@inheritdoc}
*/
public function filtersTo(DataDefinitionInterface $definition, array $arguments) {
return $definition;
}
/**
* {@inheritdoc}
*/
public function allowsNullValues() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getNumberOfRequiredArguments() {
return 1;
}
/**
* {@inheritdoc}
*/
public function validateArguments(DataDefinitionInterface $definition, array $arguments) {
$errors = parent::validateArguments($definition, $arguments);
if (isset($arguments[0])) {
// Ensure the provided value is given for this data.
$violations = $this
->getTypedDataManager()
->create($definition, $arguments[0])
->validate();
foreach ($violations as $violation) {
$errors[] = $violation
->getMessage();
}
}
return $errors;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DataFilterBase:: |
protected | property | The filter id. | |
DataFilterBase:: |
protected | property |
The plugin definition. Overrides PluginBase:: |
|
DataFilterBase:: |
public | function |
Suggests some possible argument values based on user input. Overrides DataFilterInterface:: |
|
DataFilterBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
DefaultFilter:: |
public | function |
Defines whether the filter is able to process NULL values. Overrides DataFilterBase:: |
|
DefaultFilter:: |
public | function |
Determines whether data based upon the given definition can be filtered. Overrides DataFilterInterface:: |
|
DefaultFilter:: |
public | function |
Filters the given data value. Overrides DataFilterInterface:: |
|
DefaultFilter:: |
public | function |
Describes the data after applying the filter. Overrides DataFilterInterface:: |
|
DefaultFilter:: |
public | function |
Gets the number of required arguments. Overrides DataFilterBase:: |
|
DefaultFilter:: |
public | function |
Validates the inputted arguments. Overrides DataFilterBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |