Problem/Motivation

Fatal error when using the module on PHP 8+ due to missing return type in submitConfigurationForm:

Fatal error: Declaration of Drupal\cookies\Plugin\Block\CookiesDocsBlock::submitConfigurationForm(array &$form, Drupal\Core\Form\FormStateInterface $form_state) must be compatible with Drupal\Core\Block\BlockBase::submitConfigurationForm(array &$form, Drupal\Core\Form\FormStateInterface $form_state): void

Steps to reproduce

  1. Enable the Cookies module in a Drupal site running PHP 8+
  2. Access a page rendering the CookiesDocsBlock

Proposed resolution

Update the method to match the signature of the parent class:

diff --git a/src/Plugin/Block/CookiesDocsBlock.php b/src/Plugin/Block/CookiesDocsBlock.php
index 23039b7..cececbe 100644
--- a/src/Plugin/Block/CookiesDocsBlock.php
+++ b/src/Plugin/Block/CookiesDocsBlock.php
@@ -155,7 +155,7 @@ class CookiesDocsBlock extends BlockBase implements ContainerFactoryPluginInterf
   /**
    * {@inheritdoc}
    */
-  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+  public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
     $this->configuration['show_cookies_settings_button'] = $form_state->getValue('show_cookies_settings_button');
     parent::submitConfigurationForm($form, $form_state);
   }

Remaining tasks

  • Review and commit patch

User interface changes

None

API changes

None

Issue fork cookies-3535527

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

cvalverp created an issue. See original summary.

cvalverp’s picture

cvalverp’s picture

StatusFileSize
new710 bytes
mkalkbrenner’s picture

Version: 1.2.15 » 2.x-dev
Status: Active » Needs work
mkalkbrenner’s picture

Status: Needs work » Needs review
mkalkbrenner’s picture

Assigned: cvalverp » Unassigned
Priority: Normal » Critical
mkalkbrenner’s picture

This error breaks upgrades to Drupal 11.2

mkalkbrenner’s picture

Version: 2.x-dev » 1.2.x-dev
Status: Needs review » Reviewed & tested by the community

The simple patch fixes Drupal 11.2 (and backwards) compatibility.

the app service’s picture

Just for everyone that runs into the same problem like me where no drupal page renders anymore because of this problem in the log:

Just modify the file yourself as a workaround till a new plugin version is released:
/web/modules/contrib/cookies/src/Plugin/Block/CookiesDocsBlock.php

And add the proposed change above:
OLD:
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {

NEW:
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {

liam morland’s picture

Issue tags: -php8 +PHP 8.0
anybody’s picture

Version: 1.2.x-dev » 2.x-dev
Assigned: Unassigned » grevil
anybody’s picture

Please use MRs not patches everyone!

grevil’s picture

Assigned: grevil » Unassigned
Status: Reviewed & tested by the community » Closed (duplicate)

This was already fixed through #3526709: 11.2 compatibility a long time ago.

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.