Problem/Motivation
Some hierarchical functions can be performance consuming or might be processed in different ways. Right now there is only a hierarchycal taxonomy plugin that is hardcoded in getHierarchy() function.
This will allow other modules to create their own plugins, or extend the current ones.
See also #3005018: Improve performance for taxonomy hierarchical facets.
Proposed resolution
As the code says:
public function getHierarchy() {
// TODO: do not hardcode on taxonomy, make this configurable (or better,
// autoselected depending field type).
return ['type' => 'taxonomy', 'config' => []];
}We should try to get the value from configuration instead.
Remaining tasks
No really sure about these tasks, but I will enumerate them.
- Facet entity should have this property.
- Hook update for adding default value to already existing facets.
- Facet form should take in account this posibility and the "subform" configurations. For example, a hierarchycal taxonomy with depth could have this setting in configuration.
- Test.
User interface changes
A new option in facets configuration will allow to select between some hierarchy options.
API changes
Schema and Entity will be affected, an update db will be needed for already existing facets to have this property with default value "taxonomy".
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 3005040-37.patch | 15.39 KB | mkalkbrenner |
Comments
Comment #2
tuwebo commentedAdding some more info and references.
Comment #3
tuwebo commentedI am pretty sure that code is not very good, but as starting point I will add this patch, so we can iterate over (or redo it enterly).
Comment #4
tuwebo commentedEdited "processor" word since can be confusing. Changed to plugin.
Comment #5
akalam commentedWith last patch hierarchy facets don't show their own configuration forms. Attached one that achieve this. Also trying to fix failing tests (I don't have experience with tests coverage and not sure if test will be fixed).
Comment #6
akalam commentedSorry wrong patch (forgot to add the changes on \Drupal\facets\Form\FacetForm). This should work.
Comment #7
akalam commentedMissing wrong ['settings'] key on form.
Comment #8
borisson_Patch fails a bunch of tests. Those should probably be fixed. I think this is much needed though, because we only have one hierarchy plugin we're not 100% sure that the capabilities for supporting other plugins.
Comment #9
berliner commentedUsing this patch, I am able to create a new FacetsHierarchy plugin and use that to create nested hierarchical facet lists in my current project. As far as I can tell, I didn't encounter any bug that seems related to this patch.
The main thing that I missed is a code reference to the facet that a hierarchy plugin is attached to, so that I can access the facet configuration from any of the methods in
HierarchyInterface. I solved that by adding the facet id to the hierarchy settings viabuildConfigurationForm, so that I can load the respective facet in any of the interface methods using an additional method that I added to my plugin class:Comment #10
attiks commentedI'm using custom hierarchy on top of hierarchical integer lists, patch is working perfectly
Comment #11
anfor commentedRerolled patch on 8.x-1.x-dev and update some annotations.
Comment #12
borisson_We are probably going to need to update the tests so they use the new schema's. Overall this is looking great and it already has an upgrade path, will commmit + tag a new release when this passes tests.
Comment #13
hardikpandya commentedRerolling the patch to the latest release.
Comment #14
jcisio commentedWe'd remove one TODO but add three! This new patch simply removes all these TODOs and does not pretends that we support plugin configuration (the previous patches do not support it neither). It might be added properly in follow-up.
I'll provide more patch to fix tests, but upload this one as the base.
Comment #16
jcisio commentedWould this fix tests?
Comment #18
jcisio commentedComment #20
jcisio commentedThis should fix schema error.
Comment #21
jcisio commentedAnd this one should fix the dependency on the taxonomy module.
Comment #24
jcisio commentedThis one fixes testHierarchySettings().
Sorry that I don't provide interdiff. These are to fix tests, so it'd better to review only the last patch.
Comment #25
jcisio commentedFix the normalized config tests.
Comment #28
jcisio commentedThis should fix the remaining fails.
Comment #29
jcisio commentedSame as #28 but this one removes Facet::loadHierarchies(), this is useless because getHierarchies() and loadHierarchies() always return the same thing.
Comment #30
jcisio commentedFix coding standards.
Comment #31
akalam commentedwonderful!
Comment #32
anneke_vde commentedAdded reroll of patch #30 for 8.x-2.x to fix the error for the duplicate update hook facets_update_8007() after updating to 8.x-2.x
With the help of this patch I created a custom FacetsHierarchy plugin, which now works with 8.x-2.x.
Comment #33
idebr commentedComment #34
idebr commentedReroll after #3255596: Fix coding standards was committed.
Comment #35
idebr commentedAttached patch fixes code style errors, but is otherwise unchanged.
Comment #36
mkalkbrennerI tested this patch manually and added a new plugin. It is selectable in the setting. But neither the new one nor the old plugin work. Both result in
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. Valid plugin IDs for Drupal\facets\Hierarchy\HierarchyPluginManager are: taxonomy, new_hierarchy_plugin in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).Comment #37
mkalkbrennerI think the update hook misses the default configuration.
In an update hook we don't have the entity API in place (unlike in a post update), so preSave is not called.
Comment #39
mkalkbrenner