ModalDeliveryProvider::sendData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\paragraphs_editor\Plugin\ParagraphsEditor\delivery_provider;
4
5
use Drupal\Core\Ajax\AjaxResponse;
6
use Drupal\paragraphs_editor\Ajax\CloseModalCommand;
7
use Drupal\paragraphs_editor\Ajax\DeliverWidgetBinderData;
8
use Drupal\paragraphs_editor\Ajax\OpenModalCommand;
9
use Drupal\paragraphs_editor\WidgetBinder\WidgetBinderData;
10
use Drupal\paragraphs_editor\Plugin\ParagraphsEditor\DeliveryProviderInterface;
11
use Drupal\paragraphs_editor\Plugin\ParagraphsEditor\PluginBase;
12
13
/**
14
 * Delivers paragraphs editor forms in a modal dialog.
15
 *
16
 * @ParagraphsEditorDeliveryProvider(
17
 *   id = "modal",
18
 *   title = @Translation("Modal"),
19
 *   description = @Translation("Shows forms in a modal dialog.")
20
 * )
21
 */
22
class ModalDeliveryProvider extends PluginBase implements DeliveryProviderInterface {
23
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function navigate(AjaxResponse $response, $title, $contents) {
28
    $response->setAttachments([
29
      'library' => [
30
        'core/drupal.dialog.ajax',
31
      ],
32
    ]);
33
    $response->addCommand(new OpenModalCommand($title, $contents, $this->context));
34
  }
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public function close(AjaxResponse $response) {
40
    $response->addCommand(new CloseModalCommand($this->context));
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46
  public function sendData(AjaxResponse $response, WidgetBinderData $data) {
47
    $response->addCommand(new DeliverWidgetBinderData($this->context->getAdditionalContext('module'), $data));
48
  }
49
50
}
51