Indirect modification of overloaded element of Drupal\Core\Template\Attribute has no effect in mytheme_preprocess_html()

Created on 21 May 2019, over 5 years ago
Updated 10 February 2024, 12 months ago

Hello I have a problem recently update to drupal 8.7.1 but now the personal body class I did in mytheme.theme does not work this is the error that I get

Notice: Indirect modification of overloaded element of Drupal\Core\Template\Attribute has no effect in mytheme_preprocess_html() (line 43 of /home/mytheme/public_html/themes/mytheme/mytheme.theme) #0 /home/mytheme/public_html/core/includes/bootstrap.inc(584): _drupal_error_handler_real(8, 'Indirect modifi...', '/home/mytheme/...', 43, Array) #1 /home/mytheme/public_html/themes/mytheme/mytheme.theme(43): _drupal_error_handler(8, 'Indirect modifi...', '/home/mytheme/...', 43, Array) #2 /home/mytheme/public_html/core/lib/Drupal/Core/Theme/ThemeManager.php(287): mytheme_preprocess_html(Array, 'html', Array) #3 /home/mytheme/public_html/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('html', Array) #4 /home/mytheme/public_html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #5 /home/mytheme/public_html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(147): Drupal\Core\Render\Renderer->render(Array) #6 /home/mytheme/public_html/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() #7 /home/mytheme/public_html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(148): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #8 /home/mytheme/public_html/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch)) #9 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #10 /home/mytheme/public_html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #11 /home/mytheme/public_html/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent)) #12 /home/mytheme/public_html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #13 /home/mytheme/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #14 /home/mytheme/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /home/mytheme/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(184): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /home/mytheme/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(121): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /home/mytheme/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(75): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /home/mytheme/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /home/mytheme/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /home/mytheme/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /home/mytheme/public_html/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /home/mytheme/public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #23 {main}.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated about 1 hour ago

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tregonia

    I am encountering this issues on 10.1.0-alpha1 with the following code.

    function theme_preprocess_html(&$variables) {
      // Add class to html if user is masquerading.
      $isMasquerading = \Drupal::service('masquerade')->isMasquerading();
      if ($isMasquerading) {
        $variables['html_attributes']['class'][] = 'masquerading';
      }
    }

    My workaround is to not put the class on the <html> element, and just go with the <body> instead.

    function theme_preprocess_html(&$variables) {
      // Add class to html if user is masquerading.
      $isMasquerading = \Drupal::service('masquerade')->isMasquerading();
      if ($isMasquerading) {
        $variables['attributes']['class'][] = 'masquerading';
      }
    }
  • πŸ‡¬πŸ‡§United Kingdom joachim

    I can reproduce this:

        $attr = new Attribute();
        $attr['class'][] = 'cake';
    

    The CR at https://www.drupal.org/node/1727592 β†’ says:

    > Classes are an example to use array for. When using array, you must initialize the array first before adding items.

    But in an alter hook, how are you meant to know if the array has been initialised already or not?

    E.g. I am in mymodule_preprocess_views_table() and one row gives me this error (and so does NOT have the class array initialised) and the other one doesn't (and therefore already has something there).

    Presumably if I do

    > $variables['item_attribute']['class'] = array();

    and some classes were already there, then they'll get zapped?

    Additionally, the bit about needing to initialize the array first is not documented in the class.

  • πŸ‡ͺπŸ‡ΈSpain jordimateubesancon

    I found a solution for a similar issue in my custom theme with HOOK_preprocess_links__language_block(&$variables) adapting the solution provided by the patch 3207515-fixed-indirect-modification-of-overloaded-element-03.patch in this issue https://www.drupal.org/project/field_group/issues/3207515 β†’ .

Production build 0.71.5 2024