ModalDeliveryProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
ccs 0
cts 13
cp 0
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sendData() 0 2 1
A navigate() 0 7 1
A close() 0 2 1
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