I've just noticed a small problem, while I was working on a custom module in one of our current projects. I've created a node type inlcuding an image field and included the configuration export in a custom module. Originally I wasn't using Colorbox and used the default image display with the "medium" image style. In the config dependencies, "image.style.medium" was correctly added.

Now, I've decided to use Colorbox as field formatter instead. setting the "medium" image style as "colorbox_node_style". When I now export the changed node view display again, the config dependency on the image style is missing.

It may sound like a rather small issue, but there may be certain situations, where this missing line can cause troubles. Imagine, you're providing a custom module and package all needed aspects like node type, fields, display settings, as well as the used image styles itself into this module. If the config dependency is missing, Drupal may install the configuration entities in the wrong order, leading to errors.

In our case, the image style already exists anyway, so I can't provide a specific situation to trigger an error. But I did have problems in similar situations, where I didn't update the module's dependencies accordingly to the included configuration entities, leading to a wrong installation order of my modules, ending up in errors

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agoradesign created an issue. See original summary.

frjo’s picture

Assigned: Unassigned » frjo

This sounds definitely like a bug. Will take a look at it and get it fixed.

frjo’s picture

Please try out this patch. You will need to resave your content type display settings and then export the configurations.

It should add all the image styles that the Colorbox formatter uses as dependencies.

The code are adjusted functions from the core ImageFormatter that has been added quite recently I believe.

agoradesign’s picture

Status: Active » Reviewed & tested by the community

Thanks, works for me! :-)

agoradesign’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, I have to set it back to "needs work". It works basically and is a good progress in comparison to the original state, but I've found out, that, if you have two image fields on the same node, both using Colorbox, but different image styles, only one style gets added.

Here's an example:

langcode: en
status: true
dependencies:
  config:
    - field.field.node.news.body
    - field.field.node.news.field_gallery
    - field.field.node.news.field_image
    - field.field.node.news.field_metatags
    - image.style.mobile_full
    - node.type.news
  module:
    - colorbox
    - metatag
    - text
    - user
id: node.news.default
targetEntityType: node
bundle: news
mode: default
content:
  body:
    label: hidden
    type: text_default
    weight: 101
    settings: {  }
    third_party_settings: {  }
  field_gallery:
    weight: 103
    label: hidden
    settings:
      colorbox_node_style: news
      colorbox_node_style_first: ''
      colorbox_image_style: ''
      colorbox_gallery: post
      colorbox_gallery_custom: ''
      colorbox_caption: auto
      colorbox_caption_custom: ''
    third_party_settings: {  }
    type: colorbox
  field_image:
    weight: 102
    label: hidden
    settings:
      colorbox_node_style: mobile_full
      colorbox_node_style_first: ''
      colorbox_image_style: ''
      colorbox_gallery: post
      colorbox_gallery_custom: ''
      colorbox_caption: auto
      colorbox_caption_custom: ''
    third_party_settings: {  }
    type: colorbox
  field_metatags:
    weight: 104
    label: hidden
    settings: {  }
    third_party_settings: {  }
    type: metatag_empty_formatter
  links:
    weight: 100
    settings: {  }
    third_party_settings: {  }
hidden:
  langcode: true

-> image.style.news is missing...

frjo’s picture

Thanks for testing this! I assume it works when one has two image field with different image styles?

agoradesign’s picture

You mean, with default image formatter? hmm good question. Haven't really tested this so far...

I did a quick look at my code repo, but unfortunately I've added the second image field together with Colorbox display, and I can't do some real testing at the moment

agoradesign’s picture

Just came across this issue. I still haven't found time to test the behaviour of default image formatter. However, the patch from #3 is definitely an improvement. We use it in every project. Also, the described setup in #5 is definitely not the frequently used one.

So I plead for committing the patch, and keep the issue open for further improvements (or open a separate one).

btw, what's your plan for releasing 1.1? Since 1.0 some time has passed already, and a number of commits are in already. I saw in #2626466-16: Notice: Undefined index: theme_hook_original in twig_render_template() that people already start to create patches of already committed code to avoid using the dev version.

  • frjo committed ba54ec9 on 8.x-1.x
    Issue #2686805 by frjo: Image style dependency is missing on...
frjo’s picture

Status: Needs work » Fixed

Committed to 8-dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.