Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ViewRowsSource | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
setVariableId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPropValue | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\display_builder_views\Plugin\UiPatterns\Source; |
6 | |
7 | use Drupal\Core\Plugin\Context\EntityContextDefinition; |
8 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
9 | use Drupal\display_builder_views\Plugin\ViewsUiPatternsSourceBase; |
10 | use Drupal\ui_patterns\Attribute\Source; |
11 | |
12 | /** |
13 | * Plugin implementation of the source for views. |
14 | * |
15 | * @see \Drupal\ui_patterns_views\Plugin\UiPatterns\Source\ViewRowsSource |
16 | * @see display_builder_views.module |
17 | */ |
18 | #[Source( |
19 | id: 'view_rows_tmp', |
20 | label: new TranslatableMarkup('[View] Rows (Display Builder)'), |
21 | context_requirements: ['views:style'], |
22 | prop_types: ['slot'], |
23 | tags: ['views'], |
24 | context_definitions: [ |
25 | 'ui_patterns_views:view_entity' => new EntityContextDefinition('entity:view', label: new TranslatableMarkup('View')), |
26 | ] |
27 | )] |
28 | class ViewRowsSource extends ViewsUiPatternsSourceBase { |
29 | |
30 | /** |
31 | * {@inheritdoc} |
32 | */ |
33 | public static function setVariableId(): string { |
34 | return 'rows'; |
35 | } |
36 | |
37 | /** |
38 | * {@inheritdoc} |
39 | */ |
40 | public function getPropValue(): mixed { |
41 | // Values are injected as context from |
42 | // modules/display_builder_views/src/Hook/PreprocessViewsView.php. |
43 | $view = $this->getView(); |
44 | |
45 | if (!$view) { |
46 | return []; |
47 | } |
48 | |
49 | $rows = $this->getContextValue('ui_patterns_views:rows'); |
50 | |
51 | // Specific case for empty view, still showing everything in the empty |
52 | // display. |
53 | if (!\is_array($rows) || \count($rows) < 1) { |
54 | if (!$view->empty || empty($view->empty)) { |
55 | return []; |
56 | } |
57 | $output = []; |
58 | |
59 | foreach ($view->empty as $key => $value) { |
60 | $output[$key] = $value->render(); |
61 | } |
62 | |
63 | return $output; |
64 | } |
65 | |
66 | // Return the view rows. |
67 | return $this->renderOutput($rows); |
68 | } |
69 | |
70 | } |