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']; |
|
|
|
|
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
|
|
|
|
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.