Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | public function displayEntityBrowser(array $element, FormStateInterface $form_state, array &$complete_form, array $persistent_data = []) { |
||
32 | DisplayBase::displayEntityBrowser($element, $form_state, $complete_form, $persistent_data); |
||
33 | $js_event_object = new RegisterJSCallbacks($this->configuration['entity_browser_id'], $this->getUuid()); |
||
34 | $js_event_object->registerCallback('Drupal.entityBrowser.selectionCompleted'); |
||
35 | $js_event = $this->eventDispatcher->dispatch(Events::REGISTER_JS_CALLBACKS, $js_event_object); |
||
36 | $original_path = $this->currentPath->getPath(); |
||
37 | |||
38 | $data = [ |
||
39 | 'query_parameters' => [ |
||
40 | 'query' => [ |
||
41 | 'uuid' => $this->getUuid(), |
||
42 | 'original_path' => $original_path, |
||
43 | ], |
||
44 | ], |
||
45 | 'attributes' => [ |
||
46 | 'data-uuid' => $this->getUuid(), |
||
47 | ], |
||
48 | ]; |
||
49 | $event_object = new AlterEntityBrowserDisplayData($this->configuration['entity_browser_id'], $this->getUuid(), $this->getPluginDefinition(), $form_state, $data); |
||
50 | $event = $this->eventDispatcher->dispatch(Events::ALTER_BROWSER_DISPLAY_DATA, $event_object); |
||
51 | $data = $event->getData(); |
||
52 | return [ |
||
53 | '#theme_wrappers' => ['container'], |
||
54 | 'path' => [ |
||
55 | '#type' => 'hidden', |
||
56 | '#value' => Url::fromRoute('entity_browser.' . $this->configuration['entity_browser_id'], [], $data['query_parameters'])->toString(), |
||
57 | ], |
||
58 | 'open_modal' => [ |
||
59 | '#type' => 'submit', |
||
60 | '#value' => $this->configuration['link_text'], |
||
61 | '#limit_validation_errors' => [], |
||
62 | '#submit' => [], |
||
63 | '#name' => implode('_', $element['#eb_parents']), |
||
64 | '#ajax' => [ |
||
65 | 'callback' => [$this, 'openModal'], |
||
66 | 'event' => 'click', |
||
67 | ], |
||
68 | '#executes_submit_callback' => FALSE, |
||
69 | '#attributes' => $data['attributes'], |
||
70 | '#attached' => [ |
||
71 | 'library' => ['core/drupal.dialog.ajax', 'entity_browser/modal'], |
||
72 | 'drupalSettings' => [ |
||
73 | 'entity_browser' => [ |
||
74 | 'modal' => [ |
||
75 | $this->getUuid() => [ |
||
76 | 'uuid' => $this->getUuid(), |
||
77 | 'js_callbacks' => $js_event->getCallbacks(), |
||
78 | 'original_path' => $original_path, |
||
79 | 'auto_open' => $this->configuration['auto_open'], |
||
80 | ], |
||
81 | ], |
||
82 | ], |
||
83 | ], |
||
84 | ], |
||
85 | ], |
||
86 | ]; |
||
87 | } |
||
88 | |||
178 |