public function AttributesSettingType::preprocess in UI Patterns Settings 8
Same name and namespace in other branches
- 8.2 src/Plugin/UiPatterns/SettingType/AttributesSettingType.php \Drupal\ui_patterns_settings\Plugin\UIPatterns\SettingType\AttributesSettingType::preprocess()
Returns the processed setting variable.
Parameters
string $value: The stored value.
array $context: Context informations.
Return value
mixed The processed value.
Overrides PatternSettingTypeBase::preprocess
File
- src/
Plugin/ UiPatterns/ SettingType/ AttributesSettingType.php, line 39
Class
- AttributesSettingType
- Attributes setting type.
Namespace
Drupal\ui_patterns_settings\Plugin\UIPatterns\SettingTypeCode
public function preprocess($value, array $context) {
$value = parent::preprocess($value, $context);
$parse_html = '<div ' . $value . '></div>';
$attributes = [];
foreach (Html::load($parse_html)
->getElementsByTagName('div') as $div) {
foreach ($div->attributes as $attr) {
$attributes[$attr->nodeName] = $attr->nodeValue;
}
}
return new Attribute($attributes);
}