[drupalImage] Optionally apply image style to images uploaded in CKEditor 5

Created on 9 August 2013, almost 11 years ago
Updated 25 June 2024, about 23 hours ago

Updated: Comment #212

Problem/Motivation

Inserting an image in the text editor dialog today allows the user to fiddle with image dimensions. It doesn't even have aspect ratio locking.

It's not great for the authoring experience nor for structured content reasons that users are defining the specific dimensions of every single image they insert. It'd be much better to allow them to choose from image styles — just like we do for image fields.

Proposed resolution

Allow an image style to be selected in the image dialog, which gets stored in a data-image-style attribute, and is handled by a yet-to-be-added imagestyle filter.

Remaining tasks

  1. Initial patch: select image style in dialog, inserting that sets a data- attribute, and a filter transforms the end result.

User interface changes

  • The new ability to select an image style.
  • A new filter.

API changes

None.

Related Issues

Feature request
Status

Needs work

Version

11.0 🔥

Component
CKEditor 5 

Last updated about 7 hours ago

Created by

🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Needs usability review

    Used to alert the usability topic maintainer(s) that an issue significantly affects (or has the potential to affect) the usability of Drupal, and their signoff is needed. When adding this tag, make it easy to review the issue. Make sure the issue summary describes the problem and the proposed solution. Screenshots usually help a lot! To get sign-off on issues with the "Needs usability review" tag, post about them in the #ux channel on Drupal Slack, and/or attend a UX meeting to demo the patch and get direct feedback from designers/UX folks/product management on next steps. If an issue represents a significant new feature, UI change, or change to the general "user experience" of Drupal, use Needs product manager review instead. See the scope of responsibilities for product managers.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs screenshots

    The change alters the user interface, so before and after screenshots should be added to document the UI change. Make sure to capture the relevant region only. Use a tool such as Aviary on Windows or Skitch on Mac OS X.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France prudloff Lille

    Here is a reroll for Drupal 10.0.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇺🇦Ukraine super_romeo Kiev

    Patch #428 can't not be applied anymore on D10.1.x.
    Is is still needed?

  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱

    Updated drupal-2061377-437.patch, added fixes for the following issues:

    ------ ---------------------------------------------------------------------
    Line core/modules/image/image.module
    ------ ---------------------------------------------------------------------
    561 Function file_url_transform_relative not found.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    ------ ---------------------------------------------------------------------

    ------ ---------------------------------------------------------------------
    Line core/modules/image/tests/src/Kernel/EditorImageStyleDialogTest.php
    ------ ---------------------------------------------------------------------
    102 Function file_save_data not found.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    106 Function file_url_transform_relative not found.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
    ------ ---------------------------------------------------------------------

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    Custom Commands Failed
  • last update 11 months ago
    Patch Failed to Apply
  • Status changed to Needs review 11 months ago
  • last update 11 months ago
    Custom Commands Failed
  • 🇺🇦Ukraine i-trokhanenko Lutsk 🇺🇦

    Here is a reroll of #441 for Drupal 10.1.1

  • 🇳🇬Nigeria chike Nigeria

    Patch #442 applied on Drupal 10.1.1 but no image styles are showing up in CKEditor. I did turn on 'Display image styles' for the editor and selected some image styles in the configuration but using the 'Insert image' button offers no image styles.

    Perhaps this feature is not yet targeted at CKEditor 5 as screenshot above is CKEditor 4.

  • Status changed to Needs work 11 months ago
  • 🇺🇸United States smustgrave

    CC failure

    Also such a feature will need a change record.

  • 🇺🇦Ukraine Ruslan Piskarov Kiev, Ukraine

    Is it for CKEditor 4 only?

  • 🇺🇸United States smustgrave

    Ck4 is gone from core so will only be CK5.

  • 🇫🇷France GaëlG Lille, France

    Yep, as far as I know, it's discussed in comments #423 to #425 above but has not yet been addressed.

    The current patches are for CKE4 and should rather be in a CK4 contrib module issue, probably depending on this one or restricted to Drupal 8/9. And this issue should be focused on core/CKE5, in which case it should be considered as having no patch for now (I just unchecked "display" on the available patches).

    If you need this feature on CKE5, the best available option for now is the Inline responsive images contrib module with a patch from 📌 Compatibility with CKEditor5 (default in D10 core) Needs work .

  • Assigned to COBadger
  • 🇺🇸United States COBadger

    Revised 10.1 patch forthcoming.

  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • last update 9 months ago
    Custom Commands Failed
  • 🇺🇸United States COBadger

    Re-rolled patch for 10.1.x.

  • Status changed to Needs work 9 months ago
  • 🇺🇸United States smustgrave

    CC failure.

    Also appears there is no test coverage

  • 🇫🇷France GaëlG Lille, France

    Please put CKE4 patches in the newly created Allow image style to be selected in Text Editor's image dialog Active . Patches here should contain a CKE5 plugin.

  • 🇮🇳India vsujeetkumar Delhi

    Missing Trait file in #449, Added and fixed the CCF issues. Keeps as in 'Needs Work' to address #450.

  • last update 9 months ago
    Build Successful
  • 🇫🇷France GaëlG Lille, France

    @vsujeetkumar: Thank you for your work, but as said above, please put this patch into #3392556 contrib issue instead. There is no chance for it to be accepted for core as it targets CKE4.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.2 & pgsql-14.1
    last update 8 months ago
    Custom Commands Failed
  • last update 8 months ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.2 & sqlite-3.34
    last update 8 months ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & pgsql-14.1
    last update 8 months ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 8 months ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & sqlite-3.27
    last update 8 months ago
    Custom Commands Failed
  • last update 8 months ago
    Custom Commands Failed
  • 🇧🇪Belgium flyke

    #388 and #429: In case like me you are updating your Drupal and get stuck because you keep having an error like this:

    The import failed due to the following reasons:                                                                                           
      Unexpected error during import with operation update for filter.format.basic_html: The "filter_image_style" plugin does not ex  
      ist. Valid plugin IDs for Drupal\filter\FilterPluginManager are: filter_ckeditor_media_embed, editor_file_reference, filter_html, filter  
      _htmlcorrector, filter_caption, filter_html_escape, filter_html_image_secure, filter_null, filter_url, filter_align, filter_image_lazy_l  
      oad, filter_autop, gutenberg, linkit, media_embed                                                                                         
      Unexpected error during import with operation update for filter.format.gutenberg: The "filter_image_style" plugin does not exi  
      st. Valid plugin IDs for Drupal\filter\FilterPluginManager are: filter_ckeditor_media_embed, editor_file_reference, filter_html, filter_  
      htmlcorrector, filter_caption, filter_html_escape, filter_html_image_secure, filter_null, filter_url, filter_align, filter_image_lazy_lo  
      ad, filter_autop, gutenberg, linkit, media_embed

    Then the solution is to create a dummy filter with that ID. So I created a custom module containing mymodule/src/Plugin/Filter/FilterImageStyle.php with this content:

    <?php
    
    namespace Drupal\mymodule\Plugin\Filter;
    
    use Drupal\filter\FilterProcessResult;
    use Drupal\filter\Plugin\FilterBase;
    
    /**
     * Provides a filter just to fix the filter_image_style does not exist error.
     *
     * @Filter(
     *   id = "filter_image_style",
     *   title = @Translation("Fix filter_image_style error"),
     *   description = @Translation("This is just ot fix the filter_image_style does not exist error"),
     *   type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
     *   weight = 15
     * )
     */
    class FilterImageStyle extends FilterBase {
    
      /**
       * {@inheritdoc}
       */
      public function process($text, $langcode) {
        return new FilterProcessResult($text);
      }
    
    }

    Now after drush cr, you should be able to continue your work and make sure this filter is not used anywhere. For me I first exported all my config with drush cex -y. Then I searched my config/sync folder for 'filter_image_style' and removed the references to that. Then I imported updated config with drush cim -y.

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    This is #422 to work with Drupal 10.2 for whom might be interested

  • last update 6 months ago
    Custom Commands Failed
  • 🇳🇱Netherlands Martijn de Wit 🇳🇱 The Netherlands

    Drupal 10.2 is released

  • last update 6 months ago
    Custom Commands Failed
  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    Re-queued the tests for the 11.x branch.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    So we have issues with Cspell, PHPStan, PHPCS and I also think there is an issue with one of the JS files.

    Probably also best to re-roll this patch over to a MR so we can benefit from GitLab pipelines as well.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    So we have issues with Cspell, PHPStan, PHPCS and I also think there is an issue with one of the JS files.

    Probably also best to re-roll this patch over to a MR so we can benefit from GitLab pipelines as well.

  • 🇫🇷France GaëlG Lille, France

    @flyke @claudiu.cristea @Martijn de Wit @BramDriesen: please see #447 and #451.

  • I came across this issue while working on D10 upgrade for one of my sites. Please refer to the attached patch for anyone looking for a backport patch.

    PS: Thanks to @TwoD for submitting the initial patch!

  • Please ignore the previous patch. The attached patch is the correct one, this includes the missing file core/lib/Drupal/Core/Entity/DependencyRemovalTrait.php.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Wow, blast from the past. I just stumbled upon this issue after not having seen it for a very long time (and after having started it … over a decade ago 👴). Let's get this done at last!

    📌 [11.x] Remove EditorLinkDialog, EditorImageDialog and EditorMediaDialog in Drupal 11 Fixed removed EditorImageDialog. So this should now become a CKEditor 5-specific issue. And the current patch already does that! 👍

    Adjusting issue title + component.

    The issue summary's screenshots show CKEditor 4. They need to be updated.

    Review

    1. I see there's tests already! 👏 Removed .
    2. There seem every many out of scope changes in this issue? This should not make any changes to FilterFormat or FilterBase. As long as that's the case, this issue will never land. Can we please extract those changes into blocking issues? 🙏
    3. There's still a *.es6.js file in there. We haven't been using those in at least a year, so the current patch could never land as-is in Drupal 10. And … this is still targeting CKEditor 4? 😅 CKEditor 4 is EOL, it's not part of Drupal core anymore. Fortunately, for CKEditor 5, there's reusable infrastructure for this kind of thing already: the DrupalElementStyle functionality in the drupalMedia plugin — there's even a nice blog post about it that should make it much easier to get started.
    4. This is changing the default text format + editor config in the Standard install profile. Changes to core's install profiles always should happen in separate issues, because they are a different scope/consideration. Tagged for that.
  • 🇫🇷France GaëlG Lille, France

    Note that there is a contrib module which provides this kind of feature, even for CKE5. In case it can help.
    https://www.drupal.org/project/inline_responsive_images

  • 🇺🇸United States aubjr_drupal

    +1 for this feature getting in. I just ran into this need, and it seems like a no-brainer addition in the spirit of Starshot.

  • 🇺🇸United States gcalex5

    Re-roll of #455 for 10.3.x

Production build 0.69.0 2024