Passed
Push — 8.x ( fadd51...4cf850 )
by Christopher
21:11 queued 01:56
created

DeliverWidgetBinderData   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
namespace Drupal\paragraphs_editor\Ajax;
4
5
use Drupal\Core\Ajax\CommandInterface;
6
use Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData;
7
8
/**
9
 * Ajax command for delivering widget binder model collections to the client.
10
 */
11
class DeliverWidgetBinderData implements CommandInterface {
12
13
  /**
14
   * The module name that will trigger the appropriate widget binder instance.
15
   *
16
   * @var string
17
   */
18
  protected $moduleName;
19
20
  /**
21
   * The widget binder data models to be delivered.
22
   *
23
   * @var \Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData
24
   */
25
  protected $data;
26
27
  /**
28
   * Creates a DeliverWidgetBinderData command.
29
   *
30
   * @param string $module_name
31
   *   The module name implementing the editor integration.
32
   * @param \Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData $data
33
   *   The data collection to deliver.
34
   */
35
  public function __construct($module_name, WidgetBinderData $data) {
36
    $this->moduleName = $module_name;
37
    $this->data = $data;
38
  }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public function render() {
44
    $command = [
45
      'command' => 'paragraphs_editor_data',
46
      'module' => $this->moduleName,
47
    ] + $this->data->toArray();
48
    return $command;
49
  }
50
51
}
52