Skip to content
Snippets Groups Projects
Commit c3479f06 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

Issue #3512018 by just_like_good_vibes: Make Component element builder alterable (suite)

parent 6ee5db3b
No related branches found
No related tags found
1 merge request!348Resolve #3512018 "2.0.1 make componenent"
Pipeline #444808 passed
......@@ -91,7 +91,7 @@ class ComponentElementBuilder implements TrustedCallbackInterface {
$build = $source->alterComponent($build);
$prop_type = $definition['ui_patterns']['type_definition'];
$data = $source->getValue($prop_type);
$this->moduleHandler->alter('ui_patterns_source_value', $data, $source);
$this->moduleHandler->alter('ui_patterns_source_value', $data, $source, $configuration);
if (empty($data) && $prop_type->getPluginId() !== 'attributes') {
// For JSON Schema validator, empty value is not the same as missing
// value, and we want to prevent some of the prop types rules to be
......@@ -186,7 +186,7 @@ class ComponentElementBuilder implements TrustedCallbackInterface {
}
$build = $source->alterComponent($build);
$source_value = $source->getValue($slot_prop_type) ?? [];
$this->moduleHandler->alter('ui_patterns_source_value', $source_value, $source);
$this->moduleHandler->alter('ui_patterns_source_value', $source_value, $source, $source_configuration);
if (Element::isRenderArray($source_value)) {
$build["#slots"][$slot_id][] = $this->isSingletonRenderArray($source_value) ? array_values($source_value)[0] : $source_value;
}
......
......@@ -24,8 +24,16 @@ function hook_component_info_alter(array &$definitions) {
* Value produced by the source.
* @param \Drupal\ui_patterns\SourceInterface $source
* The source object which has produced the value.
* @param array $source_configuration
* The full raw configuration used to build the source.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
function hook_ui_patterns_source_value_alter(mixed &$value, \Drupal\ui_patterns\SourceInterface $source) : void {
function hook_ui_patterns_source_value_alter(mixed &$value, \Drupal\ui_patterns\SourceInterface $source, array &$source_configuration) : void {
$type_definition = $source->getPropDefinition()['ui_patterns']['type_definition'];
if ($type_definition instanceof \Drupal\ui_patterns\Plugin\UiPatterns\PropType\SlotPropType) {
if (is_array($value)) {
$value['#cache']['tags'][] = 'custom_cache_tag';
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment