In #1928082: Make usage of book.settings:allowed_types consistent (http://drupal.org/node/1928082#comment-7128904) @sun points out that the duplicate key/value in book.settings:allowed_types kind of sucks. That patch made the following change.
allowed_types:
- - book
+ book: book
In trying to resolve this issue I realised we actually have a much more important issue. book_node_type_update()
keeps book.settings in sync with node type changes. At the moment if you have two content types with machine names book
and page
as allowed types and then you change the book
machine name to album
the book_node_type_update()
function will update book.settings:allowed_types to:
page: page
album: album
If you were then to go to admin/content/book/settings and press the save button without making any changes to the form book.settings:allowed_types will be updated to:
album: album
page: page
This means you will end up with unexpected config changes which is a bad thing(tm).
Comment | File | Size | Author |
---|---|---|---|
#15 | 10-15-interdiff.txt | 2.4 KB | alexpott |
#15 | 1933548.book-settings.15.patch | 9.94 KB | alexpott |
#10 | 9-10-interdiff.txt | 640 bytes | alexpott |
#10 | 1933548.book-settings.10.patch | 9.84 KB | alexpott |
#6 | 5-6-interdiff.txt | 24.4 KB | alexpott |
Comments
Comment #1
alexpottThe patch attached fixes this by changing allowed_types to a numerically keyed array eg.
I've added lots of tests to fully test the
book_node_type_update()
function.Comment #2
alexpottComment #3
sunStale comment, should be moved up above the new line where unchecked types are removed now.
The corresponding added test explains this some more, but we should actually clarify why this is done in the functional code, too. Actually, a proper explanation in the functional code is much more important.
In general:
Instead of explaining what the technical code lines are doing à la:
"sort and save values so they appear in the 'correct' order."
Always document the actual whats and whys:
"Ensure that the existing order of enabled book types remains to be identical, (because... | in order to ...)"
Alas, what I'm currently missing is the "why?" — why are we doing this? :)
Comment #4
alexpottThe why is because: when you change node type's machine name, book.settings.yml will change. Maybe you import this configuration into another site. Whatever... you do some action that means are an expected fixed point in terms of the state of your configuration eg. check it into git.
Then someone goes to admin/content/book/settings changes nothings and presses "Save configuration" and hey presto you configuration has changed because the order of the allowed_types array has changed.
Which is wrong.
Every time we save the book.settings:allowed_types config key we need to ensure that the ordering is consistent that means we need to sort it. We have two places in the code where we save it at the moment and they are inconsistent when they should be.
At the moment the admin form saves in the order that's returned by node_type_get_names() which is in the order of the human readable value.
In
book_node_type_update()
we only have the machine names in this array and sorting here by human readable value only leads to more complexity.Comment #5
alexpottHere's a patch that addresses - @sun thanks for the review!
Realised that I'd forgotten about the upgrade path too...
Comment #6
alexpottMinor code style fix
EDIT: ignore rebase issue... intended patch is in #9
Comment #7
YesCT CreditAttribution: YesCT commentedis this unrelated changes? it's reminding me of #1929136: Fix override-free context, move global config overrides back to an event listener
I think a newline at the end of the class is usual.
unintended change I think.
missing period to end the sentence.
This was just a quick review. I didn't read it really carefully.
Note, this will need a re-roll when the follow-up for #1763640: Introduce config context to make original config and different overrides accessible gets in.
Comment #8
alexpott:( patch mess... rerolling...
Comment #9
alexpottHmmn forgot to rebase... doh!
Comment #10
alexpottOn talking with @sun an improvement in code comments...
Comment #11
sunThanks! :)
Comment #12
webchickSorry, this is not applying for me...
Comment #13
YesCT CreditAttribution: YesCT commentedadding tag for reroll (also a help document on rerolls: http://drupal.org/patch/reroll)
Comment #14
webchickThanks! I was trying to remember that tag.
Comment #15
alexpottRerolled due to changes introduced by #1925196: Convert book's system_config_form() to SystemConfigFormBase
When this is green we should be back to rtbc.
Comment #16
alexpottComment #17
sunIn the hope it comes back green.
Comment #18
webchickCommitted and pushed to 8.x. Thanks!
Comment #19.0
(not verified) CreditAttribution: commentedTidying up the english...