Broken website after 2.0.2 update

Created on 21 September 2023, about 1 year ago
Updated 15 May 2024, 6 months ago

Hello my dear shortcode developers!

We just encountered a broken website after the 2.0.2 update with the following error:

ArgumentCountError: Too few arguments to function Drupal\shortcode\Plugin\ShortcodeBase::__construct(), 3 passed in /our-path/html/modules/custom/nd_visualshortcodes/nd_visualshortcodes.module on line 82 and exactly 4 expected in Drupal\shortcode\Plugin\ShortcodeBase->__construct() (line 71 of /our-path/html/modules/contrib/shortcode/src/Plugin/ShortcodeBase.php).

As you can see we have a custom module which extends the shortcode class with some functionality we needed for our customer.

What we didn't expect is that a patch release from 2.0.1 to 2.0.2 would introduce a (according to sematic versioning) major change in class signature since the RendererInterface $renderer was suddenly added to the ShortcodeBase as one can see here:

https://git.drupalcode.org/project/shortcode/-/compare/2.0.1...2.0.2?fro...

sure this was a rather easy fix from our side since we just had to adjust our overwritten __construct and create method but I would really like to encourage the maintainers of this module to look out for this kind of stuff and keep semantic versioning in mind.

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇦🇹Austria kevin.pfeifer

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

Comments & Activities

  • Issue created by @kevin.pfeifer
  • 🇺🇸United States CProfessionals

    Same issue here. What was your fix?

  • 🇦🇹Austria kevin.pfeifer

    As explained above we had our own Shortcode classes which overwrote/extended the __construct method of the ShortcodeBase class.

    We had to adjust

    public function __construct(array $configuration, $plugin_id, $plugin_definition, $cart_provider = NULL, EntityTypeManagerInterface $entity_type_manager = NULL) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);

    to

     public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer, $cart_provider = NULL, EntityTypeManagerInterface $entity_type_manager = NULL) {
        parent::__construct($configuration, $plugin_id, $plugin_definition, $renderer);

    and adjust the create() method to

      public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static(
          $configuration,
          $plugin_id,
          $plugin_definition,
          $container->get('renderer'),
          \Drupal::moduleHandler()->moduleExists('commerce') ? $container->get('commerce_cart.cart_provider') : [],
          $container->get('entity_type.manager')
        );

    The $container->get('renderer'), was added

  • 🇺🇸United States CProfessionals

    Thank you so much for posting your code. You Rock!

  • 🇺🇸United States CProfessionals

    Updating this issue. NikaDev on Themeforest actually sent out an update 2.0 in September that resolved this issue. I just overwrote the old nd_visualshortcode module with the new nd_visualshortcode module from the Drupal 10 distribution of the theme. Everything seems to be working.

  • 🇪🇸Spain gauladell

    Thank you! It also worked for me,

    But i needed to add also :

    use Drupal\Core\Render\RendererInterface;
    
  • 🇮🇳India rajeevCoder

    Still not working

Production build 0.71.5 2024