I'm using ECK with Bricks on a site, and having recently updated to alpha5 got a screen full of very verbose warnings. I was already using overridden templates for Bricks, so I adjusted my versions to use {{ content }} instead of {{ entity }}, but it seems the warnings will continue to display unless the original template for Bricks is changed, even though in practice that won't be used. Can this be corrected, so that the warnings only display if the active template is using {{ entity }}?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mandclu created an issue. See original summary.

legolasbo’s picture

Thanks for reporting this @mandclu,

I am going to need some more information about your configuration to be able to reproduce this. Preferably with step by step instructions detailing how to reproduce this issue on a vanilla Drupal installation. This information should at least contain the following.

  • Which (relevant) modules are you using?
  • How have these modules been configured?
  • Which templates have you overridden in which way?
mandclu’s picture

Of course, I'm happy to help.

There are a number of modules installed, but you should be able to reproduce it using just bricks and and its submodule bricks_default, including the latter's dependencies, which include ECK.

In your theme override eck-entity--brick.html.twig so that it displays {{ content }} instead of {{ entity }}. Bricks_default will have created a demo page with lots of bricks placed, which should be sufficient to observe the behaviour I'm reporting. When you visit the page, to see the content you will scroll past multiple messages like the one below:

User deprecated function: You are using the 'entity' variable in your eck-entity template. You should use 'content' instead. The 'entity' variable will be removed before the release of 8.x-1.0-beta1 in Drupal\eck\ArrayDeprecationWrapper->offsetExists() (line 45 of modules/contrib/eck/src/ArrayDeprecationWrapper.php).
Drupal\eck\ArrayDeprecationWrapper->offsetExists('field_childs') (Line: 89)
bricks_preprocess_eck_entity(Array, 'eck_entity', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('eck_entity', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 71)
__TwigTemplate_2f11609e76f1e6417cb76a3e3d2308879e780edce60ab7330a966f0ce210555f->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/de_theme/templates/field/field.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 114)
__TwigTemplate_e2d948cb564ea7f4f4bd4eeeede1b7611d107b26af421839c88f9a6ae06020bb->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/de_theme/templates/content/node.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 84)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 665)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I totally understand the desire to warn the admins of the site, but I have a number of issues with the implementation of the deprecation warning that was added to alpha5 of ECK:

  • As stated in the issue description, you get this warning even if you override the offending template.
  • The warning is unnecessarily verbose for being displayed as a message. If it's deemed necessary to display all this detail, push it into watchdog, and set a message that says to check the log for details. Personally I don't think showing all this is useful, since the specific templates it cites don't have the defect. In my case, every time it would cite all my template overrides, which were already fixed.
  • It would be much better if it were possible to only display this error once. Since it's an issue with a single module, displaying the message over and over again for each entity displayed doesn't provide additional useful information. On the site where I first observed this, I saw saw this message 19 times on the home page. To be honest, when I first saw it I thought the site was broken, not there was a deprecation issue.
mandclu’s picture

I'll add one more thing: If you go into the Bricks module and change eck-entity--brick.html.twig to use {{ content }}, all the warning go away, even though that template was already overridden.

legolasbo’s picture

Title: Deprecation warnings even if the template has been overridden » Bricks makes use of deprecated eck 'entity' variable
Project: Entity Construction Kit (ECK) » Bricks
Version: 8.x-1.x-dev » 7.x-1.x-dev

I've been able to reproduce this issue reliably and have determined that it's caused by the Bricks module which accesses the `entity` variable in it's preprocess function. Specifically this one around line 85 in bricks.module:

/**
 * Prepares variables for `eck-entity.html.twig`.
 */
function bricks_preprocess_eck_entity(&$variables) {
  if (!empty($variables['entity']['field_childs']) && Element::children($variables['entity']['field_childs'])) {
    $variables['entity']['childs'] = array_intersect_key($variables['entity']['field_childs'], Element::children($variables['entity']['field_childs']));
  }
}

Changing this to

/**
 * Prepares variables for `eck-entity.html.twig`.
 */
function bricks_preprocess_eck_entity(&$variables) {
  if (!empty($variables['content']['field_childs']) && Element::children($variables['content']['field_childs'])) {
    $variables['content']['childs'] = array_intersect_key($variables['content']['field_childs'], Element::children($variables['content']['field_childs']));
  }
}

fixes the issue.

I'll provide a patch shortly.

legolasbo’s picture

Project: Bricks » Bricks​
Version: 7.x-1.x-dev » 8.x-1.x-dev

Correct module this time

legolasbo’s picture

Status: Active » Fixed

I just checked out the latest development version of Bricks to be able to create a patch and noticed that it no longer preprocesses eck entities, nor does it provide a default template. It therefore doesn't throw any deprecation warnings. Your problem should be fixed by upgrading to the latest dev version of Bricks.

Looking at the high number of commits in the dev branch, bricks could actually use a new stable release, but that would need to be requested in another issue.

ToxaViking’s picture

Leave this patch here to add into composer.json

Status: Fixed » Closed (fixed)

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

tengoku’s picture

FileSize
920 bytes

I cant apply #8 to composer because it's mixing two projects. I'm leaving a patch with just the bricks portion that modifies bricks.module.