trait ConfigActionsValidateTrait in Config Actions 8
Trait for adding options to perform path validation for a plugin.
Can ONLY be used in a plugin that extends the ConfigActionsPluginBase class.
Hierarchy
- trait \Drupal\config_actions\ConfigActionsValidateTrait
4 files declare their use of ConfigActionsValidateTrait
- ConfigActionsAdd.php in src/
Plugin/ ConfigActions/ ConfigActionsAdd.php - ConfigActionsChange.php in src/
Plugin/ ConfigActions/ ConfigActionsChange.php - ConfigActionsDefault.php in src/
Plugin/ ConfigActions/ ConfigActionsDefault.php - ConfigActionsDelete.php in src/
Plugin/ ConfigActions/ ConfigActionsDelete.php
File
- src/
ConfigActionsValidateTrait.php, line 10
Namespace
Drupal\config_actionsView source
trait ConfigActionsValidateTrait {
/**
* Path to config being altered
* @var array
*/
protected $path;
/**
* Optional path to the $current_value to be used instead of $path.
* @var array
*/
protected $value_path;
/**
* Current data at path to be validated.
* @var mixed
*/
protected $current_value;
/**
* Perform validation of the path.
* Call this from the plugin transform or execute method.
* Throws exception if validation fails.
* @param array $source
*/
protected function validatePath(array $source) {
if (!is_null($this->current_value)) {
$path = !empty($this->value_path) ? $this->value_path : $this->path;
$actual_value = ConfigActionsTransform::read($source, $path);
if ($actual_value !== $this->current_value) {
throw new \Exception('Failed to validate path value for config action.');
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigActionsValidateTrait:: |
protected | property | Current data at path to be validated. | |
ConfigActionsValidateTrait:: |
protected | property | Path to config being altered | |
ConfigActionsValidateTrait:: |
protected | property | Optional path to the $current_value to be used instead of $path. | |
ConfigActionsValidateTrait:: |
protected | function | Perform validation of the path. Call this from the plugin transform or execute method. Throws exception if validation fails. |