Problem/Motivation
In version 2.3.4 of SVG Image Field, we renamed SVG.php to Svg.php to pass GitLab CI phpstan codesniff Drupal.NamingConventions.ValidClassName.NoUpperAcronyms in commit 454081d39.
In some scenarios, case insensitive file systems have trouble upgrading from version 2.3.3 to 2.3.4. If the filename is not properly renamed during the module update process, users may be presented with a WSOD containing one of the two following error messages on screen or in logs:
Drupal\Component\Plugin\Exception\PluginException: The plugin (svg) did not specify an instance class. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 79 of core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).
Or the error message from #3504935:
Drupal\Component\Plugin\Exception\PluginException: Plugin (svg) instance class "Drupal\svg_image_field\Plugin\media\Source\SVG" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 97 of core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).
Steps to reproduce
- Updated SVG Image Field from 2.3.3 to 2.3.4 and now receiving the above error.
- Using Drupal version 10.3.6.
Proposed resolution
- Rename class filename from
src/Plugin/media/Source/Svg.phptosrc/Plugin/media/Source/ScalableVectorGraphic.php. - Provide a
class_aliasin the module file so that Drupal\svg_image_field\Plugin\media\Source\SVG still works.
Remaining tasks
- Pass CI.
- Get someone that is experiencing the bug to confirm that the Classname change solves the issue.
User interface changes
None.
API changes
Class Drupal\svg_image_field\Plugin\media\Source\SVG will become Drupal\svg_image_field\Plugin\media\Source\ScalableVectorGraphic
Drupal\svg_image_field\Plugin\media\Source\SVG remains available as an alias for backward compatibility.
Data model changes
None.
Full stack trace:
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 62)
Drupal\Core\Plugin\DefaultSingleLazyPluginCollection->initializePlugin() (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection->get() (Line: 88)
Drupal\Core\Plugin\DefaultSingleLazyPluginCollection->setConfiguration() (Line: 104)
Drupal\Core\Plugin\DefaultSingleLazyPluginCollection->addInstanceId() (Line: 55)
Drupal\Core\Plugin\DefaultSingleLazyPluginCollection->__construct() (Line: 204)
Drupal\media\Entity\MediaType->sourcePluginCollection() (Line: 193)
Drupal\media\Entity\MediaType->getSource() (Line: 48)
media_entity_file_replace_entity_extra_field_info()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 423)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 676)
Drupal\Core\Entity\EntityFieldManager->loadExtraFields() (Line: 649)
Drupal\Core\Entity\EntityFieldManager->getExtraFields() (Line: 173)
Drupal\Core\Entity\EntityDisplayBase->init() (Line: 155)
Drupal\Core\Entity\EntityDisplayBase->__construct() (Line: 181)
Drupal\Core\Entity\Entity\EntityViewDisplay->__construct() (Line: 48)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->__construct() (Line: 418)
Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords() (Line: 41)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage->mapFromStorageRecords() (Line: 186)
Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple() (Line: 312)
Drupal\Core\Entity\EntityStorageBase->loadMultiple() (Line: 121)
Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays() (Line: 281)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple() (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 870)
Drupal\Core\Render\Renderer->doCallback() (Line: 432)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Issue fork svg_image_field-3516563
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jwilson3@ben.campbell, does rebuilding all caches after updating, as indicated in the 2.3.4 release notes resolve the problem?
Comment #3
jwilson3Comment #4
ben.campbell commented@jwilson3 unfortunately it doesn't
Comment #5
jwilson3Comment #6
jwilson3@ben.campbell, thanks for the feedback. Can you tell me a little more about your setup please. Based on the stack trace, it looks like you might be using Layout Builder, which I don't use, so I'm not as familiar with the architecture and ecosystem, including how and where things are cached. Do you have any additional insight or context on whether there is a special cache that might need to be cleared for Layout Builder? Does this happen on newly created nodes/entities that use Layout Builder with an embedded SVG Image from the media library, or only existing nodes/entities?
Other things to check:
Verify plugin file location Confirm the Svg.php file is in the correct location according to the namespace. If installed via composer with a conventional Drupal composer installation the file should be located in web/modules/contrib/svg_image_field/src/Plugin/media/Source/Svg.php (the top-level folder "web" might instead be called "docroot" or something similar, or in some rare cases may not even be present).
Confirm case-sensitive filesystem: Is the error happening on an operating system that leverages a case sensitive filesystem like Windows or Mac?
Confirm title-case filename: Please verify that the filename is exactly
Svg.phpand notSVG.php, noting correct capitalization of the first letter only. This file is located atmodules/contrib/svg_image_field/src/Plugin/media/Source/Svg.php. The 'svg' MediaSource plugin not being found could be related to the file's case not getting changed properly in the version upgrade to 2.3.4.Rebuild composer's autoload files. Run a
composer dump-autoload. Then anotherdrush cache:rebuild, and then check again to see if the problem goes away.Check file permissions:. Ensure the Svg.php file has proper read permissions and can be read by the webserver with:
Check for stale cache files: Sometimes old cached versions of the plugin definition can persist. Please check your filesystem for instances of
SVG.php(the old capitalized version of the file) and then also clear:Comment #9
jwilson3The workaround for version 2.3.4 of this module is to completely remove the old module, and re-add it, to get the new version of the file name.
This approach may not be practical for all users, especially if you depend on read-only file systems on your remote webservers, or use a continuous integration process to build your dependencies from composer.json automatically.
Therefore, after discussion with @cmlara and @penyaskito Drupal contributors in the #maitainers channel on Drupal Slack, we think the solution architecture for a proper fix is to completely rename the plugin file to
ScalableVectorGraphic.php, to avoid the case sensitivity issue, and to add class aliases for the old versions of the fileSVG.phpandSvg.php.Comment #11
jwilson3Comment #12
jwilson3Comment #13
jwilson3Comment #14
jwilson3Comment #17
jwilson3This has been included in 2.3.x branch.
I would really appreciate if someone affected by this issue could test updating their composer to:
composer require drupal/svg_image_field:^2.3.x-devThen clear cache, and confirm that the errors no longer exist.
I'm really surprised no one has bothered to chime in here, especially since I've seen a noted down-tick in adoption of the version that released the renamed SVG.php that caused this issue.
If no one answer on this issue in the next 2 weeks, I'm going to cut a new release, which will affect everyone using the module to cast the net wider to receive feedback.
Thank you.
Comment #19
jwilson3This is now released in version 2.3.5 of SVG Image Field. Please check release notes.