Problem/Motivation
When requesting a translation, a fatal error can sometimes occur if the $data array is empty in \Drupal\tmgmt_content\DefaultFieldProcessor::extractTranslatableData() :
public function extractTranslatableData(FieldItemListInterface $field) {
$data = array();
/* ... */
foreach ($field as $delta => $field_item) {
$translatable_properties = 0;
/* ... populates the $data array and increments $translatable_properties any translatable fields are found in the entity... */
// If there is only one translatable property, remove the label for it.
if ($translatable_properties <= 1) {
foreach (Element::children($data[$delta]) as $property_key) {
unset($data[$delta][$property_key]['#label']);
}
}
}
return $data;
}
... this can happen if you have a "wrapper paragraph"; that is to say, a paragraph type whose only field is a reference to other paragraphs (recall the documentation says not to make the paragraph reference field translatable).
node
--field_something
--field_outer_paragraph_reference
----field_inner_paragraph_reference
------field_something
Proposed resolution
Only remove the label for a translatable properly if the $data key is not empty.
Remaining tasks
Write a patch- Review and RTBC
- Maintainer review and commit
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Fixed a fatal error when requesting translations
Original report by abdhomsi
I'm getting a PHP error when requesting a translation:
Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in [PATH]\web\modules\contrib\tmgmt\sources\content\src\DefaultFieldProcessor.php on line 71 in Drupal\Core\Render\Element::children() (line 71 of core\lib\Drupal\Core\Render\Element.php).
Drupal\Core\Render\Element::children(NULL) (Line: 71)
Drupal\tmgmt_content\DefaultFieldProcessor->extractTranslatableData(Object) (Line: 182)
Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->extractTranslatableData(Object) (Line: 100)
Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->getData(Object) (Line: 402)
Drupal\tmgmt\Entity\JobItem->getSourceData() (Line: 1016)
Drupal\tmgmt\Entity\JobItem->recalculateStatistics() (Line: 188)
Drupal\tmgmt\Entity\JobItem->preSave(Object) (Line: 491)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 692)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 446)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase->save() (Line: 342)
Drupal\tmgmt\Entity\Job->addItem('content', 'node', '8') (Line: 136)
Drupal\tmgmt_content\Form\ContentTranslateForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder->processForm('tmgmt_content_translate_form', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('tmgmt_content_translate_form', Object) (Line: 217)
Drupal\Core\Form\FormBuilder->getForm('Drupal\tmgmt_content\Form\ContentTranslateForm', Array) (Line: 19)
Drupal\tmgmt_content\Controller\ContentTranslationControllerOverride->overview(Object, 'node')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3068004-4--request-translation-fatal-error.patch | 950 bytes | mparker17 |
Comments
Comment #2
abdhomsi commentedHere is a quick fix.
Comment #3
berdirComment #4
mparker17I was experiencing this error when exporting a node containing a paragraph type whose only field was a reference to a different paragraph type.
Updated the issue summary with more information. Fixed a typo in the issue title. Re-rolled the patch onto latest commit and added Git metadata; also fixed typo in patch filename.
Comment #5
mparker17Apparently I accidentally introduced my own typo in the issue title. Removing.
Comment #6
mparker17I can also confirm this patch fixes the issue on my site.
Comment #8
berdirThanks.