Hello

When I modify a view, I get this error:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "lazy_image" plugin does not exist. Valid plugin IDs for Drupal\Core\Field\FormatterPluginManager are: address_plain,...etc."

It looks like the src/Plugin/Field/FieldFormatter/LazyImageFormatter.php isn't executed (this file contains the declaration of the fieldformatter)

I'm confused since I can't uninstall the Lazy module (the same error message occurs) and I need to make changes to my views.

The wesite does work and isn't impacted by the issue, the problems happens only in the admin.

Thank you for your help

Comments

MNSTR created an issue. See original summary.

MNSTR’s picture

I have found the root cause of the issue.
For some reason, the "Additional image formatters" where disabled in the module configuration. It was probably enabled for some time.

Maybe there should be a workaround in the module source code for this case.

james.williams’s picture

Status: Active » Needs work

The lazy module's formatters should declare the lazy.settings configuration as a dependency, because otherwise display modes can contain the formatter despite them being disabled -- even if lazy.settings might be about to enable them in the same config sync. But because the dependencies aren't flagged, lazy.settings isn't imported first, as needed.

So each of the formatters needs a calculateDependencies() method added, which should return lazy.settings. That should be a relatively simple patch.

james.williams’s picture

Status: Needs work » Needs review
StatusFileSize
new1.22 KB

Here's a patch that should solve it, at least as long as the lazy formatter isn't disabled in lazy.settings after saving the display mode settings!

Dynamically disabling a formatter is a pretty weird pattern that is going to leave a bunch of edge cases like this :-( But at least this should solve the most common issue, I believe.

osman’s picture

Status: Needs review » Needs work
StatusFileSize
new111.2 KB

TIL, calculateDependencies() ...
thanks for this James, and the patch :)

After adding the patch, core.entity_view_display.<entity_type>.<bundle>.<view_mode>.yml would list lazy.settings in dependencies.config.

However, without the patch it would already list the lazy module as a dependency in dependencies.module.

dependencies

I was hoping it would disallow uninstalling the module, when the extra field formatters enabled.

james.williams’s picture

Status: Needs work » Needs review
StatusFileSize
new46.13 KB

As per this screenshot - this just follows Drupal's standard behaviour, which allows modules to be uninstalled, and Drupal will replace the formatter with the default formatter in the display mode.

Screenshot showing Drupal would update the display mode if Lazy module is uninstalled.

Otherwise uninstalling modules would be really tricky! If you want to make it difficult to uninstall the module, I don't think that's helpful. I think the normal behaviour that Drupal facilitates should be followed here.

Anyway -- as you say, the lazy module is listed as a dependency in this way, regardless of this module, so this patch is not doing that. This patch is just about ensuring that configuration can be reliably synchronised (i.e. so lazy.settings gets synchronised before display modes using the formatters). Handling uninstallation could be a separate issue, if you wanted to discuss that?

  • osman committed 0896c3e on 8.x-3.x
    Issue #3118015 by osman: Add dependent modules for the formatters
    
  • osman committed 1511e41 on 8.x-3.x
    Issue #3118015 by james.williams:  The "lazy_image" plugin does not...
  • osman committed 23390fd on 8.x-3.x
    Issue #3118015 by osman: Remove "formatters" settings from the Lazy...
osman’s picture

Hey James, I am happy to include the calculateDependencies() method, thank you :) With your patch now the dependencies are synced correctly for the "Image (Lazy-load)" and "Responsive image (Lazy-load)" image-formatters.

However, I noticed that the core's "Image" and "Responsive image" formatters are still missing the lazy.settings. I am still investigating...

Meanwhile, I totally agree uninstalling modules should not be tricky or complicated.

So, to make things less complicated, I decided to make the "Image (Lazy-load)" and "Responsive image (Lazy-load)" image-formatters enabled at all times, as long as the core's "Image" and "Responsive image" modules, respectively, are already enabled.

MNSTR, would you like to give the dev branch a shot on your development environment, and share your experience? :)

james.williams’s picture

Oh ace, thanks! I don't think it's a big issue for the core formatters to be missing lazy.settings from their dependencies, as they will still function fine if that config was missing - they just wouldn't get the added enhancement of lazy loading (even if configured to use lazy loading).

I'll give the update a look if I can get time... if only that came easily!

P.S. What does 'MNSTR' mean? :)

osman’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

vishal prasad’s picture

I had the same error
in that case if you have a backup of the configuration then that will be great and importing the configuration using drush cim should solve the error, but if u don't have the backup then just run composer update and that should solve the issue.