Problem/Motivation
Enabling Lazy module for the first time using version 3.7 generates PHP warnings:
Warning: Invalid argument supplied for foreach() in lazy__update_migrate_config() (line 126 of /var/www/html/web/modules/contrib/lazy/lazy.install).
Steps to reproduce
- Install Lazy v3.7
- Observe PHP errors on the Extend page upon activation.
Proposed resolution
Provide default values for legacy settings that are not used anymore.
For example; from $image_fields = $config->get('image_fields'); to $image_fields = $config->get('image_fields') ?: [];
Comments
Comment #3
osmanComment #4
miikamakarainen commentedEdit: Sorry, the following reply was meant for issue 3212059.
The dev-branch did not resolve the issue. I did a bit more digging and found out what specific settings cause it.
I have created a custom text format and have enabled lazyloading on that text format.
If I disable lazy-loading on said text format the error goes away. The default formats (basic_html and full_html) work fine with lazy-loading, it is only generating an error if enabled on my custom text format.
Below is the full error message.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function get() on null in Drupal\lazy\Plugin\Filter\LazyFilter->tips() (line 205 of modules/contrib/lazy/src/Plugin/Filter/LazyFilter.php).
Drupal\lazy\Plugin\Filter\LazyFilter->tips() (Line: 335)
_filter_tips() (Line: 362)
template_preprocess_filter_guidelines() (Line: 287)
Drupal\Core\Theme\ThemeManager->render() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 444)
Drupal\Core\Render\Renderer->doRender() (Line: 444)
Drupal\Core\Render\Renderer->doRender() (Line: 444)
Drupal\Core\Render\Renderer->doRender() (Line: 200)
Drupal\Core\Render\Renderer->render() (Line: 450)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 89)
__TwigTemplate_b9d24444049ab7e929863bdef9f07a2f4dd4f3feb56bb39da7cca8039726e43b->doDisplay() (Line: 405)
Twig\Template->displayWithErrorHandling() (Line: 378)
Twig\Template->display() (Line: 390)
Twig\Template->render() (Line: 65)
twig_render_template() (Line: 384)
Drupal\Core\Theme\ThemeManager->render() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 444)
Drupal\Core\Render\Renderer->doRender() (Line: 444)
Drupal\Core\Render\Renderer->doRender() (Line: 200)
Drupal\Core\Render\Renderer->render() (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 706)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Comment #5
osmanI use Lazy with custom text-formats as well; but never faced this error once.
I'll check on this in more-depth the first chance I have free time.
Meanwhile if you could provide additional info on your setup that would help too. Thanks
Comment #6
pick_d commentedI have had such issue today.
Probably the solution, at least in my case, was to download whole zip or tar file from latest release (now it's https://github.com/aFarkas/lazysizes/releases/tag/5.3.1), unpack the archive into /libraries and rename accordingly.
When I had only lazysizes.min.js file in /libraries/lazysizes/, the module worked just fine, but after upgrading to 3.7 I received a lot of such errors in the log, starting exactly the way stated above.
Moreover, status page said that no lazysizes library was installed.
Few minutes ago I upgraded Drupal from 9.1.7 to 9.1.8 and also unpacked the whole lazysizes zip file, as said above.
Now I don't see any errors in dblog, and status page shows no errors either.
Probably module technically can work with only lazysizes.min.js (and it worked without errors for quite some time, including version 3.6), but shows errors wth 3.7 if done this way.
Comment #7
osman@miikamakarainen, thanks. The issue you mentioned is resolved now: #3212059: Error: Call to a member function get() on null in Drupal\lazy\Plugin\Filter\LazyFilter->tips()
@pick_d, Unfortunately, v3.7 introduced a couple new bugs. The one above, was one of the issues. And likely the one caused the errors you mentioned. It's now fixed in 3.8, please upgrade, and run the update.php too.
Until 3.7, the Status page was reading the version information from the
lazy.libraries.ymlfile. Which doesn't always match to actually installed library version. As of 3.7, lazySizes library's version information is read from thepackage.jsonfile instead.If the library folder doesn't include the
package.jsonfile, the Status page would wrongly report it as if it is not installed. This little bug doesn't affect the module's functionality though.The upcoming version won't have this requirement for package.json file, to support customized library folders as well: #3213068: package.json shouldn't be required
Comment #8
pick_d commented@osman
Updated. Everything is fine, thanks.
Also thanks for explanation about status page, now it all makes sense :-)