Error: Call to a member function getDatasources()

Created on 7 June 2024, over 1 year ago
Updated 24 August 2024, about 1 year ago

Problem/Motivation

There is a fatal error with the following message:

Error: Call to a member function getDatasources() on null in Drupal\leaflet_views\Plugin\views\style\LeafletMap->init() (line 297 of web/modules/contrib/leaflet/modules/leaflet_views/src/Plugin/views/style/LeafletMap.php).

and stack trace

#0 web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(824): Drupal\leaflet_views\Plugin\views\style\LeafletMap->init(Object(Drupal\views\ViewExecutable), Object(Drupal\views\Plugin\views\display\Page), Array)
#1 web/core/modules/views/src/ViewExecutable.php(897): Drupal\views\Plugin\views\display\DisplayPluginBase->getPlugin('style')
#2 web/core/modules/views/src/ViewExecutable.php(877): Drupal\views\ViewExecutable->initStyle()
#3 web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(476): Drupal\views\ViewExecutable->getStyle()
#4 web/modules/contrib/views_database_connector/src/Plugin/views/field/StandardVDC.php(22): Drupal\views\Plugin\views\field\FieldPluginBase->defineOptions()
#5 web/core/modules/views/src/Plugin/views/PluginBase.php(143): Drupal\views_database_connector\Plugin\views\field\StandardVDC->defineOptions()
#6 web/core/modules/views/src/Plugin/views/HandlerBase.php(109): Drupal\views\Plugin\views\PluginBase->init(Object(Drupal\views\ViewExecutable), Object(Drupal\views\Plugin\views\display\Page), Array)
#7 web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(136): Drupal\views\Plugin\views\HandlerBase->init(Object(Drupal\views\ViewExecutable), Object(Drupal\views\Plugin\views\display\Page), Array)
#8 web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(899): Drupal\views\Plugin\views\field\FieldPluginBase->init(Object(Drupal\views\ViewExecutable), Object(Drupal\views\Plugin\views\display\Page), Array)
#9 web/core/modules/views/src/ViewExecutable.php(1055): Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('field')
#10 web/core/modules/views/src/ViewExecutable.php(913): Drupal\views\ViewExecutable->_initHandler('field', Array)
#11 web/modules/custom/sy3_hacks/src/Plugin/Block/VefcBlock.php(93): Drupal\views\ViewExecutable->initHandlers()
#12 web/modules/custom/sy3_hacks/src/Plugin/Block/VefcBlock.php(71): Drupal\sy3_hacks\Plugin\Block\VefcBlock->getBlock('page_12', 'dashboard_view')
#13 web/core/modules/block/src/BlockViewBuilder.php(171): Drupal\sy3_hacks\Plugin\Block\VefcBlock->build()
#14 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array)
#15 web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(111): call_user_func_array('Drupal\\block\\Bl...', Array)
#16 web/core/lib/Drupal/Core/Render/Renderer.php(859): Drupal\Core\Render\Renderer->doTrustedCallback('Drupal\\block\\Bl...', Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#17 web/core/lib/Drupal/Core/Render/Renderer.php(421): Drupal\Core\Render\Renderer->doCallback('#pre_render', 'Drupal\\block\\Bl...', Array)
#18 web/core/lib/Drupal/Core/Render/Renderer.php(493): Drupal\Core\Render\Renderer->doRender(Array)
#19 web/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender(Array, false)
#20 web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#21 web/sites/default/files/php/twig/6662e5ec95032_page.html.twig_QRa7V8GSTc9YqlWXyidtKfdW3/PEr5fTNZxlSRRFAkVieps1Rq8unIDhbmTSBtnEySxyA.php(399): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#22 vendor/twig/twig/src/Template.php(171): __TwigTemplate_789c01d3a9c76fadcebe39955c78daf1___1461188561->block_page_content(Array, Array)
#23 web/sites/default/files/php/twig/6662e5ec95032__default.twig_giomI8i-KRgXXm9qN8kMGljhW/IkEsLCzTbOHZiYmt1a0qIUI4wRCSRl49r241iUBdraU.php(178): Twig\Template->displayBlock('page_content', Array, Array)
#24 vendor/twig/twig/src/Template.php(394): __TwigTemplate_90a266794dd2017228589fa81ef27408->doDisplay(Array, Array)
#25 vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#26 web/sites/default/files/php/twig/6662e5ec95032_page.html.twig_QRa7V8GSTc9YqlWXyidtKfdW3/PEr5fTNZxlSRRFAkVieps1Rq8unIDhbmTSBtnEySxyA.php(253): Twig\Template->display(Array, Array)
#27 vendor/twig/twig/src/Template.php(394): __TwigTemplate_789c01d3a9c76fadcebe39955c78daf1___1461188561->doDisplay(Array, Array)
#28 vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#29 web/sites/default/files/php/twig/6662e5ec95032_page.html.twig_QRa7V8GSTc9YqlWXyidtKfdW3/PEr5fTNZxlSRRFAkVieps1Rq8unIDhbmTSBtnEySxyA.php(143): Twig\Template->display(Array)
#30 vendor/twig/twig/src/Template.php(394): __TwigTemplate_789c01d3a9c76fadcebe39955c78daf1->doDisplay(Array, Array)
#31 vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#32 vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#33 vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#34 web/core/themes/engines/twig/twig.engine(39): Twig\TemplateWrapper->render(Array)
#35 web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('themes/custom/w...', Array)
#36 web/core/lib/Drupal/Core/Render/Renderer.php(480): Drupal\Core\Theme\ThemeManager->render('page', Array)
#37 web/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender(Array, false)
#38 web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#39 web/sites/default/files/php/twig/6662e5ec95032_html.html.twig_VjhwLmO1zf7GJTwXBSFW1NHHS/V3YhnUvHBZp2m5omp7Yu6Blj25NYgsasHhkXocbQyhM.php(89): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#40 vendor/twig/twig/src/Template.php(394): __TwigTemplate_ac8225b436c7f40eba8dcf4852df0f7e->doDisplay(Array, Array)
#41 vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#42 vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#43 vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#44 web/core/themes/engines/twig/twig.engine(39): Twig\TemplateWrapper->render(Array)
#45 web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('themes/custom/w...', Array)
#46 web/core/lib/Drupal/Core/Render/Renderer.php(480): Drupal\Core\Theme\ThemeManager->render('html', Array)
#47 web/core/lib/Drupal/Core/Render/Renderer.php(240): Drupal\Core\Render\Renderer->doRender(Array, false)
#48 web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(158): Drupal\Core\Render\Renderer->render(Array)
#49 web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#50 web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(159): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#51 web/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))
#52 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#53 web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#54 vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#55 vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#56 web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#57 web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#58 web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#59 web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#60 web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#61 web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#62 web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#63 web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#64 web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#65 web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#66 web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#67 web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#68 web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#69 {main}

