Completed
Pull Request — 8.x-1.x (#138)
by
unknown
11:04 queued 14s
created

NewDisplay   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultConfiguration() 0 6 1
A getForm() 0 20 2
A submit() 0 5 2
1
<?php
2
3
/**
4
 * Contains \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\NewDisplay.
5
 */
6
7
namespace Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay;
8
9
use Drupal\Core\Form\FormStateInterface;
10
use Drupal\entity_browser\SelectionDisplayBase;
11
12
/*
13
 * Show current selection and delivers selected entities.
14
 *
15
 * @EntityBrowserSelectionDisplay(
16
 *   id = "new_display",
17
 *   label = @Translation("New selection display"),
18
 *   description = @Translation("Show current selection display and delivers selected entities.")
19
 * )
20
 */
21
class NewDisplay extends SelectionDisplayBase {
22
23
  /**
24
   * {@inheritdoc}
25
   */
26
  public function defaultConfiguration() {
27
    return array(
28
      'view' => NULL,
29
      'view_display' => NULL,
30
    ) + parent::defaultConfiguration();
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function getForm(array &$original_form, FormStateInterface $form_state) {
37
    $form = [];
38
39
    $selected_entities = &$form_state->getStorage()['entity_browser']['selected_entities'];
40
41
    foreach ($selected_entities as $entity) {
42
      $form['label'] = [
43
        '#type' => 'label',
44
        '$value' => t('Entity')
45
      ];
46
    }
47
48
    $form['use_selected'] = array(
49
      '#type' => 'submit',
50
      '#value' => t('Use selection'),
51
      '#name' => 'use_selected',
52
    );
53
54
    return $form;
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function submit(array &$form, FormStateInterface $form_state) {
61
    if ($form_state->getTriggeringElement()['#name'] == 'use_selected') {
62
      $this->selectionDone($form_state);
63
    }
64
  }
65
66
}
67