Drupal\Component\Plugin\Exception\PluginException: The plugin (svg) did not specify an instance class.

Created on 1 April 2025, 2 months ago

Problem/Motivation

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).
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)

Steps to reproduce

Updated from 2.3.3 to 2.3.4 and now receiving the above error

Using Drupal version 10.3.6

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.3

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia ben.campbell

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

Merge Requests

Comments & Activities

  • Issue created by @ben.campbell
  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    @ben.campbell, does rebuilding all caches after updating, as indicated in the 2.3.4 release notes β†’ resolve the problem?

  • πŸ‡¦πŸ‡ΊAustralia ben.campbell

    @jwilson3 unfortunately it doesn't

  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    @ben.campbell, thanks for the feedback. Can you tell me a little more about your setup please.

    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/custom/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: Are you running 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.php and not SVG.php, noting correct capitalization of the first letter only. This file is located at modules/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 another drush 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:

    chmod 644 web/modules/custom/svg_image_field/src/Plugin/media/Source/Svg.php
    

    Check for stale cache files: Sometimes old cached versions of the plugin definition can persist. Please check and clear:

    sites/default/files/php/twig/*
    sites/default/files/php/*
    
  • πŸ‡ΊπŸ‡ΈUnited States cmlara
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    The 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.

    composer remove drupal/svg_image_field
    composer install drupal/svg_image_field
    

    This approach may not be practical for all users, especially if you depend on a continuous integration process and a separate server to build your composer dependencies for deployment.

    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 file SVG.php and Svg.php.

Production build 0.71.5 2024