Problem/Motivation
Expose a list of checkboxes for each type. Ticking the checkbox should expose that base field for the selected entity types. In case a base field already exists and is not defined by us (e.g. node), it should be checked by default and be disabled. This in turn will then automatically expose a alias type plugin. At this point, we'll have achieved the goal of fully generic and automated integration with any entity type.
Proposed resolution
Add a setting, allow to enable it for every fieldable entity type, with it being enabled by default for user
Remaining tasks
* Tests
* Update function for default config?
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #44 | allow_to_configure-2655780-44.patch | 15.89 KB | Bambell |
| #26 | 2016-06-07-10:55:36-Screenshot.png | 10.03 KB | kgaut |
| #13 | pathauto-field-configurable-2655780-13.patch | 6.55 KB | rachel_norfolk |
| #8 | Selection_019.png | 17.67 KB | berdir |
| #2 | pathauto-field-configurable-2655780-2.patch | 6.03 KB | berdir |
Comments
Comment #2
berdirComment #3
berdirForgot about default config and schema. This passes for me.
Comment #6
berdirComment #7
dave reidComment #8
berdirThere's not much to see, just a bunch of checkboxes.
See also the referenced file_entity issue about what it means for a module that integrates with pathauto.
@todo:
* move the cache clears into a config save event listener, so it also works for config deployments and the file_entity patch can then be simplified too.
* Write a test just like the one in file_entity, with an entity_test entity.
Comment #9
dave reidComment #10
dave reidSo maybe an alternate opinion, what if, the user went to create a new pattern for the user entity type, and creating that pattern would double check that the base field exists, and created it if needed. This would minimize the need for anyone to actually use/change this setting.
Comment #11
berdirIt would, but then you'd get lots of options on the add pattern form that really don't make sense, like shortcut and menu links. But yes, now you get those options on the settings page.
We'd have to change for what we expose plugins, currently that only happens for entity types that have a path field.
It would make the code to check for which entity types the field should be added more complicated, same for the code that needs to detect a cache and clear caches. A bit worried about adding more dynamics and complexity there, but we can try that if you'd prefer that.
Comment #12
rachel_norfolkWhat *should* this patch apply against? I’m trying with a git checkout from
git clone --branch 8.x-1.x https://git.drupal.org/project/pathauto.gitbut no good.I just want to check before re-rolling etc.
Would be *really* good to help progress pathauto against arbitrary entity type (e.g. group)
Comment #13
rachel_norfolkOkay, I’ve done a little rerolling and got the attached. I think things have moved around a little since this patch applied cleanly in its original form. It does need a check to see the logic is still correct, based on the latest changes.
Comment #14
rachel_norfolkSorry - why was I thinking I made an Interdiff - I didn’t from this reroll!
Comment #15
rachel_norfolkComment #16
alexdmccabeI found an issue while testing this. If you enable an entity type, create a pattern for it, disable that same entity type, and revisit /admin/config/search/path/patterns, you get an error that persists unless you re-enable the entity type. I tested this behavior with both the user and comment entities, so I imagine it persists across all entities.
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "canonical_entities:user" plugin does not exist. in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 52 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).Additionally, there were some coding standards issues with the changes being made:
@var blocks need a short description, and it's required to include the curly brackets when using {@inheritdoc}.
Check out https://www.drupal.org/node/1354#var and https://www.drupal.org/node/1354#inheritdoc for more on those two issues.
Comment #17
Bambell commentedFixed this bug by implementing
FallbackPluginManagerInterfaceonAliasTypeManagerand disabling checkboxes of entity types that currently have pattern(s) defined.Comment #20
berdirclose, but it's not a block :)
Just return $this->t('Broken type').
not sure what this is, I think a copy & paste mistake from me. remove it.
Now we need tests for ($type = pick one that is not enabled by default. you might need to enable a module, e.g. block_content, comment, ..):
1. Ensure that $type is not available as an type when adding a pattern.
2. Ensure that Broken is not available there.
3. Enable the type.
4. Now create a pattern with that type.
5. Create an entity of that type, ensure the alias is generated.
6. Make sure the type can not be disabled now.
7. Delete $type from the setting through the API., call clearCachedDefinitions() on plugin manager.
8. visit the overview page, must not be broken, check for the broken type string.
9. Make sure that you can delete the pattern.
10. Enable $type again, disable it again while there is no pattern.
Comment #21
Bambell commentedTried implementing a test, but not having much luck with
assertEntityAliasExists. Apparently the comment isn't properly created (or the article). Not exactly sure why. Here's the patch for now.Comment #22
Bambell commentedFailing tests and #16 bug should be fixed.
Comment #25
Bambell commentedAdded a check not to try to display "Broken" as an entity type on the aliases deletion form.
Comment #26
kgaut commentedGreat patch, it's what I'm looking for.
My two cents :
By using the patch #25, I get "Broken type" for my already defined pattern for User entity type.
Also In the settings area I'm not seeing all my custom entity types listed, what makes one listed ?
Comment #27
Bambell commentedYou're going to see "Broken type" on the patterns list page if you have a pattern for an entity type that is disabled. The settings page has been modified to prevent users form disabling an entity type that already has patterns defined for it, so normally this shouldn't be seen.
Comment #28
kgaut commentedI didn't disable User entity type ;).
What I've done :
Let me know if I can help
Comment #29
berdirYes because user is now configurable and you have to enable it. Just go to the settings page and do that. We could add an update function to automatically make user selected by default.
The settings page shows content entity types with a canonical link template, only those are supported at the moment.
Comment #30
kgaut commentedThanks Berdir,
The patch #25 is working great ! Thanks.
Comment #31
berdirLets add an update function that ensures that this is also set for existing sites to avoid the confusing broken type message when they update.
You just have to get the editable config, set user as enabled and then save.
Lets make the key a bit more self-explaining and name it enabled_entity_types.
I'm also wondering if we should simplify the structure to a list of entity types instead of using them as key with a dummy boolean value. The default config would then look like this:
enabled_entity_types:
- user
it would mean that this would get a bit more complicated as we'd need an in_array() check.
what about the bulk update form, doesn't that need the same?
I would recommend that we hadd a getVisibleDefinitions() method to the alias type manager and use that, then you don't have to change anything here.
Could also be a getVisibleOptions() and just return key => label.
Comment #32
Bambell commentedHere's a quick work in progress patch. Tests will fail.
Are you sure it's as simple as this? I would have thought that the update function should enable each entity type that already has a pattern defined.
Comment #33
Bambell commentedComment #34
Bambell commentedComment #35
Bambell commentedAll changes recommended in #31 have been done. It tests fine locally. I'm posting an interdiff with #25 only, #32 should be ignored.
Comment #36
berdirAlmost there I think.
we always return an array, so the type is just array. I think this is mixed in getDefinitions() because that can also return objects for some plugin types.
No need to repeat the implementation of getDefinitions() here. Just call $definitions = $this->getDefinitions()
Missing . at the end of the comment.
This means we will now store node in the list, even though that is not actually a type that can be enabled or disabled.
There used to be only one disabled condition (not defined by us), now there are two. This means instead of just removing this check, you need to instead do the same check as in the disabled check about, with the provider.
Make sure you test this, by making sure that node is not saved in the config when submitting this form.
Comment #37
Bambell commentedI addressed points 1. to 4., manually verified that node doesn't get saved in the config.
Not sure which of
@return arrayor@return string[]is better. Both seem widely used and appropriate here. I used@return array.Comment #40
Bambell commentedFixing failing test.
Comment #41
berdirOne last thing:
Add a comment about that fairly complex condition and explain why we're doing it like that.
Comment #42
Bambell commentedDone.
Comment #43
berdirWorks for me, will commit this soon.
@davereid: Not ignoring your idea to enable it automatically, but I think this is a good first step, we could still change that, but I think there would be some challenges when doing that (basically a cross-dependency between config entities and plugins that they use, which exist based on the config entities that exist).
Thinking about that, I think what would make sense is extend the descrption on the type selection and say that additional types can be enabled on the settings page, with a link that points there. Lets do that, setting back to needs work hopefully one final time for that ;)
Comment #44
Bambell commentedAssuming you were referring to the type selection on the pattern creation form.
Comment #45
berdirYes.
Comment #47
berdirGreat, committed.
Comment #48
kgaut commentedawesome ! Thanks !