- Issue created by @dieterholvoet
- Merge request !103Ensures entity has published key before setting status → (Open) created by dieterholvoet
- 🇧🇪Belgium matthiaso Leuven
@dieterholvoet this issue persists after applying the patch.
InvalidArgumentException: Field status is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (regel 616 van /[..]/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Stacktrace:
#0 /[..]/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(597): Drupal\Core\Entity\ContentEntityBase->getTranslatedField('status', 'ti') #1 /[..]/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(657): Drupal\Core\Entity\ContentEntityBase->get('status') #2 /[..]/web/core/lib/Drupal/Core/Entity/EntityPublishedTrait.php(56): Drupal\Core\Entity\ContentEntityBase->set('status', true) #3 /[..]/web/modules/contrib/tmgmt/sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php(599): Drupal\eck\Entity\EckEntity->setPublished() #4 /[..]/web/modules/contrib/tmgmt/sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php(405): Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->doSaveTranslations(Object(Drupal\eck\Entity\EckEntity), Array, 'ti', Object(Drupal\tmgmt\Entity\JobItem)) #5 /[..]/web/modules/contrib/tmgmt/src/Entity/JobItem.php(890): Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->saveTranslation(Object(Drupal\tmgmt\Entity\JobItem), 'ti') #6 /[..]/web/modules/contrib/tmgmt/src/Form/JobItemForm.php(377): Drupal\tmgmt\Entity\JobItem->acceptTranslation() #7 [internal function]: Drupal\tmgmt\Form\JobItemForm->save(Array, Object(Drupal\Core\Form\FormState)) #8 /[..]/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array) #9 /[..]/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #10 /[..]/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #11 /[..]/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('tmgmt_job_item_...', Array, Object(Drupal\Core\Form\FormState)) #12 /[..]/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\tmgmt\Form\JobItemForm), Object(Drupal\Core\Form\FormState)) #13 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #14 /[..]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #15 /[..]/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #16 /[..]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #17 /[..]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #18 /[..]/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #19 /[..]/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #20 /[..]/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /[..]/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /[..]/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /[..]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /[..]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /[..]/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /[..]/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /[..]/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /[..]/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /[..]/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /[..]/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /[..]/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #32 {main}
- 🇨🇭Switzerland berdir Switzerland
That seems like a bug in your custom entity type/with ECK. If you implement EntityPublishedInterface then isPublished() and setPublished() are expected to work.
- 🇧🇪Belgium dieterholvoet Brussels
If you implement EntityPublishedInterface then isPublished() and setPublished() are expected to work.
ECK allows for entity types to optionally enable the published field, but all ECK entities share the same base class.
Drupal\Core\Entity\EntityPublishedTrait::publishedBaseFieldDefinitions()
checks both the presence of the interface and the presence of a published key, so we should probably do the same here. That, together with 🐛 Entity keys should only be added to an entity type if they are enabled Active , would fix this issue. I'll work on getting that fix in ECK first. - 🇨🇭Switzerland berdir Switzerland
IMHO, if an entity implements EntityPublishedInterface then it should deal with that and it shouldn't be necessary to check for an entity key. That could in theory break some cases that chose not to set the entity key and have their own isPublished()/setPublished() implementation.
- 🇧🇪Belgium dieterholvoet Brussels
Yeah, ideally we would generate entity type classes implementing only the necessary interfaces, like the Trash module generates entity storage classes, but as long as that's not completely necessary I'd like to avoid adding that complexity to the ECK module.
I just thought about something. Most getters/setters in
Drupal\eck\Entity\EckEntity
have ahasField()
check for this exact situation, while theisPublished()
/setPublished()
/setUnpublished()
methods don't. I'll fix this issue that way. Thanks for your input berdir. - 🇨🇭Switzerland berdir Switzerland
Yes, also not very fond of what Trash module does.
Just checking seems like a sensible first step. Note that TMGMT will still incorrectly give users he option to chose the publication state as long as it implements that interface, which might be a bit confusing.
Instead of dynamically generating, you could possibly have a few predefined combinations of classes to use, but that can obviously quickly result in a considerable amount of permutations of having a status/owner/created/...
- 🇧🇪Belgium matthiaso Leuven
Using ECK patch 🐛 Field status is unknown Active resolved the error.