From 7b1456bf42adcdf34ce440e6fae60e73f92bfbd3 Mon Sep 17 00:00:00 2001 From: phenaproxima Date: Thu, 29 Jun 2017 10:04:21 -0400 Subject: [PATCH] Issue #2784699 by phenaproxima: Provide option for resizing inline images --- UPDATE.md | 26 +++++ lightning.install | 6 +- .../lightning_dev/lightning_dev.install | 19 +++ .../lightning_test/lightning_test.install | 20 ---- .../lightning_core/src/ConfigHelper.php | 2 +- .../install/embed.button.media_browser.yml | 1 + .../install/filter.format.rich_text.yml | 4 +- .../install/lightning_media.settings.yml | 2 + .../config/schema/lightning_media.schema.yml | 12 ++ .../lightning_media/lightning_media.install | 16 ++- .../lightning_media.links.task.yml | 4 + .../lightning_media.routing.yml | 7 ++ .../lightning_media.services.yml | 6 + .../lightning_media_image.module | 5 + .../src/Form/EntityEmbedDialog.php | 43 +++++++ .../lightning_media/src/Form/SettingsForm.php | 50 ++++++++ .../EntityEmbedDisplay/MediaImage.php | 108 ++++++++++++++++++ .../src/Routing/RouteSubscriber.php | 20 ++++ modules/upload_bundles_test | 1 + .../Context/TestModuleContext.behat.inc | 72 ++++++++++++ .../Context/UtilityContext.behat.inc | 100 ++++++++-------- tests/config/embed.button.media_browser.yml | 2 + tests/config/filter.format.rich_text.yml | 2 +- tests/config/lightning_media.settings.yml | 2 + tests/features/bootstrap/lightning.behat.inc | 24 +--- tests/features/media/browser.feature | 6 +- .../features/media/browser_embed_code.feature | 2 +- tests/features/media/browser_upload.feature | 6 +- tests/features/media/embed_code.feature | 2 +- tests/features/media/entity_embed.feature | 92 +++++++++++++++ tests/features/media/image_browser.feature | 4 +- .../field.field.media.z_image.image.yml | 0 .../field.field.node.page.field_z_image.yml | 0 .../field.storage.node.field_z_image.yml | 0 .../install/media_entity.bundle.z_image.yml | 0 .../upload_bundles_test.info.yml | 8 ++ .../upload_bundles_test.install | 42 +++++++ tests/src/Functional/ConfigIntegrityTest.php | 41 +++++++ 38 files changed, 647 insertions(+), 110 deletions(-) create mode 100644 modules/lightning_features/lightning_media/config/install/lightning_media.settings.yml create mode 100644 modules/lightning_features/lightning_media/lightning_media.links.task.yml create mode 100644 modules/lightning_features/lightning_media/lightning_media.routing.yml create mode 100644 modules/lightning_features/lightning_media/src/Form/EntityEmbedDialog.php create mode 100644 modules/lightning_features/lightning_media/src/Form/SettingsForm.php create mode 100644 modules/lightning_features/lightning_media/src/Plugin/entity_embed/EntityEmbedDisplay/MediaImage.php create mode 100644 modules/lightning_features/lightning_media/src/Routing/RouteSubscriber.php create mode 120000 modules/upload_bundles_test create mode 100644 src/LightningExtension/Context/TestModuleContext.behat.inc create mode 100644 tests/config/lightning_media.settings.yml create mode 100644 tests/features/media/entity_embed.feature rename {modules/lightning_features/lightning_core/modules/lightning_test => tests/modules/upload_bundles_test}/config/install/field.field.media.z_image.image.yml (100%) rename {modules/lightning_features/lightning_core/modules/lightning_test => tests/modules/upload_bundles_test}/config/install/field.field.node.page.field_z_image.yml (100%) rename {modules/lightning_features/lightning_core/modules/lightning_test => tests/modules/upload_bundles_test}/config/install/field.storage.node.field_z_image.yml (100%) rename {modules/lightning_features/lightning_core/modules/lightning_test => tests/modules/upload_bundles_test}/config/install/media_entity.bundle.z_image.yml (100%) create mode 100644 tests/modules/upload_bundles_test/upload_bundles_test.info.yml create mode 100644 tests/modules/upload_bundles_test/upload_bundles_test.install diff --git a/UPDATE.md b/UPDATE.md index 92e1ffe1e..8fbe590e4 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -54,6 +54,32 @@ use. For example, if you are currently running Beta 1 and are trying to update to Beta 3, you will need to follow the instructions for updating from Beta 1 to Beta 2, then from Beta 2 to Beta 3, in that order. +## 2.1.5 to 2.1.6 +This version of Lightning adds the ability to choose an image style, alt text, +and other settings each time you embed an image in a WYSIWYG editor, rather +that needing to rely on view modes. To enable this functionality: + +1. As always, visit ```update.php``` or run ```drush updatedb``` to perform + database updates. +1. Clear all caches. +1. Under *Configuration > Content Authoring > Text formats and editors*, + configure the **Rich Text** filter format. Under "Filter settings", open the + tab labeled "Limit allowed HTML tags and correct faulty HTML". +1. In the "Allowed HTML tags" text field, you should see a tag like + ``. Change it to ``. +1. Save the filter format. +1. Under *Configuration > Content Authoring > Text editor embed buttons*, edit + the "Media browser" embed button. +1. Under "Allowed Entity Embed Display plugins", ensure that the "Media Image" + checkbox is checked. +1. Save the embed button. +1. If you would like to allow authors to choose how embedded media should be + displayed, go to *Configuration > System > Lightning > Media*, ensure that + the box labeled "Allow users to choose how to display embedded media" is + checked, then submit the form. If the box is not checked, Lightning will + automatically choose a preferred display method (the recommended, default + behavior). + ## 2.1.4 to 2.1.5 There are no manual update steps for this version. diff --git a/lightning.install b/lightning.install index 2e0df1a76..4906e59a8 100644 --- a/lightning.install +++ b/lightning.install @@ -7,6 +7,7 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\field\Entity\FieldConfig; +use Drupal\lightning_core\ConfigHelper as Config; use Drupal\user\Entity\User; use Drupal\user\RoleInterface; @@ -457,7 +458,8 @@ function lightning_update_8001() { // Install the body field on the basic block_content type. $field = FieldConfig::load('block_content.basic.body'); if (empty($field)) { - lightning_core_create_config('field_config', 'block_content.basic.body', 'lightning'); + $config = Config::forModule('lightning'); + $config->getEntity('field_config', 'block_content.basic.body')->save(); $display = EntityViewDisplay::load('block_content.basic.default'); if ($display) { @@ -471,7 +473,7 @@ function lightning_update_8001() { ])->save(); } else { - lightning_core_create_config('entity_view_display', 'block_content.basic.default', 'lightning'); + $config->getEntity('entity_view_display', 'block_content.basic.default')->save(); } } diff --git a/modules/lightning_features/lightning_core/modules/lightning_dev/lightning_dev.install b/modules/lightning_features/lightning_core/modules/lightning_dev/lightning_dev.install index e1a50129e..5975fbb0c 100644 --- a/modules/lightning_features/lightning_core/modules/lightning_dev/lightning_dev.install +++ b/modules/lightning_features/lightning_core/modules/lightning_dev/lightning_dev.install @@ -5,9 +5,11 @@ * Contains installation and update routines for Lightning Dev. */ +use Drupal\embed\Entity\EmbedButton; use Drupal\entity_browser\Entity\EntityBrowser; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\filter\Entity\FilterFormat; use Drupal\lightning_core\ConfigHelper as Config; use Drupal\media_entity\Entity\MediaBundle; use Drupal\scheduled_updates\Entity\ScheduledUpdateType; @@ -192,3 +194,20 @@ function lightning_dev_update_8005() { $display['display_options']['filters']['bundle']['expose']['argument'] = 'bundle'; $view->save(); } + +/** + * Executes manual updates for Lightning 2.1.5 --> 2.1.6. + */ +function lightning_dev_update_8006() { + \Drupal::service('plugin.manager.embed.type')->clearCachedDefinitions(); + + $button = EmbedButton::load('media_browser'); + $settings = $button->getTypeSettings(); + $settings['display_plugins'][] = 'media_image'; + $button->set('type_settings', $settings)->save(); + + $format = FilterFormat::load('rich_text'); + $configuration = $format->filters('filter_html')->getConfiguration(); + $configuration['settings']['allowed_html'] = str_replace('', '', $configuration['settings']['allowed_html']); + $format->setFilterConfig('filter_html', $configuration)->save(); +} diff --git a/modules/lightning_features/lightning_core/modules/lightning_test/lightning_test.install b/modules/lightning_features/lightning_core/modules/lightning_test/lightning_test.install index 5b29b7c9f..607e4511d 100644 --- a/modules/lightning_features/lightning_core/modules/lightning_test/lightning_test.install +++ b/modules/lightning_features/lightning_core/modules/lightning_test/lightning_test.install @@ -81,21 +81,6 @@ function lightning_test_install() { ], 'region' => 'content', ]) - ->setComponent('field_z_image', [ - 'type' => 'entity_browser_entity_reference', - 'settings' => [ - 'entity_browser' => 'media_browser', - 'field_widget_display' => 'rendered_entity', - 'field_widget_edit' => TRUE, - 'field_widget_remove' => TRUE, - 'selection_mode' => EntityBrowserElement::SELECTION_MODE_APPEND, - 'field_widget_display_settings' => [ - 'view_mode' => 'embedded', - ], - 'open' => TRUE, - ], - 'region' => 'content', - ]) ->save(); $display = entity_get_form_display('media', 'video', 'default'); @@ -144,9 +129,4 @@ function lightning_test_uninstall() { } } $state->delete('_fields'); - - \Drupal::entityTypeManager() - ->getStorage('media_bundle') - ->load('z_image') - ->delete(); } diff --git a/modules/lightning_features/lightning_core/src/ConfigHelper.php b/modules/lightning_features/lightning_core/src/ConfigHelper.php index b1edd0819..84dd6d444 100644 --- a/modules/lightning_features/lightning_core/src/ConfigHelper.php +++ b/modules/lightning_features/lightning_core/src/ConfigHelper.php @@ -128,7 +128,7 @@ public function delete($id) { if (Unicode::strpos($id, $prefix) === 0) { $entity = $this->getEntity( $entity_type, - Unicode::substr($id, Unicode::strlen($prefix) + 1) + Unicode::substr($id, Unicode::strlen($prefix)) ); return $entity->delete(); } diff --git a/modules/lightning_features/lightning_media/config/install/embed.button.media_browser.yml b/modules/lightning_features/lightning_media/config/install/embed.button.media_browser.yml index d28da8f3b..c389e0b70 100644 --- a/modules/lightning_features/lightning_media/config/install/embed.button.media_browser.yml +++ b/modules/lightning_features/lightning_media/config/install/embed.button.media_browser.yml @@ -12,6 +12,7 @@ type_settings: bundles: { } display_plugins: - 'entity_reference:entity_reference_entity_view' + - media_image entity_browser: media_browser entity_browser_settings: display_review: false diff --git a/modules/lightning_features/lightning_media/config/install/filter.format.rich_text.yml b/modules/lightning_features/lightning_media/config/install/filter.format.rich_text.yml index 4155bb9a2..98581f9f5 100644 --- a/modules/lightning_features/lightning_media/config/install/filter.format.rich_text.yml +++ b/modules/lightning_features/lightning_media/config/install/filter.format.rich_text.yml @@ -4,8 +4,6 @@ dependencies: module: - editor - entity_embed -_core: - default_config_hash: ba3RWDN1-BRYH1z2GlIchbXVWirdh7mDbsjSmbCmbIw name: 'Rich Text' format: rich_text weight: 1 @@ -46,7 +44,7 @@ filters: status: true weight: -50 settings: - allowed_html: '