Here's the scenario:
- user created a node type 'foo' in the admin UI
- user then installs a module that adds a node type of the same name (eg, forum, image, program, etc...)
- user is baffled that the node type promised by the module documentation doesn't function as expected.
Obviously, node type modules can check for this themselves, but is this something core should take care of?
I'm looking at the code in node module, and a check could be made in _node_types_build() but what action should be taken if the check fails? It's surely too late by now to cancel installation of the new module.
Problem/Motivation
Here's the scenario:
- user created a node type 'foo' in the admin UI
- user then installs a module that adds a node type of the same name (eg, forum, image, program, etc...)
- user is baffled that the node type promised by the module documentation doesn't function as expected.
Proposed resolution
Two solutions have been proposed to solve this problem:
- Prefix "custom_" or "$module_" before machine name of node type.
- Make an implementation of hook_requirements() that detects this condition and throws an error that describes the situation and prevents the installation from proceeding.
Remaining tasks
Some patches have been created to fix the issue but the biggest issue is the path to be taken in order to fix the issue. Some are suggestion prefixing "custom_" before the machine name of the node type. Some patches have been made with this in mind but have not yet been successful. Others feel that it is a issue that is going to occur only rarely and such a major change should not be made for this issue. There should rather be a check to detect this condition and throw an error that would let users become notified that a problem exists and would offer them the option to handle it on their own terms.
Related Issues
#1887654: Creating a config entity with an existing machine name shouldn't work
Comment | File | Size | Author |
---|---|---|---|
#30 | 468976-30-only-test.patch | 4.42 KB | marthinal |
#27 | node-468976-27.patch | 2.32 KB | ward marzouki |
#19 | node-468976-19.patch | 2.54 KB | ryan.gibson |
#19 | interdiff.txt | 1.29 KB | ryan.gibson |
#18 | node-468976-18.patch | 3.58 KB | tim.plunkett |
Comments
Comment #1
sunsubscribing
Wow. That's really hard to tackle.
Comment #2
joachim CreditAttribution: joachim commentedMaybe this should be done just before or after hook_requirements is called on a module: call the module's hook_(define node types can't remember its name) and check against the database for those node type names and if found, act as if hook_requirements failed.
Or provide a stock check_my_type_doesnt_exist function that custom modules should call in hook_requirements if they define types, but then that's not as nice DX.
Argh, except drupal_check_module() only loads the module's .install, not its .module.
Comment #3
Leeteq CreditAttribution: Leeteq commentedCore should check prior to starting the installation process, and abort the installatin (in time...) with a message if there is such a conflict.
Comment #4
Leeteq CreditAttribution: Leeteq commentedHow is this handled in D7?
Comment #5
amateescu CreditAttribution: amateescu commentedI was able to reproduce this in 7.x, moving to 8.x to be fixed in there first.
Comment #6
sunI don't think there's any possible solution for D7- for this.
However, we need to make sure that the new entity and bundle system in D8 properly accounts for this.
E.g., all custom/user-defined bundles could get an enforced prefix of
'custom_'
- or alternatively, all module-defined bundles could be enforced to have a prefix of"$module_"
- not pretty, but a workaround/solution.Comment #7
Everett Zufelt CreditAttribution: Everett Zufelt commentedI've never run into this, but always prefix $module_ to node types I create. mymodule_foo. Again, this isn't necessarily pretty, and does sometimes cause naming issues, as I like to prefix node type name to field names, leaving field_mymodule_foo_bar as a field name, which often gets up near / over the 32 char limit on field machine names.
Comment #8
Alan D. CreditAttribution: Alan D. commentedWouldn't a simple check / override in _node_types_build() be enough. It would set the module name and any overridden properties. So module overrides / updates User type and module with higher system weight wins if both define the same type.
Comment #9
catchTagging.
Comment #10
rkjha CreditAttribution: rkjha commentedComment #11
tim.plunkettHere's a test following the steps described in #10.
Comment #13
ryan.gibson CreditAttribution: ryan.gibson commentedGoing off of sun's idea in #6. Adding "custom_" prefix before machine name of node type.
Comment #14
ryan.gibson CreditAttribution: ryan.gibson commentedComment #15
ryan.gibson CreditAttribution: ryan.gibson commentedagain, combined with Tim's test.
Comment #16
tim.plunkettTwo problems with my test:
Of course, this all assumes this is how we want to solve this problem, which I'm not convinced of :)
Comment #18
tim.plunkettThe 'custom_' prefix was getting added on every time the content type page was saved, it should only happen on creation.
Comment #19
ryan.gibson CreditAttribution: ryan.gibson commentedThis was still happening in the UI when editing. tim.plunkett fixed it in this patch.
Comment #21
gddIt seems from a functional perspective that a better option would be to detect this condition and throw an error of some sort that describes the situation and prevents the installation from happening at all. timplunkett suggested this might have to happen in hook_requirements() but I'd rather see the user a) notified that a problem exists and b) offered the option to handle it on their own terms. The automated addition of 'custom_' to the machine name seems pretty hack to me for a situation that is mostly likely pretty damn rare.
Comment #22
sunClosely related problem space: #1887654: Creating a config entity with an existing machine name shouldn't work
Comment #22.0
rkjha CreditAttribution: rkjha commentedEdited Issue Summary
Comment #22.1
heddnUpdated issue summary.
Comment #23
star-szrTagging for reroll.
Comment #24
Rajesh Ashok CreditAttribution: Rajesh Ashok commentedThe last patch #19, failed testing. Should we reroll this patch ?
Comment #25
Salah Messaoud CreditAttribution: Salah Messaoud commentedStarted work
Comment #26
ward marzouki CreditAttribution: ward marzouki commentedsalah has assigned this to me
Comment #27
ward marzouki CreditAttribution: ward marzouki commentedI have rerolled the patch against HEAD
Please note that this patch was a year old, and there has been many changes to HEAD since then. The biggest change is that this patch made changes to a file that no longer exist below is the merge message.
"deleted by them: core/modules/node/content_types.inc"
Comment #28
joachim CreditAttribution: joachim commentedThe patch at 27 only contains the tests, it doesn't have the changes to actual code.
To fix this, you need to figure out where the code that used to be in core/modules/node/content_types.inc has been moved to. The changes in the patch #19 to core/modules/node/content_types.inc need to be applied manually to this new file, once you find it.
Comment #30
marthinal CreditAttribution: marthinal commentedThis test should fail. I don't know if this is the best way to make it fails... other possibilities are welcome :)
I prefer to fix the problem with a message to the user where we communicate the reason and ... then to offer the possibility to change the machine name from the current type active not altering the name of the node type by default in the contrib module.
As I can see hook_requirements invoke all the hooks only at the update phase ... So, where is the best place to do this? Here I am.
Comment #32
Keith Eldridge CreditAttribution: Keith Eldridge commented30: 468976-30-only-test.patch queued for re-testing.
Comment #34
Keith Eldridge CreditAttribution: Keith Eldridge commentedThe patch applied cleanly but failed the test.
Comment #35
alexpottThis is a special case of #2140511: Configuration file name collisions silently ignored for default configuration
Comment #36
alimac CreditAttribution: alimac commentedMinor tag cleanup - please ignore.
Comment #37
alexpott#2140511: Configuration file name collisions silently ignored for default configuration is fixed and now if you do try to install a module that provides configuration that matches something that is in the active storage you get an exception before the module is installed.
Comment #38
DamienMcKennaRemoved the "Needs reroll" tag.