Problem/Motivation
Module install updates default user form display like a simple config
//rebuild user entity form display for new fields.
$config = \Drupal::service('config.factory')->getEditable('core.entity_form_display.user.user.default');
// Not sure why this isn't set, but it throws an error in simpletest.
$config->set('targetEntityType', 'user');
$config->set('bundle', 'user');
So that leads to broken user/X/edit form and admin/config/people/accounts/form-display
Fatal error: Call to a member function getName() on null in .../core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php on line 214
Proposed resolution
Use form display API to add fields and enforce dependency on the module for shipped fields
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | user_edit_is_broken-2605086-14.patch | 6.3 KB | andypost |
| #14 | interdiff.txt | 5.01 KB | andypost |
| #13 | password_policy-reinstall_broken-2605086-13-8.x-3.x.patch | 5.78 KB | nerdstein |
Comments
Comment #2
andypostthe error message is
Fatal error: Call to a member function getName() on null in ..../core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php on line 214Comment #3
andypostAlso PR https://github.com/d8-contrib-modules/password_policy/pull/69
Comment #4
nerdsteinComment #5
nerdsteinPer the contrib tracking page:
@andypost - also... the module does not allow reinstall (uninstall and there's no way install again)
My response:
I am guessing this is because the install hook config exists upon reinstall and we're trying to install it again. We can solve within the uninstall hook. And, I am going to explore CMI - because I feel like we're trying to solve CMI related issues. I'll debug.
Comment #6
nerdsteinFor some reason, the configuration "dependencies" being set for password policies' installed user profile fields are not being observed. As such, these fields have not been removed upon uninstall. This causes the aforementioned error where uninstall leaves password policy artifacts and it should not. Because it doesn't properly clean things up, re-installing breaks because the configuration already exists. The previous patch did not address the root of the issue, so I developed a new one that leverages the configuration API.
The guts of the patch is an updated uninstall hook, which removes all of the added and altered config. Why does this need done? I have no idea. I expected "dependencies" defined in the config/install and the "dependencies" in the install hook to be respected when password_policy would be uninstalled. This may suggest another issue with this config (or even core), but the patch seems to work now.
Can someone review?
Comment #7
andypostFinal patch should be combined mine +
password_policy_uninstall()from core's forum moduleshould be fixed
That's totally wrong
Proper way see core's forum module uninstall
forum does the same
Comment #8
andypostAdditions to #3
suppose this should be
entityTypeManager()service nowComment #9
nerdsteinForum's uninstall hook only accounts for field storage. This may be the proper convention for removing the field storage configuration. But, CMI is used to install it. I don't see why this isn't acceptable and more generally applicable even outside of the field storage (as you can see). There is more than one way to skin a cat... I'd rather do it the correct way, I'm just not convinced by one example in core. Are there other examples?
Plus, this approach can't be used for the other config -- adjustments to the the user edit form display and the field settings. This use case seems a bit different from the forum module.
Comment #10
andypost@nerdstein the difference in CMI and EntityAPI - fields and storage are entities that use CMI as storage, the same applies to entity displays - they must be managed with own api. Basically you can swap storage for this entities but install and uninstall will not break
Comment #11
nerdsteinI was able to catch up with @timplunkett (again, thanks for your help).
The following patch addresses the issue. The uninstall hook can go away entirely. The dependencies, as noted previously, were not "enforced". Adding this key tied all of the config to the install/uninstall of the module. No uninstall hook needed...
Comment #12
andypostnot sure that needed
user should be there
once again, this is a entity, should be managed as #3
Comment #13
nerdsteinOK, the following patch should do the trick. The "enforced" config is needed to perform the appropriate cleanup when password policy is uninstalled.
Comment #14
andypostModule should enforce only the module dependency, user form display is updated automatically.
Cleaned-up code and comments.
Field storage should be locked to prevent fields deleted via UI.
Comment #15
andypostDefault value for timestamp is now.
And field already defines default value as 0
Actually I'm not sure that module should do that.
It's a install profile task to ship display and set weight
Comment #16
nerdstein@andypost - I'll test this out tonight and see how it works. In previous testing, I had to have "enforced" to ensure it was properly removed. I'll get back to you shortly once I pull this down and test.
Comment #17
nerdstein@andypost - Oddly, the patch is not applying cleanly for me. I'll try to get it to apply.
Comment #18
nerdsteinThe patch has been reviewed and is working great. I'll push.
Comment #20
nerdsteinPushed to the 8.x-3.x branch
Comment #21
andypost@nerdstein Thanx a lot, looks we need follow-up to discus #15.2 #2650192: Properly place fields into entity display on install