Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
53.85% |
7 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
UiPatternsHooks | |
53.85% |
7 / 13 |
|
66.67% |
2 / 3 |
11.82 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
sourceValueAlter | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
schemaInfoAlter | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\display_builder\Hook; |
6 | |
7 | use Drupal\Core\Hook\Attribute\Hook; |
8 | use Drupal\display_builder\IslandPluginManagerInterface; |
9 | use Drupal\display_builder\RenderableAltererInterface; |
10 | use Drupal\ui_patterns\SourceInterface; |
11 | |
12 | /** |
13 | * Hook implementations for display_builder_entity_view. |
14 | */ |
15 | class UiPatternsHooks { |
16 | |
17 | public function __construct( |
18 | protected IslandPluginManagerInterface $islandManager, |
19 | ) {} |
20 | |
21 | /** |
22 | * Alters the renderable array for a component that has been built. |
23 | * |
24 | * @param mixed &$build |
25 | * The renderable array of the component. |
26 | * @param \Drupal\ui_patterns\SourceInterface $source |
27 | * The data array containing information about the component. |
28 | * @param array $source_configuration |
29 | * The full raw configuration used to build the source. |
30 | */ |
31 | #[Hook('ui_patterns_source_value_alter')] |
32 | public function sourceValueAlter(mixed &$build, SourceInterface $source, array &$source_configuration): void { |
33 | if (!isset($source_configuration['_third_party_settings'])) { |
34 | return; |
35 | } |
36 | |
37 | foreach ($source_configuration['_third_party_settings'] as $island_id => $settings) { |
38 | $island = $this->islandManager->createInstance($island_id); |
39 | |
40 | if ($build && $island instanceof RenderableAltererInterface) { |
41 | $build = $island->alterElement($build, $settings); |
42 | } |
43 | } |
44 | } |
45 | |
46 | /** |
47 | * Add third-party-settings to UI Patterns slot source schema. |
48 | * |
49 | * Can be removed once |
50 | * https://www.drupal.org/project/ui_patterns/issues/3540614 is merged. |
51 | * |
52 | * @param array $definitions |
53 | * Associative array of configuration type definitions keyed by schema type |
54 | * names. The elements are themselves array with information about the type. |
55 | */ |
56 | #[Hook('config_schema_info_alter')] |
57 | public function schemaInfoAlter(array &$definitions): void { |
58 | $definitions['ui_patterns_slot_source']['mapping']['_third_party_settings'] = [ |
59 | 'type' => 'sequence', |
60 | 'sequence' => [ |
61 | 'type' => 'ui_patterns_slot_source.third_party_setting.[%key]', |
62 | ], |
63 | ]; |
64 | } |
65 | |
66 | } |