Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
MainPageContentSource
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 getPropValue
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder_page_layout\Plugin\UiPatterns\Source;
6
7use Drupal\Core\StringTranslation\TranslatableMarkup;
8use Drupal\ui_patterns\Attribute\Source;
9use Drupal\ui_patterns\PropTypeInterface;
10use Drupal\ui_patterns\SourcePluginBase;
11
12/**
13 * Plugin implementation of the source.
14 *
15 * Slot is explicitly added to prop_types to allow getPropValue
16 * to return a renderable array in case of slot prop type.
17 */
18#[Source(
19  id: 'main_page_content',
20  label: new TranslatableMarkup('[Page] Main content'),
21  description: new TranslatableMarkup('The Drupal `Main page content` block (system_main_block).'),
22  prop_types: ['slot'],
23  tags: [],
24  context_requirements: ['page'],
25  context_definitions: []
26)]
27class MainPageContentSource extends SourcePluginBase {
28
29  /**
30   * {@inheritdoc}
31   */
32  public function getPropValue(): mixed {
33    $isSlot = ($this->propDefinition['ui_patterns']['type_definition']->getPluginId() === 'slot');
34
35    return $isSlot ? [] : '';
36  }
37
38  /**
39   * Get the value from settings.
40   *
41   * @param \Drupal\ui_patterns\PropTypeInterface|null $prop_type
42   *   The prop type.
43   */
44  public function getValue(?PropTypeInterface $prop_type = NULL): mixed {
45    return $this->configuration['settings'];
46  }
47
48}