Entity (vanilla) Field Formatter loses "View mode"

Created on 27 September 2023, about 1 year ago
Updated 28 September 2023, about 1 year ago

Problem/Motivation

I use the module "slick_entityreference" to create content slides (nodes with text and images) using the module Slick and Blazy, with the previous versions (Slick 2.09 and Blazy 2.16) everything works correctly, but with the latest versions (Slick 2.10 and Blazy 2. 18) it is impossible to choose or configure the "View Mode" to use (usually the view mode "default" is used to display the page and the the view mode "teaser" or similar is the one used to display an image and text to create a nice Slide content). Now, this field "View mode" has disappeared in the interface for "Slick Entity Reference Vanilla". The functionality is intact as long as you don't need to reconfigure this field in content Type Display, because if you do, you lose the View_mode value that was already saved previosly.

Investigating I thought it was a problem with the "slick_entityreference" module, or the "Slick" module, but in the end I realised that the problem is in the Blazy module, see the proposed solution for more information on the problem.

Steps to reproduce

1.- Create a Test Content Type
2.- Add a Node Reference Field
3.- In "Manage Display" of this newly created Content Type choose "Slick Entity Reference Vanilla", when trying to configure it, the "View mode" field does not appear.

Proposed resolution

blazy\src\Form\BlazyAdminBase.php

The code has changed a lot from version 2.16 to version 2.18 in that Fucntion:

public function baseForm(array &$definition)

Line 283-288:

    $no_image   = $scopes->is('no_image_style');
    $multimedia = $scopes->is('multimedia');

    if ($no_image) {
      return [];
    }

Remove the "If" code or comment the "return"

    $no_image   = $scopes->is('no_image_style');
    $multimedia = $scopes->is('multimedia');

    if ($no_image) {
      //return [];
    }

As there are no images (or rather the value 'no_image_style' is TRUE), it doesn't finish building the form and returns an empty value, so it never gets any lower and the following code is never executed, which is the one I'm interested in:

    $disabled = $scopes->is('no_view_mode');
    $target_type = $blazies->get('field.target_type');
    $is_fieldable = $target_type && $blazies->get('field.view_mode');

    if ($is_fieldable && !$disabled) {
      $form['view_mode'] = [
        '#type'     => 'select',
        '#options'  => $this->getViewModeOptions($target_type),
        '#title'    => $this->t('View mode'),
        '#weight'   => -101,
        '#enforced' => TRUE,
      ];
    }

And this is the reason why in Blazy version 2.18 the "View mode" field in the interface has disappeared.

This "return" causes more problems, like never saving the "override options" settings for example, and may be causing more problems elsewhere...

Remaining tasks

Someone with more knowledge of the module/s may propose a better solution, as I don't have a complete picture of the project and I am not able to see the problems that the change I propose may cause, although in my Webs everything works apparently fine with this change.

User interface changes

-

API changes

-

Data model changes

-

🐛 Bug report
Status

Fixed

Version

2.18

Component

User interface

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Luispe
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    50 pass
  • 🇮🇩Indonesia gausarts

    Thank you.

    Looks like being blocked by $no_image check.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    50 pass
  • 🇮🇩Indonesia gausarts

    Another miss. Unlike Slick, Splide is capable of displaying images even with vanilla mode.

    • gausarts committed bec78a61 on 8.x-2.x
      Issue #3390209 by gausarts, Luispe: Field Formatter lose "View mode"
      
  • Status changed to Fixed about 1 year ago
  • 🇮🇩Indonesia gausarts

    Not so useful tips:
    When changing formatters, slick to splide entity references (rare case in real world), and you don't see Splide options, be sure to reload the page first. Looks like Drupal AJAX doesn't read the differences between the two almost similar forms with minor added form items.

    Feel free to re-open if still an issue.

    Committed. Thank you for contribution.

  • Hello I can't apply the patch.
    I get the following:

    ~/website/web/modules/contrib/blazy$ git apply -v drupal.org_files_issues_2023-09-28_blazy-3390209-view-mode-gone-5.patch
    Checking patch css/blazy.css...
    error: while searching for:
    border: 0;
    }

    /* To keep animated elements in place when not happing .blazy container. */
    .media--blazy,
    /* Or BlazyFilter which has no .blazy container. */
    .media--fx {

    error: patch failed: css/blazy.css:54
    error: css/blazy.css: patch does not apply
    Checking patch src/Form/BlazyAdminBase.php...

    And then nothing happens.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.5 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Patch Failed to Apply
  • 🇮🇩Indonesia gausarts

    Not sure :)

    Try viewing this file in browsers:
    .../modules/contrib/blazy/blazy.css

    Search for typos: happing vs having.

    If the first exists, something else breaks it.
    If the later exists, you are using the latest DEV which already contains it, no need to apply the patch.

  • Hello gausarts,

    As always a pleasure to deal with you, you do a great job and we thank you very much.

    I hope you forgive me, but I'm sorry to inform you that the patch is not correct, maybe the output has been mixed with other changes you were making, the first lines of the patch must be removed so that the patch is applied correctly:

    diff --git a/css/blazy.css b/css/blazy.css
    index a7b6477..6cda23c 100644
    --- a/css/blazy.css
    +++ b/css/blazy.css
    @@ -54,7 +54,7 @@ html:not(.js) [data-b-blur] {
       border: 0;
     }
     
    -/* To keep animated elements in place when not happing .blazy container. */
    +/* To keep animated elements in place when not having .blazy container. */
     .media--blazy,
     /* Or BlazyFilter which has no .blazy container. */
     .media--fx {

    Also it doesn't work properly, although the "View mode" field appears, but only the "default" value appears, this is because you use the variable "$target_type" to get the view mode options in:

          $form['view_mode'] = [
            '#type'     => 'select',
    	'#options'  => $this->getViewModeOptions($target_type),
            '#title'    => $this->t('View mode'),
            '#weight'   => -101,
            '#enforced' => TRUE,
          ];

    But this variable, which should have a string value, like "node" for example, has become a boolean value, because previously you make a comparison "||" and if both values are empty it returns "false" and if any of them contains any data it returns "true":

    $target_type  = $scopes->get('target_type') || $blazies->get('field.target_type');
    
  • 🇮🇩Indonesia gausarts

    Looks like JS logic mixed up PHP :)

    Try changing || to ?:.

  • Thank You gausart, I have uploaded a new patch with the suggested changes, in case anyone needs it.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Thank you all! Now it's working.
    I change || to ?: as suggested.

    Thank you.

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

Production build 0.71.5 2024