Skip to content
Snippets Groups Projects

Issue #3257729: Formatters shouldn't repeat core code

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Joshua Sedler
  • Joshua Sedler
  • Joshua Sedler
  • added 1 commit

    • a8a6f062 - Simplify code further, bring back early opt-out

    Compare with previous version

  • 94 foreach ($imageStyles as $image_style) {
    95 $cacheTags = Cache::mergeTags($cacheTags, $image_style->getCacheTags());
    96 }
    97 78
    98 79 $svgAttributes = $this->getSetting('svg_attributes');
    80
    99 81 foreach ($files as $delta => $file) {
    100 $attributes = [];
    82 $element = &$elements[$delta];
    101 83 $isSvg = svg_image_is_file_svg($file);
    102 84
    103 if ($isSvg) {
    85 $cacheTags = Cache::mergeTags($element['#cache']['tags'], $file->getCacheTags());
    86
    87 if (!$isSvg) {
    88 $elements[$delta]['#cache']['tags'] = $cacheTags;
    • Was wondering why we need to update cache tags for non-SVG files... :thinking:

    • So am I. I kept the cache tags handling due to the fact that they are merged with the file's cache tags:

      $cacheTags = Cache::mergeTags($element['#cache']['tags'], $file->getCacheTags());

      But I'm not sure if that's really necessary at all. The parent formatter has no such handling.

    • Exactly, may be we can remove it for better clarity.

      @Grevil what do you think?

      EDIT: it looks like it was added in the original commit (issue #2981263).

      Edited by Frank Mably
    • Yea, this seems unnecessary! Seems I missed that, thx! :) Let's remove it! I think we need to pass

      cacheTags in 124 and 132 instead of `
      elements[$delta]['#cache']['tags']`?

    • Christopher Lewis changed this line in version 13 of the diff

      changed this line in version 13 of the diff

    • After removing the additional $cacheTags, there is no need to pass the already existing $elements[$delta]['#cache']['tags'] , so I was able to further simplify the code.

    • Are you sure it was completely unneeded?

      I was saying that we could remove $cacheTags from the !$isSvg part of the condition, not the other part...

      Edited by Frank Mably
    • The fact is that in the $isSvg part, the responsive image formatter does exactly the same as the non-responsive image formatter: return an image_formatter render array without image style (when "render as image" is active) or the raw SVG contents. In both cases, the SvgImageFormatter does not add additional cache tags.

      That's why I didn't see a reason to keep the cache tags in the SvgResponsiveImageFormatter. That way, we are further unifying the two formatters (see also #3477774).

    • Ok for me then, @Grevil you can merge.

    • Please register or sign in to reply
  • Had another look at this and was able to simplify the code further by removing more code that's already contained in the parent formatters. Also, I removed some cache handling code that had already been removed in HEAD but was brought back to this branch by mistake.

    Also added a few comments as requested by @Grevil.

    Last but not least, I noticed that there is a bug in SvgResponsiveImageFormatter not linking the image when we're dealing with an inline SVG. But that's out of scope of this issue; will open a separate one.

  • added 8 commits

    • 10c0c556 - 1 commit from branch project:3.x
    • 6e10b2f8 - 3257729: Formatters should not repeat core code.
    • 98eb89c9 - Fix cache context handling
    • dc41559a - Use existing fileUrlGenerator variable
    • 42cbeee9 - Tidy up use statements
    • 77d1ee7a - Fix another phpcs issue
    • dcd8052c - Bring back the $imageStyle variable that is now used for dimension transformation. Fix phpcs.
    • bc330b82 - Simplify code further, bring back early opt-out

    Compare with previous version

  • added 1 commit

    • e796bf51 - Remove additional cache tags; unify code in both formatters in preparation for #3477774

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading