Problem/Motivation
After trying to update to SVG Image Field 2.3.6 I get the following error:
PHP Fatal error: Uncaught Error: Class "Drupal\media\Plugin\media\Source\File" not found in /web/modules/contrib/svg_image_field/src/Plugin/media/Source/ScalableVectorGraphic.php:21
I do not have the Media module installed.
Details:
→ drush cr
PHP Fatal error: Uncaught Error: Class "Drupal\media\Plugin\media\Source\File" not found in /web/modules/contrib/svg_image_field/src/Plugin/media/Source/ScalableVectorGraphic.php:21
Stack trace:
#0 /vendor/composer/ClassLoader.php(576): include()
#1 /vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}()
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\\svg_imag...')
#3 /web/modules/contrib/svg_image_field/svg_image_field.module(14): class_alias('\\Drupal\\svg_ima...', '\\Drupal\\svg_ima...')
#4 /web/core/lib/Drupal/Core/Extension/Extension.php(153): include_once()
#5 /web/core/lib/Drupal/Core/Extension/ModuleHandler.php(128): Drupal\Core\Extension\Extension->load()
#6 /web/core/lib/Drupal/Core/Extension/ModuleHandler.php(141): Drupal\Core\Extension\ModuleHandler->load('svg_image_field')
#7 /web/core/lib/Drupal/Core/DrupalKernel.php(615): Drupal\Core\Extension\ModuleHandler->loadAll()
#8 /web/core/includes/utility.inc(35): Drupal\Core\DrupalKernel->preHandle(Object(Symfony\Component\HttpFoundation\Request))
#9 /vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(70): drupal_rebuild(Object(Composer\Autoload\ClassLoader), Object(Symfony\Component\HttpFoundation\Request))
#10 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild(Array)
#11 /vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#12 /vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#13 /vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#14 /vendor/consolidation/annotated-command/src/AnnotatedCommand.php(389): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#15 /vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /vendor/symfony/console/Application.php(1088): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#22 /vendor/drush/drush/drush(4): require()
#23 /vendor/bin/drush(119): include()
#24 {main}
thrown in /web/modules/contrib/svg_image_field/src/Plugin/media/Source/ScalableVectorGraphic.php on line 21
[warning] Drush command terminated abnormally.
It is caused by the class_alias() call in svg_image_field.module. That apparently caused the file ScalableVectorGraphic.php to be loaded and if the Media module is not installed it cannot find \Drupal\media\Plugin\media\Source\File.
Steps to reproduce
- Have a Drupal site that does not have the Media module installed.
- Install svg_image_field 2.3.6
Proposed resolution
Check if the class \Drupal\media\Plugin\media\Source\File exists before making the class_alias() call.
Remaining tasks
Add an automated test that demonstrates the problem.Implement the proposed resolution.- Review.
- Merge.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork svg_image_field-3561016
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 #3
megachrizI've provided a test and a possible fix in the MR.
Comment #4
abdulaziz zaidTested; the changes work correctly with and without the Media modules enabled.
Comment #5
jwilson3Thanks Youri and Abdulaziz.
I've tested the functional test (THANK YOU!) and confirmed that without the fix, the test fails, and with the fix, the tests pas.
Merge and release on the way.
Comment #7
jwilson3This issue has been fixed and released in 2.3.7.
Comment #9
megachrizThanks for merging!
Just so you know, on the MR pipeline there is now an option to run tests without the fix. It also runs only the tests in files that were modified.
Comment #10
jwilson3Yes! I just saw that AFTER I had finished testing locally. Great addition.