Error: Call to a member function getPluginId() on null

Created on 15 May 2023, over 1 year ago

Problem/Motivation

If variable storing original components for translated layout builder field is null, then following error appears on main content dashboard and site errors out when attempting to download translations.

Error: Call to a member function getPluginId() on null in Drupal\lingotek\Plugin\LingotekFieldProcessor\LingotekLayoutBuilderSTProcessor->store() (line 236 of /app/core-submodule/web/modules/contrib/lingotek/src/Plugin/LingotekFieldProcessor/LingotekLayoutBuilderSTProcessor.php)
#0 /app/core-submodule/web/modules/contrib/lingotek/src/LingotekContentTranslationService.php(1377): Drupal\lingotek\Plugin\LingotekFieldProcessor\LingotekLayoutBuilderSTProcessor->store(Object(Drupal\node\Entity\Node), 'es', Object(Drupal\node\Entity\Node), 'layout_builder_...', Object(Drupal\field\Entity\FieldConfig), Array)

#1 /app/core-submodule/web/modules/contrib/lingotek/src/LingotekContentTranslationService.php(935): Drupal\lingotek\LingotekContentTranslationService->saveTargetData(Object(Drupal\node\Entity\Node), 'es', Array)

#2 /app/core-submodule/web/modules/contrib/lingotek/src/Plugin/LingotekFormComponent/BulkAction/DownloadTranslation.php(121): Drupal\lingotek\LingotekContentTranslationService->downloadDocument(Object(Drupal\node\Entity\Node), 'es_419')

#3 /app/core-submodule/web/modules/contrib/lingotek/src/FormComponent/LingotekFormComponentBulkActionExecutor.php(39): Drupal\lingotek\Plugin\LingotekFormComponent\BulkAction\DownloadTranslation->executeSingle(Object(Drupal\node\Entity\Node), Array, Object(Drupal\lingotek\FormComponent\LingotekFormComponentBulkActionExecutor), Array)

#4 /app/core-submodule/web/core/includes/batch.inc(295): Drupal\lingotek\FormComponent\LingotekFormComponentBulkActionExecutor->doExecuteSingle(Object(Drupal\lingotek\Plugin\LingotekFormComponent\BulkAction\DownloadTranslation), Object(Drupal\node\Entity\Node), Array, Object(Drupal\lingotek\Plugin\LingotekFormComponent\BulkAction\Upload), Array)

#5 /app/core-submodule/web/core/includes/batch.inc(137): _batch_process()

#6 /app/core-submodule/web/core/includes/batch.inc(93): _batch_do()

#7 /app/core-submodule/web/core/modules/system/src/Controller/BatchController.php(55): _batch_page(Object(Symfony\Component\HttpFoundation\Request))

#8 [internal function]: Drupal\system\Controller\BatchController->batchPage(Object(Symfony\Component\HttpFoundation\Request))

#9 /app/core-submodule/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)

#10 /app/core-submodule/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()

#11 /app/core-submodule/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))

#12 /app/core-submodule/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)

#13 /app/core-submodule/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()

#14 /app/core-submodule/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)

#15 /app/core-submodule/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#16 /app/core-submodule/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#17 /app/core-submodule/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#18 /app/core-submodule/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#19 /app/core-submodule/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#20 /app/core-submodule/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#21 /app/core-submodule/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#22 /app/core-submodule/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

#23 /app/core-submodule/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))

#24 {main}

Steps to reproduce

Step 1. Have a node that is waiting to be re-uploaded for translations due to edits made to the node
Step 2. Either click on target dropdown to download translation and be met with site error "The website encountered an unexpected error. Please try again later."
Step 3. Or in "Bulk document management" dropdown section choose to download translation that way and be met with main content dashboard AJAX error

Proposed resolution

Add a conditional for the $originalComponent variable to make sure it's set and not null.
Here's the code I used to fix the issue:

if (isset($originalComponent)) {
  $block_instance = $this->blockManager->createInstance($originalComponent->getPluginId(), $originalComponent->get('configuration'));
}
🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024