Follow-up to #2649752: Add categorization to config translation mappers
Problem/Motivation
ConfigEntityMapper provides additional methods on top of ConfigNamesMapper that do not have an interface.
The interface and its methods are needed for use-cases where we need to dynamically enhance mappers (once #2577761: We need a way to dynamically alter the list of config names for config mappers is in), for example #2546212: Entity view/form mode formatter/widget settings have no translation UI.
Proposed resolution
Create interface for ConfigEntityMapper
so we can code against contracts.
Remaining tasks
Commit.
User interface changes
None.
API changes
API addition. No breaks for classes extending ConfigEntityMapper (or not doing so). The following interface is added:
interface ConfigEntityMapperInterface {
public function getEntity();
public function setEntity(ConfigEntityInterface $entity);
public function setType($entity_type);
public function getType();
}
Data model changes
None.
Comment | File | Size | Author |
---|
Issue fork drupal-2653652
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 #2
Daniel_Rempe CreditAttribution: Daniel_Rempe commentedPatch proposal
Comment #3
tstoecklerThanks a lot, looks great.
ConfigEntityMapper is in fact not used anywhere else in the code, so this is sufficient. ConfigFieldMapper does not provide any methods at the moment, so it does not make sense to add an interface for it.
Updating title and issue summary accordingly.
Comment #4
Gábor HojtsyUpdated issue summary.
Comment #5
catchI'm not convinced this is a good use case for an interface - it's used only by config_translation module internally, and extended by NodeTypeMapper. Just looks like a base class to me.
If we add an interface, then realise we need to add another method to ConfigEntityMapper, then we'd not be able to without adding an additional interface.
On top of that, I didn't look exhaustively, but the only place I can see actually using this class is config_translation_config_translation_info(), which doesn't call any of the methods in the interface.
This suggests to me that the methods should have been protected in the first place, and are only public by accident.
We might decide we can't make them protected during 8.x (or we could decide this class is internal and should never be used directly), but we could add a note that they'll be made protected in 9.x even if we can't do that.
Uploading a patch that just makes them protected to see if that assumption is right. The unit tests will break but if everything else passes we need to rethink this a bit.
Comment #8
Gábor Hojtsy@catch: I believe we use the methods in listings to populate mappers. I am not 100% sure how to read the fails if they appear due to the test only or due to the page being tested, but it is clearly not only unit tests.
Comment #9
maxocub CreditAttribution: maxocub commentedI think the fail in ConfigTranslationOverviewTest() is due to the fact that getType() is called in ConfigTranslationListController.php (line 65)
Comment #10
Gábor HojtsySo looks like we either need that or some equivalent to make the logic still work.
Comment #11
tstoecklerWe need this interface for #2546212: Entity view/form mode formatter/widget settings have no translation UI, for example, to be able to introspect for which entity a mapper is for. Currently the latest patch does a
instanceof ConfigEntityMapper
in order to to a->getEntity()
. It would be nice to instead have an interface for that.Re-uploading #2 but for some minor fixes (see interdiff). To me this is still RTBC but would like some confirmation that this is the way to go.
Comment #13
Kristen PolI reviewed the code and didn't see anything obviously wrong with the syntax or logic though I don't have an opinion on whether or not this is the "right" way to go (adding the interface).
I am wondering the best way to test this via the UI.
Comment #14
penyaskito#11 updated the issue summary with the purpose of this responding to #5, so removing the Needs summary update tag.
Interface looks good to me, and this is a good improvement not only for unblocking core issues but for some special contrib cases (e.g. Lingotek module).
I'm wondering if we need the same for ConfigFieldMapper, but that could be a different issue. RTBCing this.
Comment #16
penyaskitoRerolled.
Changed @return docblock per phpcs complaint. Changed docblock in the setEntity() method in the interface as it changed in the class since last patch.
Comment #17
tstoecklerSorry, found one nitpick.
This change is actually wrong.
Comment #18
tstoecklerHere we go.
@penyaskito maybe it would be OK for you to RTBC even though you worked on this, because both of our changes are very minimal?
Comment #19
maxocub CreditAttribution: maxocub commented+1 for this
Comment #21
penyaskitoThat failure is unrelated, maybe a broken HEAD?
Comment #22
tstoecklerComment #24
tstoecklerComment #25
alexpottWhat is weird about this object is the entity type and entity can get out-of-sync
entity type ID
entity type ID
Let's make this comply we coding standards and say that it returns the entity type ID.
Comment #41
vasikethis looks (almost) done ... but it was abandoned
Created a MR
- From previous commits - but keep the existing comments
- + updates for #25 suggestions
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedLeft some small nitpicks
Can we get a change record written for the new interface?
Comment #43
vasikeUpdates
- new change record draft https://www.drupal.org/node/3366740
Not sure what details/info should i put there.
- Update the MR
Add typehints.
Use interface for instanceof instead of class.
@smustgrave could you, please, check all these?
thanks
Comment #44
smustgrave CreditAttribution: smustgrave at Mobomo commentedChange record and typehint changes look good to me.
Comment #46
longwaveCommitted and pushed 49e0f8b6a4 to 11.x. Thanks!
Also published the change record.
Comment #47
penyaskitoFinally! Thanks everyone! :party: