public static function BackgroundImageFormTrait::mapStatesConditions in Background Image 8
Same name and namespace in other branches
- 2.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::mapStatesConditions()
- 2.0.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::mapStatesConditions()
Recursively maps a selector for a set of #states conditions.
Parameters
string $selector: The real DOM selector that should be used in the #states conditions.
array $conditions: A standard States API conditions array. In place of a condition selector, you can use "%selector" anywhere and it will be replaced with the real $selector value above. An example of what this real selector value would be is if an element's #parents value contained an array with the values ['parent', 'child', 'input_element'], then the corresponding selector would be "edit-parent-child-input-selector". In most cases, you can pass "*" as the whole selector which will turn into the following selector: "[data-drupal-selector="%selector"]".
Return value
array The newly mapped #states conditions.
See also
\Drupal\background_image\BackgroundImageFormTrait::addState
\Drupal\background_image\BackgroundImageFormTrait::preRenderStates
1 call to BackgroundImageFormTrait::mapStatesConditions()
- BackgroundImageFormTrait::preRenderStates in src/
BackgroundImageFormTrait.php - The #pre_render callback for ::addState.
File
- src/
BackgroundImageFormTrait.php, line 513
Class
- BackgroundImageFormTrait
- Trait BackgroundImageFormTrait.
Namespace
Drupal\background_imageCode
public static function mapStatesConditions($selector, array $conditions = []) {
$mapped = [];
foreach ($conditions as $key => $value) {
if (is_numeric($key) && is_array($value)) {
$mapped[] = self::mapStatesConditions($selector, $value);
}
else {
if ($key === '*') {
$key = '[data-drupal-selector="%selector"]';
}
$real_selector = preg_replace_callback('/%selector/', function () use ($selector) {
return $selector;
}, $key);
$mapped[$real_selector] = $value;
}
}
return $mapped;
}