Problem/Motivation

I was using power portfolio for my website for a while without an issue; the theme worked perfectly. Unfortunately, this week I attempted to open my localhost site to make additional edits only to find an error stating, "The website encountered an unexpected error. Please try again later." After adding a configure command to the settings.php file in order to see what the error actually was, the following issue was displayed:

Error: Call to a member function getFileUri() on null in power_portfolio_preprocess_page() (line 228 of themes\contrib\power_portfolio\power_portfolio.theme).
call_user_func_array('power_portfolio_preprocess_page', Array) (Line: 285)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 474)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 80)
__TwigTemplate_753c57db3e8c904ced952d31e6792e07->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)
twig_render_template('core/modules/system/templates/html.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 153)
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(Object, 'kernel.view') (Line: 171)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I have attempted to update, uninstall and reinstall, adjust theme files as depicted in various Drupal forum posts on the matter. None of these solutions worked. Would you have any idea what the issue may be and how to fix it?

Proposed resolution

perform null check for file object

CommentFileSizeAuthor
#2 power_portfolio-3381974-1.patch954 bytesmohd sahzad
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

Dimafirsov created an issue. See original summary.

mohd sahzad’s picture

StatusFileSize
new954 bytes

I have created patch for this issue getFileUri() Error

keshavv’s picture

Status: Active » Needs work

@Mohd Sahzad In the patch, There is no need to add multiple conditions. if (!empty($file) && $file != NULL && !is_null($file->getFileUri())) {
Just add if ($file) {. It will work.

Can you please recreate it?

akshay.singh made their first commit to this issue’s fork.

akshay.singh’s picture

Title: getFileUri() Error » Call to a member function getFileUri() on null
Version: 9.0.2 » 9.0.x-dev
Assigned: Dimafirsov » Unassigned
Issue summary: View changes

akshay.singh’s picture

Status: Needs work » Needs review

I have tried to simplify the logic and keeping in mind the error and created an MR for same.

please review.

Thanks

apermuy’s picture

Patch #2 works fine in Drupal 10.2.2 PHP 8.1.27 a Power Portfolio 9.0.2. Thanks!

urbanlegend’s picture

Confirming, patch #2 works fine with D10.2.5 and php 8.3.6 for v9.0.2 Power Portfolio.

ashutosh ahirwal’s picture

Assigned: Unassigned » ashutosh ahirwal

This will be fix in upcoming version.