Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291641

Changing plugins from annotations to attributes in contrib leads to error if plugin extends from a missing dependency

$
0
0

Problem/Motivation

In the Image Effects module, we have been providing a set of image operations for both the 'gd' and the 'imagemagick' toolkits.

There never was a formal dependency to the ImageMagick module, though. If the module is installed, it benefits from the operations; if it isn't, the operations just stay there silently.

In converting the plugins to use attributes in place of annotations, though, I came across the fact that if the ImageMagick module is not installed, all the GD image toolkit operations fail with

The image toolkit 'gd' failed processing 'scale' for image 'core/modules/image/sample.png'. Reported error: Error - Class "Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase" not found

I think this is occurring during plugin discovery, and is probably due to class reflection actually trying to load the extended class.

Proposed resolution

If reflection failed on the class, it could be due to the class implementing or extending from interfaces/classes that are not available to the classloader. This can happen in contrib when a class in a module extends from a class in another module that is not installed.

In that case, just skip the plugin.

Drupal\Component\Plugin\Discovery\AttributeClassDiscovery no longer uses FileCache to store results of plugin class parsing.

Differently that discovery via annotations, discovery via attributes is subject to PHP runtime checks that may fail due to circumstances outside of the class itself (for instance, if a plugin class extends from an uninstalled module class). Caching the result leads to errors due if the external circumstances changes (i.e. the module that is missing is installed, or an installed module is uninstalled).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 291641

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>