Use drupal_static() instead of setting dynamic property on $config in ConfigEventsSubscriber

Created on 10 August 2023, 11 months ago
Updated 21 August 2023, 10 months ago

Compatibility issue between module version 2.1.1 and PHP version 8.2 in my project.
The error it was causing was this:

error:
Deprecated function: Creation of dynamic property Drupal\Core\Config\Config::$oembedProvidersProcessed is deprecated in Drupal\oembed_providers\EventSubscriber\ConfigEventsSubscriber->configSave() (line 82 of modules/contrib/oembed_providers/src/EventSubscriber/ConfigEventsSubscriber.php).
Drupal\oembed_providers\EventSubscriber\ConfigEventsSubscriber->configSave(Object, 'config.save', Object)
call_user_func(Array, Object, 'config.save', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'config.save') (Line: 229)
Drupal\Core\Config\Config->save(1) (Line: 278)
Drupal\Core\Config\Entity\ConfigEntityStorage->doSave('remote_audio', Object) (Line: 486)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 609)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 388)
Drupal\Core\Config\ConfigInstaller->createConfiguration('', Array) (Line: 259)
Drupal\Core\Config\ConfigInstaller->installOptionalConfig(Object, '') (Line: 163)
Drupal\Core\Config\ConfigInstaller->installDefaultConfig('module', 'media_remote_audio') (Line: 75)
Drupal\Core\ProxyClass\Config\ConfigInstaller->installDefaultConfig('module', 'media_remote_audio') (Line: 327)
Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 502)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
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: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

The issue remains open due to possible future problems, as I haven't thoroughly checked that everything functions correctly with PHP version 8.2.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • PHP 8.2

    The issue particularly affects sites running on PHP version 8.2.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @PatriciaCB
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    Instead of setting a dynamic property on the config object, I'm wondering if we can use ConfigCrudEvent::isChanged.

    ConfigEventsSubscriber::configSave modifies config and then saves it, which fires off another ConfigCrudEvent event. The purpose of $oembedProvidersProcessed is prevent an infinite loop. We need to figure out another way to check if ConfigEventsSubscriber::configSave has already acted on the config save.

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    On second thought, I bet we can leverage drupal_static() here. We should include the config object's name as part of the $name parameter to cover the case where multiple config objects are saved during the same request.

        $config_processed = &drupal_static(__METHOD__ . ':' . $config->getName());
    ...
        // Skip if the media config entity has already been processed.
        if (isset($config_processed) {
          return;
        }
    ...
            $config->setData($data);
            $config_processed = TRUE;
            $config->save();
    
    
    
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    Steps to reproduce:

    1. Install Drupal 10 with PHP 8.2.
    2. Install oEmbed Providers module.
    3. Open the Media Type entity edit page (/admin/structure/media/manage/remote_video)for 'Remove video' and save the form.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.5 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    60 pass
  • @chris-burge opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    60 pass
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    Let's go ahead and scope this issue to this use of a dynamic property on an object. If there are additional PHP 8.2 issues, we can address those separately.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.5 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    60 pass
  • Issue was unassigned.
  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    @PatriciaCB - Thanks for reporting this issue.

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

Production build 0.69.0 2024