Problem/Motivation
Stemming from followup comments: https://www.drupal.org/project/custom_field/issues/3496669#comment-15925128
There's a use case where user could create a translation in other language before and independent of default site language entity existing. The subfields should always be visible in this case as this translation will be considered the default.
Proposed resolution
Our logic for the $entity variable is incorrect as we need to load the translation from the current language and use the $entity->isDefaultTranslation(). Additionally, as recommended in the related issue, we need to also evaluate access on if the $entity->isNew().
Issue fork custom_field-3497244
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
apmsooner commentedPlease test patch.
Comment #4
jurgenhaasThis is looking pretty good, but there is 1 part that I found that still needs a change.
Checking for
$entity instanceof TranslatableInterfaceisn't what you expect. This is because all content entities are an instance ofContentEntityInterfacewhich extendsTranslatableRevisionableInterfacewhich extendsTranslatableInterface. In other words: every content entity is an instance ofTranslatableInterface.What you really want to check is
$entity->isTranslatable(). This gives you the real information whether the current entity is translatable. If it's not, you can skip all the translation logic.It seems that this is not only within the scope of the current MR. You most likely need to replace
$entity instanceof TranslatableInterfacewith$entity->isTranslatable()in the whole code base.Comment #5
apmsooner commentedThanks for catching that. I've made revisions and ready to review again. Noted other places in the codebase will need similar revisions and those places should be limited to the formatter logic which I'm in the process of refactoring/simplifying logic as part of https://www.drupal.org/project/custom_field/issues/3496708. Mainly the BaseFormatter.php file handles some logic for entity references so I will take care of it there in that ticket so we can keep the scope of this ticket limited.
Comment #6
jurgenhaasThis is looking good for the use cases I've tested before and again after the last commit. Not sure, if this now covers everything, though. It's certainly a complex topic.
Not sure what else is going on in the other issue, I haven't had time to look into that as well. It's just important to note, that
$entity instanceof TranslatableInterfacealways returns TRUE - and that's most likely not what's expected.Comment #8
apmsooner commentedThanks for all the due diligence in this review!
As for the other issue, i'm adding some optional html wrapper logic for the formatters similar to the fences module. In starting that feature, I realized the existing formatter logic was over complicating things and needed to be more like core with the way the plugins get instantiated so I'm simplifying/standardizing the apis on those for cleaner and reduced code.
Comment #9
apmsooner commentedComment #10
apmsooner commented