Problem/Motivation
When attempting to translate a field configuration, there's a fatal error:
Drupal\Core\Entity\EntityStorageException: The "user_fields" entity type does not exist. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 756 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
I encountered the bug when attemting to translate a field config of a field on the user entity. The problem seems to be that ConfigSource::getMapper() is using $job_item->getItemType() for both, the creation of a configMapper and to determine the entity type of the config entity that gets translated.
Proposed resolution
Make sure the entity type is determined correctly.
Comments
Comment #2
giancarlosotelo commentedThis is a first step, I am adding test to expose the problem and I am trying to not change too much the code in order to avoid mayor changes.
The problem basically is that the configMapper is trying to get a definition of a 'field_config' that doesn't exist so instead of using the type of the job item we should use the type of the $config_mapper, it is the same with other entities but for field_config changes to the good one.
For the UI in the translation of tmgmt, as suggested by @berdir, I am adding a new option 'Field' that has every 'field_config' of entities and then can be translated.
But now the problem is that the translation is not saved, the same as #2566353: Translation is not saved from Account settings so probably we have to fix that in the other issue.
Comment #5
s_leu commentedI tested the patch on an out dated d8 instance and the field translation worked now. However when i click the "Needs review" link on the translations overview i get the following error:
Fatal error: Call to undefined method Drupal\Component\Utility\Html::escape() in modules/submodules/tmgmt/src/Form/JobItemForm.php on line 97Not sure whether this is due to my out dated d8 or due to the code of TMGMT.
Besides this, the patch looks fine to me.
Comment #6
giancarlosotelo commentedIt is related to the core, that function was added recently here #2550945: Add Html::escape() and SafeMarkup::checkPlain was removed so we changed that in #2555045: SafeMarkup::checkPlain is being removed.
Comment #7
miro_dietikerUnsure how qualified my response is here. I'm just trying to understand what we do...
This check still seems a bit odd to me. And thus at least need a comment why field_config have no link... EntityInterface guarantees that we can call link() on all entities. So we should fix this bug elsewhere. Otherwise it's not an entity at all?
Needs a comment about the problem.
Why is this change needed? I would expect that enumerating the entity types is more what we want than enumerating the mappings... (duplicates?)
Comment #8
giancarlosotelo commented1. As far as I understand the problem here is that the entity is 'FieldConfig' and it have a link but we want to list the fields of 'fieldable' entities so this ones don't have a link and there are not entities. Added a comment.
2. Commented.
3. It was suggested by @berdir, there are duplicates for field_config but it was the only way to have 'Field' listed on the UI. Another option could be added this manually (?).
Comment #9
juanse254 commentedTested locally, everything seems to work just fine.
Comment #10
berdirThere is a better way to check this, the existence of a edit-form link template.
You have $entity available here, why so complicated?
Missing docblock.
We're not really asserting much here. Shouldn't we check that the translation was saved correctly?
Same. You don't need to check if the field config was translated in both, one of them is enough.
But this one should at least also have some assertText() for a configuration message. This could end in an exception and you wouldn't notice.
Comment #11
giancarlosotelo commented1. Done.
2. I realized that if we want to request more than 1 translation, each one have a different type so this could lead to an error with this approach (?).
I added a new key to the items array to save the type and then this is used to add the job. I don't know if is the best way because the type doesn't change with other entities.
3. Added.
4,5. Added text to assert in one of the test.
Comment #13
edurenye commentedIt' seems to work correcly, the code it's fine. The test fail are unrelated to this issue.
Comment #16
berdirCommitted.
Comment #18
berdir