Updated: Comment 0
Problem/Motivation
menu.module contains a number of calls to variable_get, which will not be supported in Drupal 8.
core/modules/menu/menu.module
278 $type_menus = variable_get('menu_options_' . $type, array('main' => 'main'));
411 $menu_name = strtok(variable_get('menu_parent_' . $node->getType(), 'main:0'), ':');
416 $type_menus = variable_get('menu_options_' . $node->getType(), array('main' => 'main'));
534 $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : variable_get('menu_parent_' . $type, 'main:0'));
600 '#default_value' => variable_get('menu_options_' . $type->id(), array('main')),
613 '#default_value' => variable_get('menu_parent_' . $type->id(), 'main:0'),
Proposed resolution
Convert all calls to use CMI
Remaining tasks
User interface changes
API changes
Related Issues
This is a child of #1775842: [meta] Convert all variables to state and/or config systems
Some variables have already been converted in #1829308: Convert variables in menu.inc to config and state
menu_default_active_menus has been moved to #2106097: Finish converting menu_default_active_menus to CMI
Comment | File | Size | Author |
---|---|---|---|
#44 | 2102521-44-menu-module-variables.patch | 9.62 KB | ianthomas_uk |
#35 | 2102521-31-35-interdiff.txt | 734 bytes | ianthomas_uk |
#35 | menu-2102521-35.patch | 9.62 KB | ianthomas_uk |
#31 | 2102521-23-31-interdiff.txt | 1.9 KB | ianthomas_uk |
#31 | menu-2102521-31.patch | 9.77 KB | ianthomas_uk |
Comments
Comment #1
catchThese all look like node type-specific variables. Might be worth checking if there's another issue dealing with the node type variables that touched these.
Comment #2
ianthomas_ukSimilar issues seem to be #1739928: Generalize language configuration on content types to apply to terms and other entities and #111715: Convert node/content types into configuration although both relate to other node type-specific variables and have large, committed patches.
node_type_language_default_.$node_type became language.settings.node.$node_type.language.default_configuration
node_submitted_$node_type became node.type.$node_type.settings.node.submitted
Should menu_options_$node_type become node.type.$node_type.settings.menu.options?
UI (at least in 7.x) is at /admin/structure/types/manage/$node_type, menu settings vertical tab.
Comment #3
ianthomas_ukCatch was right, there is a related issue open: #2026165: Finish node type settings conversion
Which refers to: #1911080: Replace menu node form additions with entity reference field
To summarise, we can either store this information in the node type settings or in the menu settings. The main purpose of the option seems to be to have a manageable-sized menu to select from when editing a node, which would suggest the node settings is the appropriate place. This also matches the UI.
However, [#9111080] proposes that it should be possible to add any entity type to a menu, which would suggest either storing on the entity (where?) or the menu. I think this just raises a whole load of questions, so for now I'm going to work on a patch that stores them on the node type.
Comment #4
ianthomas_ukOK, here goes.
I've decided to store under menu using both the entity type (currently hard coded to null) and content type/bundle in the config key. This brings the form handling code from node.module into menu.module*, which should hopefully make it easier to convert to an entity reference-based implementation at some point in the future, or at least extend to other entity types.
When reviewing, please consider if this data is being stored with the best IDs (menu.entity.$entity_type.$content_type, subkeys available_menus and parent).
* I've not removed the code from node.module yet, but I'd like to deal with that later to avoid distractions.
Comment #6
ianthomas_ukAdd back the default that was missed in #4
Comment #7
ianthomas_ukOops, also spotted that I changed the submit handler name without changing what it was registered as in the form.
Is there a way to cancel the tests on #6?
Comment #9
ianthomas_ukHmm, parent form field id was wrong, not sure how I made that mistake.
Comment #11
ianthomas_ukThere was another variable name that I'd incompletely tidied
and a test that needed to be updated
Comment #12
ianthomas_ukOne final patch from me (subject to reviews and SimpleTest of course). I've changed the name of the submit handler, ensured it is only attached in one place and improved the commenting around the alter hook/submit handler to match the format used in the field_ui module.
I've also removed the code from NodeTypeFormController that was designed to save these variables (and those of the Comment form, which has already been removed).
I've tested the UI of both the Node Type form and the Node form and checked the yml output, and I think it's all correct, so just need a review now please.
Comment #13
andypostLooks mostly good, just minor nitpicks
maybe array_filter() is shorter here?
needs surrounding spaces around dot
seems need manual checking
Comment #14
ianthomas_ukRE #13.3 The code in this function saves all values from $form_state as variables, except those that are already handled by the node type form, and this variable which should not persist. $variables is not used outside of the code that I removed.
Comment #15
ianthomas_ukThis addresses #13.1 and #13.2
Comment #16
ianthomas_ukI had some time to test that a bit more carefully and noticed that the array_filter code caused kept the array keys, so the .yml files look like:
I've added an array_values() around this line to fix that.
Which outputs:
Comment #17
cosmicdreams CreditAttribution: cosmicdreams commentedLooks good to me
Comment #18
ianthomas_ukSpeaking to tim.plunkett in IRC yesterday it sounds like this doesn't follow best practise.
- \Drupal::config() should not take a variable in it's parameter, these should be configuration entities instead
- Defaults should be provided by the configuration system instead of by using :?
Documentation for configuration entities is at https://drupal.org/node/1809494 but I don't understand how they would be used in this scenario. I'll ask tim if he can offer further guidance.
Comment #19
ianthomas_ukI spoke to tim.plunkett on IRC again and he said that I had misunderstood that \Drupal::config() could not accept variables in it's parameter, it's just that I should be confident that the config set I am trying to access exists and therefore has a value.
For this patch, that means inserting default config when a node type is added/removed, or when the menu module is installed (Drupal will clean up all of menu's config when the module is uninstalled). These changes are in the attached patch.
Comment #21
aspilicious CreditAttribution: aspilicious commentedI would put the ->delete on the same line
Comment #22
ianthomas_ukI've had another look into this, most of the test failures are in *UpgradePathTest tests. From speaking to chx I understand these tests are superseded by content migration, so we should just remove the tests rather than spend time fixing them.
The remaining test failure is actually on the 'Add content type' and was spotted in passing by BreadcrumbTest. Should there not be a specific test that we can add/remove content types?
To fix the warning we need to provide a default value for available_menus in menu_form_node_type_form_alter() when creating new content types, but that would mean providing the same defaults in three places (others are menu_node_type_insert and menu_install), which isn't great. Is there a better way these could be provided? They can't be included in a .yml file because we don't know the config keys they will be accessed with.
Comment #22.0
ianthomas_ukmove menu_default_active_menus to 2106097
Comment #23
tim.plunkettYes, we don't need this in a migrate-based world, but that is not here yet and we need this stuff to pass.
Made a couple other fixes.
Comment #24
tim.plunkettComment #26
cosmicdreams CreditAttribution: cosmicdreams commentedLooks like #2084463: Convert contextual links to a plugin system similar to local tasks/actions was committed about 3 hours before this patch and touched on menu system so I'm surprised that you didn't run into issues with this patch. Did you pull before you created the patch?
Comment #27
cosmicdreams CreditAttribution: cosmicdreams commentedThe problem seems to be this line of code from menu.module (line 629)
By reading the menu.schema.yml file I'm a bit confused as to exactly where the problem is. It seems that CMI is smart enough to navigate to specific set of config even if several levels deep in a config structure.
For the sake of argument let's say that get command returns what the yml declares:
This is still not the previous data that was passed along:
Later on in form.inc's
form_type_checkboxes_value
, we expect an array to be passed in so can extend it. Then we do a foreach to loop through the values.The error we get is when that foreach fails. It seems to fail because it doesn't recieve an array to iterate over, the array is deliver to the foreach ultimately because we are sending the right data to form_type_checkboxes_value. (I think)
Comment #28
ianthomas_ukThe error is on the create node type page, so I think that
$node_type_config->get('available_menus')
will return null, even though the schema says it should be an array (if you accept the empty string as a matching the * in menu.schema.yml).I think it would work if we changed
$node_type_config = \Drupal::config('menu.entity.node.' . $type->id());
to
But that means we'd now be setting the default to array('main') in four places - there must be a better way?
Comment #29
xjmComment #30
xjmComment #31
ianthomas_ukNo one has suggested a better fix, so here's a patch that implements #28.
Comment #32
tim.plunkettWhy not just
$config_values = $node_type_config->get();
? I thought that worked.Comment #33
ianthomas_ukYes, I think we could just call ->get().
I quite like the way each half of the if/else is the same though, so if you change one half then it's a prompt for you to change the other half (e.g. if someone adds a third config value, they would notice it wasn't in $config_values whether or not they were editing an existing content type or creating a new content type).
I don't really mind either way though. I can roll a patch tomorrow with that change if you want.
Comment #34
aspilicious CreditAttribution: aspilicious commentedI agree with tim :). Go for the reroll!
Comment #35
ianthomas_ukHere's a patch with that change
Comment #36
aspilicious CreditAttribution: aspilicious commentedReading through the comments and the patch, I think this is finally done :)
Comment #37
catchIsn't this going to run into the default config issue with uuids?
Comment #38
ianthomas_ukDo you mean #2127573: Stop creating node, comment and custom block fields automatically and provide defaults in CMI? If so, yes there is a conflict. That issue is still a bit up in the air though.
Should this be postponed on that, or is it better to get this in and add it to the list of things that need to be converted from hooks to yaml for that issue?
Comment #39
catchHmm that's a good question. I'd lean towards committing this as is and then adding it to that issue, but since Alex Pott has been working on the uuid stuff double checking.
Comment #40
chx CreditAttribution: chx commentedComment #41
ianthomas_uk35: menu-2102521-35.patch queued for re-testing.
Comment #43
ianthomas_uk#2127573: Stop creating node, comment and custom block fields automatically and provide defaults in CMI has now been won't fixed, so #35 should be ready to commit. It needs a re-roll though, so assigning to myself to do that.
Comment #44
ianthomas_ukThe patch didn't apply because the case of a function call had been changed in #2113319: Rename getOriginalID() to getOriginalId() and setOriginalID() to setOriginalId(), so other than the case of one deleted character this is identical to #35, which was RTBC until this issue was postponed on an issue that has since been won't fixed.
Comment #45
aspilicious CreditAttribution: aspilicious commentedrtbc than :)
Comment #46
catchSince this was RTBC for a while already, committing it straight away. Thanks!