Proposed resolution

A simple check for value of the variable $index in web/modules/contrib/leaflet/modules/leaflet_views/src/Plugin/views/style/LeafletMap.php on line 297.

💬 Support request
Status

Closed: cannot reproduce

Version

10.2

Component

Code

Created by

🇪🇹Ethiopia tsega

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

Comments & Activities

  • Issue created by @tsega
  • 🇪🇹Ethiopia tsega

    Patch to stop fatal error.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇮🇹Italy itamair

    This issue / report definitely needs some more context info.
    I tried to reproduce this, with a Search API based Leaflet View and I couldn't reproduce any use case where:

    is_null($index) === TRUE

    Bug Issues shouldn't be reported just copy - pasting the error message and its stack trace.

    @tsega could you provide more details on your use case and better explain how to reproduce it and have evidence of the bug you report (on a general basis).

  • Status changed to Closed: cannot reproduce about 1 year ago
  • 🇮🇹Italy itamair

    Closing this for lack of activity and feedback.

  • 🇬🇧United Kingdom ded

    We were also experiencing this issue and had used the patch to correct it. Recently though we have discovered that the patch was causing issues with changing configuration of views based on Search API and using Leaflet.

    Investigating the patch, it was discovered to be invalid PHP syntax.
    foreach (!is_null($index) && $index->getDatasources() as $datasource) {

    If this is split out to be an if statement then it does work and solves the problem and doesn't cause issues with view configuration.

    I'm not sure how to replicate but our debugging shows that the error is thrown when $base_table = 'localgov_geo_field_data' and therefore the $index_id = 'd_data'. This will return null for $index so the error is thrown.

    I am trying to understand if checking for a null $index is the correct way to go where this happens or if there is another approach.

  • 🇮🇹Italy itamair

    Hi @here ...
    could you check, and and review the attache patch, that looks to me the best fixing / defensive code to skip the reported error, in the singular case where $index turns out to be null?

  • 🇬🇧United Kingdom ded

    Hi itamair,

    yes that is good and solves the issue

    • itamair committed 7d825ed5 on 10.3.x
      [#3453183] feat: Error: Call to a member function getDatasources()
      
      By:...
  • 🇮🇹Italy itamair

    thanks all. Committed into 10.3.x branch, will be parto of next Drupal Leaflet release.

Production build 0.71.5 2024