Problem/Motivation

I have this error

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getFileUri() on null in store_locator_entity_view_alter() (line 56 of modules/contrib/gmap_store_locator/store_locator.module).
store_locator_entity_view_alter(Array, Object, Object) (Line: 562)
Drupal\Core\Extension\ModuleHandler->alter('store_locator_view', Array, Object, Object) (Line: 305)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
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: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->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: 130)
Drupal\cdn\StackMiddleware\DuplicateContentPreventionMiddleware->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: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

create a store.
view store page.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

trickfun created an issue. See original summary.

guilherme-lima-almeida’s picture

StatusFileSize
new903 bytes

Hi, there @trickfun,

The problem is the verification on line 54 in the file store_locator.module, even if you didn't add a new marker, the $fid returns an empty string, and the is_null only finds whether a variable is null. To solve this I replaced the

!is_null

with

!empty

.

Also, I change the

file_create_url()

function with

\Drupal::service('file_url_generator')->generateAbsoluteString()

, since that function is deprecated (https://www.drupal.org/node/2940031).

geoanders’s picture

Status: Active » Needs review
guilherme-lima-almeida’s picture

Hi, there @geoanders,

I reverted the change I made in the

\Drupal::service('file_url_generator')->generateAbsoluteString($file_entity->getFileUri())

since the service file_url_generator is only available in Drupal 9.3.X.

guilherme-lima-almeida’s picture

StatusFileSize
new621 bytes

Update patch.

guilherme-lima-almeida’s picture

Status: Needs review » Reviewed & tested by the community
geoanders’s picture

Status: Reviewed & tested by the community » Fixed

Now merged. Thanks!

Status: Fixed » Closed (fixed)

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