Problem/Motivation
The format in the book.settings.yml file initially is:
allowed_types:
- book
block:
navigation:
mode: all pages
child_type: book
After saving the form, looking at the file in sites/default/files/hash... it is:
allowed_types:
book: book
article: '0'
page: '0'
block:
navigation:
mode: 'all pages'
child_type: book
The format of saving the "sequence" is different.
Before it uses - content_type
and after: content_type_allowed: content_type_allowed
or: content_type_not_allowed: 0
Also... the mode string is missing quotes initially.
Proposed resolution
Add quotes around the string that has a space in book.settings.yml
Fix the book config set to only save allowed types, and to match the format of the sequence with the -
Remaining tasks
discuss proposed resolution
implement
User interface changes
No UI changes.
API changes
No API changes.
Steps to reproduce
- clean out a possible previous site: sudo rm -r sites; git checkout sites;
- install site
- open in an editor: core/modules/book/config/book.settings.yml
- enable book module under Extend
- save the book settings form at admin/content/book/settings
- open in an editor the yml file saved under the config hash, for example: sites/default/files/config_NrobAyuHYCIoR5CIio_mXfe6zna5HJ1qO3tsEp1eJ5g/active/book.settings.yml
Original report by @YesCT
Follow up for #1912302-11: Create configuration schemas for book module
Comment | File | Size | Author |
---|---|---|---|
#10 | 8-10-interdiff.txt | 6.04 KB | alexpott |
#10 | 1928082-format-config-book-10.patch | 6.96 KB | alexpott |
#10 | book_bench.php_.txt | 1.29 KB | alexpott |
#8 | 1928082-format-config-book-8.patch | 1.06 KB | vijaycs85 |
#7 | 1928082-format-config-book-6.patch | 6.73 KB | vijaycs85 |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedlook for/near:
config('book.settings') ->set('allowed_types', $form_state['values']['book_allowed_types'])
Comment #2
YesCT CreditAttribution: YesCT commentedhere is a little start, just for the quotes.
Comment #3
alexpottLooks like the default config should look like this:
And use array_filter() here...
Nice catch!
Comment #4
vijaycs85Fixed and added patch. Attached screenshot after this change on schema inspector.
Comment #5
YesCT CreditAttribution: YesCT commentedcan we make this (for example, ...) instead of sample?
Comment #6
vijaycs85Comment #7
vijaycs85Adding "for example"
Comment #8
vijaycs85Updating book.settings.yml to have book: book format for allowed_types. We got to do this because:
1. book_node_type_update() using key to get the type.
2. book_type_is_allowed() checking in_array() to get the type.
To avoid any calculation (array_key() or flip etc), keeping this simple "type: type" format.
Comment #9
vijaycs85Comment #10
alexpottPatch makes the book.settings:allowed_types consistent... as a result it includes:
book_node_type_update()
book_type_is_allowed()
book_node_type_update()
Drupal\system\Tests\Upgrade\SystemUpgradePathTest
to ensure variable book_allowed_types is migrated to the expected format.Performance testing done with book_bench.php.txt (attached) and drush using the command:
which outputs:
Comment #11
Gábor HojtsyGreat changes! I think it is of paramount importance to CMI that the config structure will not change when there are new content types added to the site (but the config itself does not change). The fixed approach to storing the types makes this possible. Now if the config diff shows a change it is due to real changes regarding this configuration. The extra performance improvements are also nice :)
Comment #12
webchickLooks great, and even comes with upgrade tests! Lovely. :)
Committed and pushed to 8.x. Thanks!
Comment #13
sunSorry for chiming in late. I wasn't aware of this issue.
Hm. I'm not happy with this repetition of values. Configuration is supposed to be in a simple, declarative format.
In all config conversions thus far, we've used simple lists/sequences to denote a configured set of enabled option values.
We want to save the selected options with
array_values(array_filter($form_state['values']['yada']))
AFAIK, that simple list format is suitable as #options value when building the settings form.
What probably needs to be changed are other API-level accesses, most likely from
isset()
toin_array()
.Comment #14
YesCT CreditAttribution: YesCT commentedI wonder if there is already an issue to tackle that. If not, we should open one to address the root cause.
Comment #15
alexpottOpened #1933548: Book allowed_types settings repetitive and in under certain conditions can change unexpectedly to address #13 as in trying to solve #13 I discover another closely related issue.