Conditions | 5 |
Paths | 16 |
Total Lines | 80 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 1 | Features | 2 |
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 |
||
70 | public function form(array $form, FormStateInterface $form_state) { |
||
71 | $form = parent::form($form, $form_state); |
||
72 | |||
73 | /** @var \Drupal\embed\EmbedButtonInterface $button */ |
||
74 | $button = $this->entity; |
||
75 | $form_state->setTemporaryValue('embed_button', $button); |
||
76 | |||
77 | $form['label'] = [ |
||
78 | '#title' => $this->t('Label'), |
||
79 | '#type' => 'textfield', |
||
80 | '#default_value' => $button->label(), |
||
81 | '#description' => t('The human-readable name of this embed button. This text will be displayed when the user hovers over the CKEditor button. This name must be unique.'), |
||
82 | '#required' => TRUE, |
||
83 | '#size' => 30, |
||
84 | ]; |
||
85 | |||
86 | $form['id'] = [ |
||
87 | '#type' => 'machine_name', |
||
88 | '#default_value' => $button->id(), |
||
89 | '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, |
||
90 | '#disabled' => !$button->isNew(), |
||
91 | '#machine_name' => [ |
||
92 | 'exists' => ['Drupal\embed\Entity\EmbedButton', 'load'], |
||
93 | ], |
||
94 | '#description' => $this->t('A unique machine-readable name for this embed button. It must only contain lowercase letters, numbers, and underscores.'), |
||
95 | ]; |
||
96 | |||
97 | $form['type_id'] = [ |
||
98 | '#type' => 'select', |
||
99 | '#title' => $this->t('Embed type'), |
||
100 | '#options' => $this->embedTypeManager->getDefinitionOptions(), |
||
101 | '#default_value' => $button->getTypeId(), |
||
102 | '#required' => TRUE, |
||
103 | '#ajax' => [ |
||
104 | 'callback' => '::updateTypeSettings', |
||
105 | 'effect' => 'fade', |
||
106 | ], |
||
107 | '#disabled' => !$button->isNew(), |
||
108 | ]; |
||
109 | if (count($form['type_id']['#options']) == 0) { |
||
110 | drupal_set_message($this->t('No embed types found.'), 'warning'); |
||
111 | } |
||
112 | |||
113 | // Add the embed type plugin settings. |
||
114 | $form['type_settings'] = [ |
||
115 | '#type' => 'container', |
||
116 | '#tree' => TRUE, |
||
117 | '#prefix' => '<div id="embed-type-settings-wrapper">', |
||
118 | '#suffix' => '</div>', |
||
119 | ]; |
||
120 | |||
121 | try { |
||
122 | if ($plugin = $button->getTypePlugin()) { |
||
123 | $form['type_settings'] = $plugin->buildConfigurationForm($form['type_settings'], $form_state); |
||
124 | } |
||
125 | } |
||
126 | catch (PluginNotFoundException $exception) { |
||
|
|||
127 | drupal_set_message($exception->getMessage(), 'error'); |
||
128 | watchdog_exception('embed', $exception); |
||
129 | $form['type_id']['#disabled'] = FALSE; |
||
130 | } |
||
131 | |||
132 | $config = $this->config('embed.settings'); |
||
133 | $upload_location = $config->get('file_scheme') . '://' . $config->get('upload_directory') . '/'; |
||
134 | $form['icon_file'] = [ |
||
135 | '#title' => $this->t('Button icon'), |
||
136 | '#type' => 'managed_file', |
||
137 | '#description' => $this->t('Icon for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon.'), |
||
138 | '#upload_location' => $upload_location, |
||
139 | '#upload_validators' => [ |
||
140 | 'file_validate_extensions' => ['gif png jpg jpeg'], |
||
141 | 'file_validate_image_resolution' => ['32x32', '16x16'], |
||
142 | ], |
||
143 | ]; |
||
144 | if ($file = $button->getIconFile()) { |
||
145 | $form['icon_file']['#default_value'] = ['target_id' => $file->id()]; |
||
146 | } |
||
147 | |||
148 | return $form; |
||
149 | } |
||
150 | |||
238 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.