I got an error when I wanted to save some config changes in Content language and translation after enabling metatag module.
I only installed the module and then the translations stop working.
This is the error:
The website encountered an unexpected error. Please try again later.
Drupal\Core\Field\FieldException: Attempt to create a base field bundle override of field Metatags without an entity_type in Drupal\Core\Field\Entity\BaseFieldOverride->__construct() (line 101 of core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php).
Drupal\Core\Config\Entity\ConfigEntityStorage->doCreate(Array) (Line: 184)
Drupal\Core\Entity\EntityStorageBase->create(Array) (Line: 67)
Drupal\Core\Field\Entity\BaseFieldOverride::createFromBaseFieldDefinition(Object, 'hotel') (Line: 723)
Drupal\Core\Field\BaseFieldDefinition->getConfig('hotel') (Line: 340)
content_translation_form_language_content_settings_submit(Array, Object)
call_user_func_array('content_translation_form_language_content_settings_submit', Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('language_content_settings_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('language_content_settings_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
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}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Any idea what's going on?
Comments
Comment #2
damienmckennaSomeone contacted me about what might be the same problem. Would you mind testing to see if this fixes the problem? Thanks.
Comment #3
damienmckennaSorry, try this one (I forgot that $entity_type was an object, not a string).
Comment #4
jagundez commentedDamien! It's work! You have no idea so much useful is this for me right now!
Thank you so much!!!
Comment #5
wanjee commentedI have got the same error message without patch applied.
When patch #3 is applied I have got a different error message:
( ! ) Fatal error: Call to a member function getFieldStorageDefinition() on null in /www/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php on line 114
Call Stack
# Time Memory Function Location
1 0.0000 571568 {main}( ) ../index.php:0
2 0.0057 932720 Drupal\Core\DrupalKernel->handle( ) ../index.php:19
3 0.0180 2161368 Stack\StackedHttpKernel->handle( ) ../DrupalKernel.php:656
4 0.0180 2161480 Drupal\Core\StackMiddleware\NegotiationMiddleware->handle( ) ../StackedHttpKernel.php:23
5 0.0180 2161872 Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle( ) ../NegotiationMiddleware.php:50
6 0.0180 2162304 Drupal\page_cache\StackMiddleware\PageCache->handle( ) ../ReverseProxyMiddleware.php:47
7 0.0181 2162824 Drupal\page_cache\StackMiddleware\PageCache->pass( ) ../PageCache.php:78
8 0.0181 2162904 Drupal\Core\StackMiddleware\KernelPreHandle->handle( ) ../PageCache.php:99
9 0.0243 2618168 Drupal\Core\StackMiddleware\Session->handle( ) ../KernelPreHandle.php:47
10 0.0294 2792072 Symfony\Component\HttpKernel\HttpKernel->handle( ) ../Session.php:57
11 0.0295 2792928 Symfony\Component\HttpKernel\HttpKernel->handleRaw( ) ../HttpKernel.php:64
12 0.1011 5244512 call_user_func_array:{/www/vendor/symfony/http-kernel/HttpKernel.php:144} ( ) ../HttpKernel.php:144
13 0.1011 5244712 Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}( ) ../HttpKernel.php:144
14 0.1011 5244960 Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext( ) ../EarlyRenderingControllerWrapperSubscriber.php:97
15 0.1013 5256984 Drupal\Core\Render\Renderer->executeInRenderContext( ) ../EarlyRenderingControllerWrapperSubscriber.php:124
16 0.1013 5257432 Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}( ) ../Renderer.php:574
17 0.1013 5257480 call_user_func_array:{/www/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123} ( ) ../EarlyRenderingControllerWrapperSubscriber.php:123
18 0.1013 5258176 Drupal\Core\Controller\FormController->getContentResult( ) ../EarlyRenderingControllerWrapperSubscriber.php:123
19 0.1044 5680840 Drupal\Core\Form\FormBuilder->buildForm( ) ../FormController.php:74
20 0.4237 25273920 Drupal\Core\Form\FormBuilder->processForm( ) ../FormBuilder.php:314
21 0.7694 32494200 Drupal\Core\Form\FormSubmitter->doSubmitForm( ) ../FormBuilder.php:585
22 0.7694 32494312 Drupal\Core\Form\FormSubmitter->executeSubmitHandlers( ) ../FormSubmitter.php:51
23 3.0694 41421640 call_user_func_array:{/www/core/lib/Drupal/Core/Form/FormSubmitter.php:111} ( ) ../FormSubmitter.php:111
24 3.0694 41425328 content_translation_form_language_content_settings_submit( ) ../FormSubmitter.php:111
25 8.8734 51175872 Drupal\Core\Field\FieldConfigBase->isTranslatable( ) ../content_translation.admin.inc:341
26 8.8734 51175872 Drupal\Core\Field\Entity\BaseFieldOverride->getFieldStorageDefinition( ) ../FieldConfigBase.php:329
Same configuration with metatag module disabled shows no errors.
Comment #7
damienmckennaFYI the patch was from giangi.vigazzola.
Comment #8
damienmckenna@wanjee: What happens if you add this to the top of the function?
.. so that it looks like this:
I'm interested to know what the last entity type recorded is.
Comment #9
wanjee commentedIt loops over types like:
node
user
menu_link_content
file
taxonomy_term
paragraph
crop
search_api_task
With patch applied: it fails after a lot of iterations
Without patch applied: it fails after first iteration of search_api_task
Comment #10
damienmckennaAh. So maybe the code needs to exclude certain entity types, or maybe work out some entity properties that would be required in order for the Metatag functionality to be included?
Comment #11
wanjee commentedYes indeed, paragraphs, crop, search_api_task should probably not have any metatags
Comment #12
damienmckennaDoes this help in any way?
Comment #13
damienmckennaComment #15
damienmckennaRerolled the patch.
Comment #17
wanjee commentedApplied patch #15.
Submission of "Content language and translation" form does not fail anymore.
I however only have a "Metatags" checkbox for taxonomy terms anymore. Is this the expected behavior ?
Thanks !
Comment #18
damienmckenna@wanjee: Where are you seeing that checkbox?
Comment #19
wanjee commentedIn admin/config/regional/content-language form.
I see that a checkbox appears for content types only if I add the "metatag" field to my entity so it's ok, sorry :)
Checkboxes appear however for all vocabularies even with no "metatag" field attached.
Comment #20
samuel.mortenson@DamienMcKenna I'm uploading this patch to try to fix tests - I changed the logic that checks for a URI callback (which is rarely used) to check for a canonical route, which I think is what you wanted to check for. If I'm wrong let me know and I'll jump back in.
Comment #22
samuel.mortensonComment #23
damienmckenna@samuel.mortenson: yeah, that's what I was looking for! Thanks!
@wanjee: Please test out the patch above and let me know if it fixes the problem for you.
Comment #24
Ruedische commentedPatch #20 is working.
Comment #25
damienmckenna@Ruedische: Thanks.
@jagundez / @wanjee: Could you please let me know if the patch in #20 solves the problem for you? Thanks.
Comment #26
jph2eolg8 commentedHello guys,
Thank you for the patch, I've got the error since few days...
Applied the patch #15 2 days ago, and it works (need to test the #20 yet).
Unfortunately, now, in page edition, I've an extra HTML in the title (see file attached).
Am I the only one?
Thank you
Comment #27
edurenye commentedAfter apply the #20 patch I had the same error than #5 and reloading the page, all the translatable fields but metatags where selected properly and the following error appeared at the top of the page:
Comment #28
damienmckennaThat means that the test coverage needs to be expanded.
Anyone have any thoughts on how to make the JSON output still work if metatag_entity_base_field_info_alter() is removed?
Comment #29
niklanHi guys, having the same problem. But none of the patches didn't work for me.
On submit I've got:
After page reload:
I tried to apply patches #3 #15 and #20 separately.
Comment #30
wanjee commented@DamienMcKenna Applied patch #20. It seems getFieldStorageDefinition error is back there
Comment #31
huzookaAdding related issues:
My opinion:
Using an alter hook to introduce a new (base) field is a really-really bad idea. It's for alter existing base fields. For first, let's change the alter hook to a normal base field info.
http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Entity/Entit...
Comment #32
huzookaComment #33
huzookaComment #34
huzookaComment #35
damienmckenna@huzooka: Thanks for taking the time to dig into this. Lets see what the testbot says.
Comment #36
huzooka@DamienMcKenna existing tests are fine.
Could you please help us and describe what kind of test do we need here?
I'd say that a functional test would be enough to cover the scope of this bug (test that the content translation form is usable). What else should be covered (and how)?
Comment #37
edurenye commentedThe #33 patch fixes everything. Thank you!
I think with the functional test that you describe would be enough for this issue, more tests could be in a follow-up.
Comment #38
damienmckennaFor the tests, all I'd really like is a scenario that shows the problem in the current codebase as I still haven't been able to replicate the bug locally.
Comment #39
streger commentedJust another confirm that #33 fixed this issue. Thanks.
Comment #40
huzookaComment #41
huzookaComment #43
huzookaTest doesn't passes CS.
Comment #44
huzookaComment #45
damienmckennaThe test-only patch is *supposed* to fail, that's the point :-)
Comment #46
damienmckennaA slight cleanup of #41.
Comment #48
damienmckennaA test-only version of #46; this should fail.
Comment #50
damienmckennaAs expected the test fails on this:
That means it hits an error saving the configuration, which is expected.
Comment #51
damienmckennaComment #52
alexmoreno commentedI had the same issue, I am using Ligthning distribution, with translations and metatag. Tested #46 and works fine.
Comment #53
alexmoreno commentedComment #54
sarikak commentedThanks
The patch #46 works in d8.3.7.
Comment #55
deepakrmklm commentedPatch could not be applied in Drupal 8.3.7, Meta tag - version: '8.x-1.2'
Comment #56
deepakrmklm commentedUpdated hook comment.
Comment #58
deepakrmklm commentedUpdating patch file path.
Comment #59
edurenye commentedComment #60
vincenzodb commented#58 works for me, thanks
metatag 1.2
Comment #61
edurenye commentedFollowing the standards for the Tests, the name of the class should end with the word 'test' I think, so should be 'EnsureContentTranslationWorksTest' other than that, everything works fine and looks good, so this could be a RTBC.
Comment #62
gagarine commented#58 works for me too on 8.x-1.2.
Comment #63
rene bakxRolled the #58 patch against a production site on the dev-1.x c923b26 version and that works as well.
Setting status to RTBC.
Comment #64
sneo commented#58 work like a charm for me ! Push it ;)
Comment #65
deepakrmklm commentedDear Edurenye,
All the other test files were having the same naming patterns. Could you please confirm that all class names for test need to be renamed in Metatag module? If so, that needs to be handled separately.
Thanks,
Deepak R
Comment #66
edurenye commentedYou are right, all the Functional Tests from Metatag do not have the 'Test' suffix, but in the kernel tests (MetatagManagerTest) have it, and in general in core and other modules is that way. Anyway as you say that would be another issue to rename all the Functional tests and discuss about it or why was done that way, maybe there is another reason I don't know.
So, RTBC+1
Comment #67
mario steinitzJust stumbled across the error with a setup of paragraphs module and metatag (8.x-dev) while enabling translation for several paragraphs fields.
Patch #58 fixed the issue.
Comment #68
deepakrmklm commentedDear Mario Steinitz,
Paragraph fields are not translatable. You may have to translate the entity which you use a paragraph. Seems paragraph module will consider the translation as another entry in the paragraph entity.
"Out of context"
Thanks,
Deepak R
Comment #69
damienmckennaLets try the tests on their own again.
Comment #71
damienmckennaOk, that is as expected.
Comment #73
damienmckennaCommitted. Thanks everyone for your help fixing this!
Comment #74
mario steinitz@deepak_zyxware: The paragraph reference field isn't, but the fields within the paragraphs are. Hence, I was talking about enabling translation for the paragraph entities and their fields, which wasn't possible without above fix.
@DamienMcKenna: Thanks for commiting.
Comment #75
damienmckennaI think there was a misunderstanding about the Paragraph fields. Anyway, thanks for everyone's help getting this fixed.
Comment #76
mario steinitzYes, the fix is very much appreciated. Committed the new metatag version to the current development site, I've been talking about before. Works like a charm.
Comment #77
cobenashThanks for the patch. works like a charm too. :)