Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 15 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UiPatternsHooks | |
0.00% |
0 / 16 |
|
0.00% |
0 / 15 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| sourceValueAlter | |
0.00% |
0 / 8 |
|
0.00% |
0 / 12 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
42 | |||
| schemaInfoAlter | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| sourceInfoAlter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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. |
| 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 (empty($source_configuration['third_party_settings'])) { |
| 34 | // Sometimes, third_party_settings are stored as an empty string instead |
| 35 | // of an empty array. |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 40 | // In Display Builder, third_party_settings providers can be: |
| 41 | // - an island plugin ID (our 'normal' way) |
| 42 | // - a Drupal module name (the Drupal way, found in displays imported and |
| 43 | // converted, not leveraged by us for now but we may do it later). |
| 44 | // So, let's check the plugin ID exists before running logic. |
| 45 | if (!$this->islandManager->hasDefinition($provider)) { |
| 46 | continue; |
| 47 | } |
| 48 | $island = $this->islandManager->createInstance($provider); |
| 49 | |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 51 | $build = $island->alterElement($build, $settings); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Add third-party-settings to UI Patterns slot source schema. |
| 58 | * |
| 59 | * Can be removed once |
| 60 | * https://www.drupal.org/project/ui_patterns/issues/3540614 is merged. |
| 61 | * |
| 62 | * @param array $definitions |
| 63 | * Associative array of configuration type definitions keyed by schema type |
| 64 | * names. The elements are themselves array with information about the type. |
| 65 | */ |
| 66 | #[Hook('config_schema_info_alter')] |
| 67 | public function schemaInfoAlter(array &$definitions): void { |
| 68 | $definitions['ui_patterns_slot_source']['mapping']['third_party_settings'] = [ |
| 69 | 'type' => 'sequence', |
| 70 | 'sequence' => [ |
| 71 | 'type' => 'ui_patterns_slot_source.third_party_setting.[%key]', |
| 72 | ], |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Implements hook_ui_patterns_source_info_alter(). |
| 78 | * |
| 79 | * @param array $definitions |
| 80 | * An array of all the existing plugin definitions, passed by reference. |
| 81 | */ |
| 82 | #[Hook('ui_patterns_source_info_alter')] |
| 83 | public function sourceInfoAlter(array &$definitions): void { |
| 84 | $definitions['component']['class'] = 'Drupal\display_builder\Plugin\UiPatterns\Source\ComponentSource'; |
| 85 | } |
| 86 | |
| 87 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 18 | protected IslandPluginManagerInterface $islandManager, |
| 19 | ) {} |
| 67 | public function schemaInfoAlter(array &$definitions): void { |
| 68 | $definitions['ui_patterns_slot_source']['mapping']['third_party_settings'] = [ |
| 69 | 'type' => 'sequence', |
| 70 | 'sequence' => [ |
| 71 | 'type' => 'ui_patterns_slot_source.third_party_setting.[%key]', |
| 72 | ], |
| 73 | ]; |
| 74 | } |
| 83 | public function sourceInfoAlter(array &$definitions): void { |
| 84 | $definitions['component']['class'] = 'Drupal\display_builder\Plugin\UiPatterns\Source\ComponentSource'; |
| 85 | } |
| 32 | public function sourceValueAlter(mixed &$build, SourceInterface $source, array &$source_configuration): void { |
| 33 | if (empty($source_configuration['third_party_settings'])) { |
| 36 | return; |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 40 | // In Display Builder, third_party_settings providers can be: |
| 41 | // - an island plugin ID (our 'normal' way) |
| 42 | // - a Drupal module name (the Drupal way, found in displays imported and |
| 43 | // converted, not leveraged by us for now but we may do it later). |
| 44 | // So, let's check the plugin ID exists before running logic. |
| 45 | if (!$this->islandManager->hasDefinition($provider)) { |
| 46 | continue; |
| 48 | $island = $this->islandManager->createInstance($provider); |
| 49 | |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 40 | // In Display Builder, third_party_settings providers can be: |
| 41 | // - an island plugin ID (our 'normal' way) |
| 42 | // - a Drupal module name (the Drupal way, found in displays imported and |
| 43 | // converted, not leveraged by us for now but we may do it later). |
| 44 | // So, let's check the plugin ID exists before running logic. |
| 45 | if (!$this->islandManager->hasDefinition($provider)) { |
| 46 | continue; |
| 47 | } |
| 48 | $island = $this->islandManager->createInstance($provider); |
| 49 | |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 51 | $build = $island->alterElement($build, $settings); |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 39 | foreach ($source_configuration['third_party_settings'] as $provider => $settings) { |
| 40 | // In Display Builder, third_party_settings providers can be: |
| 41 | // - an island plugin ID (our 'normal' way) |
| 42 | // - a Drupal module name (the Drupal way, found in displays imported and |
| 43 | // converted, not leveraged by us for now but we may do it later). |
| 44 | // So, let's check the plugin ID exists before running logic. |
| 45 | if (!$this->islandManager->hasDefinition($provider)) { |
| 46 | continue; |
| 47 | } |
| 48 | $island = $this->islandManager->createInstance($provider); |
| 49 | |
| 50 | if ($build && $island instanceof RenderableAltererInterface) { |
| 51 | $build = $island->alterElement($build, $settings); |
| 52 | } |
| 53 | } |
| 54 | } |