Completed
Pull Request — 8.x-1.x (#138)
by
unknown
60:33 queued 58:59
created

NewDisplay   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultConfiguration() 0 6 1
B getForm() 0 29 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
38
    $form = [];
39
40
    $storage = &$form_state->getStorage();
41
42
    //$selected_entities = $storage['entity_browser']['selected_entities'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
    $selected_entities = ['en1', 'en2', 'en3', 'en4'];
44
45
    $form['selected'] = [
46
      '#type' => 'container',
47
      '#attributes' => ['id' => 'selected'],
48
    ];
49
    foreach ($selected_entities as $key => $value) {
50
      $form['selected']['element'][$key] = [
51
        '#type' => 'label',
52
        '$value' => t('Entity'),
53
        '#title' => $value
54
      ];
55
    }
56
57
    $form['use_selected'] = array(
58
      '#type' => 'submit',
59
      '#value' => t('Use selection'),
60
      '#name' => 'use_selected',
61
    );
62
63
    return $form;
64
  }
65
66
  /**
67
   * {@inheritdoc}
68
   */
69
  public function submit(array &$form, FormStateInterface $form_state) {
70
    if ($form_state->getTriggeringElement()['#name'] == 'use_selected') {
71
      $this->selectionDone($form_state);
72
    }
73
  }
74
75
}
76