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

Comments

TuWebO created an issue. See original summary.

tuwebo’s picture

Adding some more info and references.

tuwebo’s picture

Status: Active » Needs review
StatusFileSize
new6.69 KB

I 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).

tuwebo’s picture

Issue summary: View changes

Edited "processor" word since can be confusing. Changed to plugin.

akalam’s picture

StatusFileSize
new10.69 KB
new2.88 KB

With 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).

akalam’s picture

StatusFileSize
new11.88 KB
new6.31 KB

Sorry wrong patch (forgot to add the changes on \Drupal\facets\Form\FacetForm). This should work.

akalam’s picture

StatusFileSize
new11.86 KB
new6.29 KB

Missing wrong ['settings'] key on form.

borisson_’s picture

Status: Needs review » Needs work

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.

berliner’s picture

Using 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 via buildConfigurationForm, 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:

/**
   * Get the facet that this processor is attached to.
   *
   * @return \Drupal\facets\FacetInterface
   */
  protected function getFacet() {
    $facet_id = $this->getConfiguration()['source_facet'];
    return \Drupal::entityTypeManager()->getStorage('facets_facet')->load($facet_id);
  }
attiks’s picture

I'm using custom hierarchy on top of hierarchical integer lists, patch is working perfectly

anfor’s picture

Rerolled patch on 8.x-1.x-dev and update some annotations.

borisson_’s picture

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.

hardikpandya’s picture

Rerolling the patch to the latest release.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new10.72 KB

We'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.

Status: Needs review » Needs work

The last submitted patch, 14: 3005040-facet-hierarchy-no-todo-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new10.89 KB

Would this fix tests?

Status: Needs review » Needs work

The last submitted patch, 16: 3005040-facet-hierarchy-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new11.44 KB

Status: Needs review » Needs work

The last submitted patch, 18: 3005040-facet-hierarchy-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new11.17 KB

This should fix schema error.

jcisio’s picture

StatusFileSize
new14.95 KB

And this one should fix the dependency on the taxonomy module.

The last submitted patch, 20: 3005040-facet-hierarchy-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 21: 3005040-facet-hierarchy-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new15.54 KB

This 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.

jcisio’s picture

StatusFileSize
new16.14 KB

Fix the normalized config tests.

The last submitted patch, 24: 3005040-facet-hierarchy-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 25: 3005040-facet-hierarchy-25.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new16.14 KB

This should fix the remaining fails.

jcisio’s picture

StatusFileSize
new15.84 KB

Same as #28 but this one removes Facet::loadHierarchies(), this is useless because getHierarchies() and loadHierarchies() always return the same thing.

jcisio’s picture

StatusFileSize
new15.84 KB

Fix coding standards.

akalam’s picture

wonderful!

anneke_vde’s picture

StatusFileSize
new15.86 KB

Added 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.

idebr’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
idebr’s picture

idebr’s picture

StatusFileSize
new4.35 KB
new15.33 KB

Attached patch fixes code style errors, but is otherwise unchanged.

mkalkbrenner’s picture

Status: Needs review » Needs work

I 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).

mkalkbrenner’s picture

Status: Needs work » Needs review
StatusFileSize
new15.39 KB
new553 bytes

I 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.

  • mkalkbrenner committed 56afe2e on 2.0.x
    Issue #3005040 by jcisio, akalam, idebr, mkalkbrenner, anfor, TuWebO,...
mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.