Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Configuration manager single import must utilize configuration dependency manager from #2030073: Config cannot be imported in order for dependencies
How to reproduce
- Install Drupal 8 using
Standard
profile - Enable
Configuration manager
module - Import the following configuration:
uuid: e7129925-c8d9-4b8a-8700-a2203431c810 langcode: und status: true dependencies: entity: - field.storage.node.field_image - node.type.article2 id: node.article2.field_image field_name: field_image entity_type: node bundle: article2 label: Image description: '' required: false translatable: true default_value: { } default_value_function: '' settings: file_directory: field/image file_extensions: 'png gif jpg jpeg' max_filesize: '' max_resolution: '' min_resolution: '' alt_field: true title_field: false alt_field_required: false title_field_required: false default_image: fid: null alt: '' title: '' width: null height: null handler: default third_party_settings: { } field_type: image
- Fatal error will be displayed, as
article2
content type is not available
Proposed resolution
Implement dependency checks before the actual import execution
Comment | File | Size | Author |
---|---|---|---|
#45 | drupal-single_configuration_import_dependency_check-2224571-45.patch | 19.06 KB | mgifford |
#35 | interdiff.35.txt | 1.33 KB | Taran2L |
#35 | drupal-single_configuration_import_dependency_check-2224571-35.patch | 19.64 KB | Taran2L |
Comments
Comment #1
Taran2LComment #2
Taran2LFirst patch version attached.
Comment #3
Taran2LComment #5
Taran2LShould work on PHP 5.4 now.
Comment #6
Taran2LComment #8
Taran2LPassing tests
Comment #9
Taran2LProbably some new tests are required
Comment #10
alexpottHow about a getEntityByConfigName($name) that just returns the loaded config entity? I'm not a huge fan of functions the return an array
Comment #11
Taran2LChanges from the last commit:
Comment #12
Taran2LComment #14
Taran2LReroll
Comment #15
Taran2LComment #16
XanoThese are mostly nitpicks about code style and documentation. The actual code looks pretty good!
Instead of using entity_load() (which prevents unit testing), use $this->entityManager->getStorageController()->load(). This is an injected dependency and can therefore be mocked in PHPUnit tests.
Debugging code?
Checks if modules exist. This is probably easier to understand, and does not contain the grammatical error.
@param string[]
to indicate this is an array of strings.Checks if themes exist. This is probably easier to understand, and does not contain the grammatical error.
@param string[]
Checks if configuration entities exist. This is probably easier to understand, and does not contain the grammatical error.
@param string[]
...if the entity...
...the existence...
@param array[]
to indicate this is an array of arrays. Please also extend the description with the structure of the child arrays.Our UI text standards stipulate that we do not say please, because we are not requesting users to do anything. Instead, we are simply telling them what happened and must be done to solve the problem.
Comment #17
Taran2LIssues 2-14 have been fixed. New patch attached. Working on UnitTests.
Comment #18
XanoIs there a reason why you are not returning the return value of
$this->validateConfigEntityDependentModulesExistence()
directly?Good! :)
Comment #19
Taran2LI'm not sure it will work here. But the main reason is performance, my code fails as soon as at least one missing dependency was found, because there is no reason to run checks further.
Comment #20
Taran2LAdded unit tests for introduced ConfigManager methods.
Comment #21
XanoAdding tag.
Comment #22
XanoThis can be made simpler and faster by simply returning
$this->validateConfigEntityDependentModulesExistence() && $this->validateConfigEntityDependentThemesExistence() && $this->validateConfigEntityDependentEntitiesExistence()
. The fact that you added a separate method per dependency type is very good, and you should keep this :)Comment #23
Taran2LChanges from the last past:
Comment #25
Xano23: drupal-single_configuration_import_dependency_check-2224571-23.patch queued for re-testing.
Comment #27
Taran2LReroll
Comment #28
Taran2LRe-roll #2
Comment #29
Taran2LRe-roll #3
Comment #30
Taran2LComment #32
Taran2LFixed circular dependency between ThemeHandler and ConfigManager.
Comment #33
Taran2LComment #34
chx CreditAttribution: chx commentedThanks much for working on this! A couple small things:
Surely there's a handy array_diff or array_intersection that can do this without a userspace loop (sorry, 2am, can't think clearly which one)? There aren't enough themes usually that it'd be worth the eager return the userspace loop provides.
Why not just if (!$this->getEntityByConfigName($config_name)) , why the separate variable, it's not needed as far as i can see. Same pattern as validateConfigEntityDependentModulesExistence.
By the way, both validateConfigEntityDependentModulesExistence and can be converted into the following pattern:
if all them exist then $result will remain TRUE (-ish) and $names will become empty and thus terminate the loop; the first time one doesn't exist $result is FALSE and the loop is immediately terminated. But that's perhaps a bit too dense :) ask the people around you at DrupalCon what they think :)
Comment #35
Taran2Larray_diff does the thing, thanks
Fixed
I have showed this to couple guys. Most of them doesn't like it, because it's probably not so straightforward.
Comment #36
pwolanin CreditAttribution: pwolanin commentedThis is basically why the single import is problematic.
I'm concerned that we are adding a dependency on the module handler here - can we have separate validation code?
Comment #37
BerdirDid not check the patch yet, but we have the same problem for default configuration, we don't validate those either. Does this already fix it and if not, can we fix that here as well?
Comment #38
Taran2LWe can remove dependency on ModuleHandler and use it directly from the container.
Could you provide more details on this? I'm not sure I'm aware where to look in order to reproduce/check? Thanks
Comment #39
BerdirAs an example, add a entity_view_display entity for a non-existing view mode as default configuration to a module. Then try to install that module => fatal error (that doesn't tell you what is broken and why). We should instead throw an exception or something that includes the config and which dependency is missing.
Comment #40
jhodgdonThis is a problem in the config manager module, right?
Comment #42
mgiffordComment #44
alexpottWe just need to ensure that all the validators we implement #1842956: [Meta] Implement event listeners to validate imports are run - especially #2416109: Validate configuration dependencies before importing configuration
Comment #45
mgiffordReroll.
Comment #47
alexpottThis is a duplicate of #2486467: Single config import form needs to use the config validation events - which has a different approach but the same outcome.
Comment #48
alexpott@Taran2L can you comment on #2486467: Single config import form needs to use the config validation events so that we can give you credit for the work done on this issue?
Comment #49
Taran2LSeems like it's too late :)