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
- Enable the Cookies module in a Drupal site running PHP 8+
- 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
User interface changes
None
API changes
None
Comments
Comment #2
cvalverp commentedComment #3
cvalverp commentedComment #4
mkalkbrennerComment #5
mkalkbrennerComment #6
mkalkbrennerComment #7
mkalkbrennerThis error breaks upgrades to Drupal 11.2
Comment #8
mkalkbrennerThe simple patch fixes Drupal 11.2 (and backwards) compatibility.
Comment #9
the app service commentedJust 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 {Comment #10
liam morlandComment #11
anybodyComment #12
anybodyPlease use MRs not patches everyone!
Comment #13
grevil commentedThis was already fixed through #3526709: 11.2 compatibility a long time ago.