drupal-media /
embed
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | use Drupal\Core\Form\FormStateInterface; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Implements hook_form_FORM_ID_alter() on behalf of ckeditor.module. |
||
| 7 | */ |
||
| 8 | function ckeditor_form_embed_button_add_form_alter(array &$form, FormStateInterface $form_state) { |
||
|
0 ignored issues
–
show
|
|||
| 9 | $form['#validate'][] = 'ckeditor_form_embed_button_add_form_validate'; |
||
| 10 | } |
||
| 11 | |||
| 12 | /** |
||
| 13 | * CKEditor-validation callback for new embed buttons. |
||
| 14 | * |
||
| 15 | * Checks to make sure that when adding a new embed button, its ID will not |
||
| 16 | * conflict with any existing CKEditor buttons. |
||
| 17 | */ |
||
| 18 | function ckeditor_form_embed_button_add_form_validate(array &$form, FormStateInterface $form_state) { |
||
|
0 ignored issues
–
show
|
|||
| 19 | /** @var \Drupal\ckeditor\CKEditorPluginManager $ckeditor_plugin_manager */ |
||
| 20 | $ckeditor_plugin_manager = \Drupal::service('plugin.manager.ckeditor.plugin'); |
||
| 21 | |||
| 22 | // Get a list of all buttons that are provided by all plugins. |
||
| 23 | $button_ids = array_reduce($ckeditor_plugin_manager->getButtons(), function($result, $item) { |
||
| 24 | return array_merge($result, array_keys($item)); |
||
| 25 | }, []); |
||
| 26 | |||
| 27 | // Ensure that button ID is unique. |
||
| 28 | // @todo Should this do a case-insensitive comparison? |
||
| 29 | $button_id = $form_state->getValue('id'); |
||
| 30 | if (in_array($button_id, $button_ids)) { |
||
| 31 | $form_state->setErrorByName('id', $this->t('A CKEditor button with ID %id already exists.', ['%id' => $button_id])); |
||
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | } |
||
| 34 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.