Installing the module on Drupal 11.2.8 and going to the configuration page I get this error:

The website encountered an unexpected error. Try again later.

ArgumentCountError: Too few arguments to function Drupal\Core\Form\ConfigFormBase::__construct(), 1 passed in /var/www/html/web/modules/contrib/whatsapp/src/Form/WhatsappSettingsForm.php on line 56 and exactly 2 expected in Drupal\Core\Form\ConfigFormBase->__construct() (line 44 of core/lib/Drupal/Core/Form/ConfigFormBase.php).

Drupal\whatsapp\Form\WhatsappSettingsForm->__construct(Object, Object, Object) (Line: 65)
Drupal\whatsapp\Form\WhatsappSettingsForm::create(Object) (Line: 36)
Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition('\Drupal\whatsapp\Form\WhatsappSettingsForm') (Line: 48)
Drupal\Core\Controller\HtmlFormController->getFormObject(Object, '\Drupal\whatsapp\Form\WhatsappSettingsForm') (Line: 58)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 55)
Drupal\crawler_rate_limit\CrawlerRateLimitMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 715)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Issue fork whatsapp-3557876

Command icon 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

mecmartini created an issue. See original summary.

mecmartini’s picture

StatusFileSize
new1.85 KB

Proposed solution

Based on https://www.drupal.org/node/3404140:

  1. Add the missing import
    use Drupal\Core\Config\TypedConfigManagerInterface;
    
  2. Update the constructor to include the new parameter
    /**
       * Constructs a new Whatsapp settings form.
       *
       * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
       *   The factory for configuration objects.
       * @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
       * The typed config manager.
       * @param \Drupal\key\KeyRepositoryInterface $key_repository
       *   The key repository service.
       * @param \Drupal\whatsapp\JavascriptLocalCache $javascript_service
       *   The JavaScript service.
       */
      public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typedConfigManager, KeyRepositoryInterface $key_repository, JavascriptLocalCache $javascript_service) {
        parent::__construct($config_factory, $typedConfigManager);
        $this->keyRepository = $key_repository;
        $this->javascriptService = $javascript_service;
      }
    
  3. Update the create() method to inject the new service
     public static function create(ContainerInterface $container) {
        return new static(
          $container->get('config.factory'),
          $container->get('config.typed'),
          $container->get('key.repository'),
          $container->get('whatsapp.javascript_cache')
        );
      }
    

This change is necessary for Drupal 11 compatibility. The module works fine with these modifications.

mecmartini’s picture

Status: Active » Needs review
joe huggans’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and it fixes the WhatsappSettingsForm form error. Thanks @mecmartini

pcambra’s picture

Status: Reviewed & tested by the community » Needs work

I think this needs to be BC with D10 otherwise we'd need a new release for D11, could you please move the patch to a MR that does this in a compatible way, maybe using https://www.previousnext.com.au/blog/safely-extending-drupal-10-plugin-c...

albert.garcia made their first commit to this issue’s fork.

albert.garcia’s picture

Created a MR with the pattern suggested by @pcambra.

pcambra’s picture

Status: Needs work » Needs review

pcambra’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

pcambra’s picture

Thanks @albert.garcia :) if you're feeling inspired, I have the same issue in the Like! module https://www.drupal.org/project/like/issues/3557853

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.