Loading core/modules/ckeditor/ckeditor.module +73 −0 Original line number Diff line number Diff line Loading @@ -6,8 +6,11 @@ */ use Drupal\Core\Url; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\editor\Entity\Editor; /** Loading Loading @@ -130,3 +133,73 @@ function ckeditor_library_info_alter(&$libraries, $extension) { $libraries['drupal.ckeditor']['drupalSettings']['ckeditor']['timestamp'] = $query_string; } } /** * Implements hook_form_FORM_ID_alter(). */ function ckeditor_form_filter_format_edit_form_alter(array &$form, FormStateInterface $form_state, $form_id) { // Add an additional validate callback so we can ensure the media_embed filter // is enabled when the DrupalMediaLibrary button is enabled. $form['#validate'][] = 'ckeditor_filter_format_edit_form_validate'; } /** * Implements hook_form_FORM_ID_alter(). */ function ckeditor_form_filter_format_add_form_alter(array &$form, FormStateInterface $form_state, $form_id) { // Add an additional validate callback so we can ensure the media_embed filter // is enabled when the DrupalMediaLibrary button is enabled. $form['#validate'][] = 'ckeditor_filter_format_edit_form_validate'; } /** * Validate callback to ensure the DrupalMediaLibrary button can work correctly. */ function ckeditor_filter_format_edit_form_validate($form, FormStateInterface $form_state) { if ($form_state->getTriggeringElement()['#name'] !== 'op') { return; } // The "DrupalMediaLibrary" button is for the CKEditor text editor. if ($form_state->getValue(['editor', 'editor']) !== 'ckeditor') { return; } $button_group_path = [ 'editor', 'settings', 'toolbar', 'button_groups', ]; if ($button_groups = $form_state->getValue($button_group_path)) { $buttons = []; $button_groups = Json::decode($button_groups); foreach ($button_groups as $button_row) { foreach ($button_row as $button_group) { $buttons = array_merge($buttons, array_values($button_group['items'])); } } $get_filter_label = function ($filter_plugin_id) use ($form) { return (string) $form['filters']['order'][$filter_plugin_id]['filter']['#markup']; }; if (in_array('DrupalMediaLibrary', $buttons, TRUE)) { $media_embed_enabled = $form_state->getValue([ 'filters', 'media_embed', 'status', ]); if (!$media_embed_enabled) { $error_message = new TranslatableMarkup('The %media-embed-filter-label filter must be enabled to use the %drupal-media-library-button button.', [ '%media-embed-filter-label' => $get_filter_label('media_embed'), '%drupal-media-library-button' => new TranslatableMarkup('Insert from Media Library'), ]); $form_state->setErrorByName('filters', $error_message); } } } } core/modules/media_library/js/plugins/drupalmedialibrary/icons/drupalmedialibrary.png→core/modules/ckeditor/js/plugins/drupalmedialibrary/icons/drupalmedialibrary.png (283 B) File moved. View file core/modules/media_library/js/plugins/drupalmedialibrary/icons/hidpi/drupalmedialibrary.png→core/modules/ckeditor/js/plugins/drupalmedialibrary/icons/hidpi/drupalmedialibrary.png (620 B) File moved. View file core/modules/media_library/js/plugins/drupalmedialibrary/plugin.es6.js→core/modules/ckeditor/js/plugins/drupalmedialibrary/plugin.es6.js +0 −0 File moved. View file core/modules/media_library/js/plugins/drupalmedialibrary/plugin.js→core/modules/ckeditor/js/plugins/drupalmedialibrary/plugin.js +0 −0 File moved. View file Loading
core/modules/ckeditor/ckeditor.module +73 −0 Original line number Diff line number Diff line Loading @@ -6,8 +6,11 @@ */ use Drupal\Core\Url; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\editor\Entity\Editor; /** Loading Loading @@ -130,3 +133,73 @@ function ckeditor_library_info_alter(&$libraries, $extension) { $libraries['drupal.ckeditor']['drupalSettings']['ckeditor']['timestamp'] = $query_string; } } /** * Implements hook_form_FORM_ID_alter(). */ function ckeditor_form_filter_format_edit_form_alter(array &$form, FormStateInterface $form_state, $form_id) { // Add an additional validate callback so we can ensure the media_embed filter // is enabled when the DrupalMediaLibrary button is enabled. $form['#validate'][] = 'ckeditor_filter_format_edit_form_validate'; } /** * Implements hook_form_FORM_ID_alter(). */ function ckeditor_form_filter_format_add_form_alter(array &$form, FormStateInterface $form_state, $form_id) { // Add an additional validate callback so we can ensure the media_embed filter // is enabled when the DrupalMediaLibrary button is enabled. $form['#validate'][] = 'ckeditor_filter_format_edit_form_validate'; } /** * Validate callback to ensure the DrupalMediaLibrary button can work correctly. */ function ckeditor_filter_format_edit_form_validate($form, FormStateInterface $form_state) { if ($form_state->getTriggeringElement()['#name'] !== 'op') { return; } // The "DrupalMediaLibrary" button is for the CKEditor text editor. if ($form_state->getValue(['editor', 'editor']) !== 'ckeditor') { return; } $button_group_path = [ 'editor', 'settings', 'toolbar', 'button_groups', ]; if ($button_groups = $form_state->getValue($button_group_path)) { $buttons = []; $button_groups = Json::decode($button_groups); foreach ($button_groups as $button_row) { foreach ($button_row as $button_group) { $buttons = array_merge($buttons, array_values($button_group['items'])); } } $get_filter_label = function ($filter_plugin_id) use ($form) { return (string) $form['filters']['order'][$filter_plugin_id]['filter']['#markup']; }; if (in_array('DrupalMediaLibrary', $buttons, TRUE)) { $media_embed_enabled = $form_state->getValue([ 'filters', 'media_embed', 'status', ]); if (!$media_embed_enabled) { $error_message = new TranslatableMarkup('The %media-embed-filter-label filter must be enabled to use the %drupal-media-library-button button.', [ '%media-embed-filter-label' => $get_filter_label('media_embed'), '%drupal-media-library-button' => new TranslatableMarkup('Insert from Media Library'), ]); $form_state->setErrorByName('filters', $error_message); } } } }
core/modules/media_library/js/plugins/drupalmedialibrary/icons/drupalmedialibrary.png→core/modules/ckeditor/js/plugins/drupalmedialibrary/icons/drupalmedialibrary.png (283 B) File moved. View file
core/modules/media_library/js/plugins/drupalmedialibrary/icons/hidpi/drupalmedialibrary.png→core/modules/ckeditor/js/plugins/drupalmedialibrary/icons/hidpi/drupalmedialibrary.png (620 B) File moved. View file
core/modules/media_library/js/plugins/drupalmedialibrary/plugin.es6.js→core/modules/ckeditor/js/plugins/drupalmedialibrary/plugin.es6.js +0 −0 File moved. View file
core/modules/media_library/js/plugins/drupalmedialibrary/plugin.js→core/modules/ckeditor/js/plugins/drupalmedialibrary/plugin.js +0 −0 File moved. View file