Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
DisplayBuilderEvent
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 11
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 appendResult
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInstance
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getData
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNodeId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getIslandConfiguration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEnabledIslands
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getParentId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCurrentIslandId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVisibleIslands
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getResult
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
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\Event;
6
7use Drupal\Component\EventDispatcher\Event;
8use Drupal\display_builder\InstanceInterface;
9
10/**
11 * Event fired when display builder is used.
12 */
13final class DisplayBuilderEvent extends Event {
14
15  /**
16   * The result for this event.
17   *
18   * A render array.
19   */
20  private array $result = [];
21
22  /**
23   * Constructs a DisplayBuilderEvent object.
24   *
25   * @param \Drupal\display_builder\InstanceInterface $instance
26   *   The display builder instance.
27   * @param array|null $data
28   *   The data associated with this event.
29   * @param string|null $node_id
30   *   The tree node ID.
31   * @param string|null $parent_id
32   *   The parent node ID.
33   * @param string|null $current_island_id
34   *   Optional current island ID which trigger action.
35   * @param array|null $visible_islands
36   *   Optional list of island plugin IDs the client reports as currently
37   *   visible on screen. NULL means the client did not report anything, in
38   *   which case every island is rendered - the pre-deferral behavior. An
39   *   empty array is meaningful and distinct from NULL: it means the client
40   *   reported that nothing deferrable is visible.
41   */
42  public function __construct(
43    private InstanceInterface $instance,
44    private ?array $data = NULL,
45    private ?string $node_id = NULL,
46    private ?string $parent_id = NULL,
47    private ?string $current_island_id = NULL,
48    private ?array $visible_islands = NULL,
49  ) {}
50
51  /**
52   * Append a result for this event.
53   *
54   * @param string $islandId
55   *   The island ID.
56   * @param array $result
57   *   The result array to append.
58   */
59  public function appendResult(string $islandId, array $result): void {
60    $this->result[$islandId] = $result;
61  }
62
63  /**
64   * Gets the display builder instance.
65   *
66   * @return \Drupal\display_builder\InstanceInterface
67   *   The display builder instance.
68   */
69  public function getInstance(): InstanceInterface {
70    return $this->instance;
71  }
72
73  /**
74   * Gets the data associated with this event.
75   *
76   * @return array|null
77   *   The event data.
78   */
79  public function getData(): ?array {
80    return $this->data;
81  }
82
83  /**
84   * Gets the tree node ID.
85   *
86   * @return string
87   *   The tree node ID.
88   */
89  public function getNodeId(): ?string {
90    return $this->node_id;
91  }
92
93  /**
94   * Gets the enabled islands.
95   *
96   * @return array
97   *   The enabled islands.
98   */
99  public function getIslandConfiguration(): array {
100    return $this->instance->getProfile()->getIslandConfigurations();
101  }
102
103  /**
104   * Gets the enabled islands.
105   *
106   * @return array
107   *   The enabled islands.
108   */
109  public function getEnabledIslands(): array {
110    return $this->instance->getProfile()->getEnabledIslands();
111  }
112
113  /**
114   * Gets the parent node ID.
115   *
116   * @return string
117   *   The parent node ID.
118   */
119  public function getParentId(): ?string {
120    return $this->parent_id;
121  }
122
123  /**
124   * Gets the current island ID.
125   *
126   * @return string
127   *   The current island ID which trigger action.
128   */
129  public function getCurrentIslandId(): ?string {
130    return $this->current_island_id;
131  }
132
133  /**
134   * Gets the islands the client reports as currently visible.
135   *
136   * @return array|null
137   *   The visible island plugin IDs, or NULL if the client did not report.
138   */
139  public function getVisibleIslands(): ?array {
140    return $this->visible_islands;
141  }
142
143  /**
144   * Gets the result for this event.
145   *
146   * @return array
147   *   The result array, or empty array if not set.
148   */
149  public function getResult(): array {
150    return $this->result;
151  }
152
153}