As noted in #2851736: Language reference fields do not implement OptionsProviderInterface facet source plugins should provide metadata for facet fields. It should not be job of processor plugins like the ListItemProcess to figure out the metadata of the configured field - the facet source knows about the source and should provide the necessary metadata, i.e. a typed data definition or if the API is bound to entity fields, a entity field definition.

Comments

fago created an issue. See original summary.

borisson_’s picture

Status: Active » Needs review
StatusFileSize
new3.61 KB

This is a first shot at it, we need to figure out a way to do this for core search still. Just uploading progress for now as it's too late to continue for today.

borisson_’s picture

@fago: is the path in #2 what you wanted to achieve here? I'd like to get approval before I start implementing this in other places.

borisson_’s picture

StatusFileSize
new3.02 KB
new5.41 KB

Rerolled + converted TranslateEntityProcessor. I'm really liking this as this makes the processor so much easier.

Status: Needs review » Needs work

The last submitted patch, 4: facet_source_plugins-2851851-4.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.31 KB
new6.72 KB

Fixes the unit test, which is now also a little bit simpler.

fago’s picture

Oh, awesome to see this getting implemented! :-)

The approach taken looks generally good, however it (needlessly?) restricts it to field definitions. A search is not necessarily about a content entity with fields, i.e. with search API any data could be indexed and searched. Thus, the API should have getDataDefinition(). In the case of indexed entities, it then can return the field definition. So could it just be getDataDefinition() and getDataDefinitions() instead?

borisson_’s picture

StatusFileSize
new6.62 KB
new8.56 KB

I forgot to commit on my local branch, so the interdiff includes the interdiff in #6.

This makes the change suggested in #7 and adds a kernel test to test basic functionality of the new methods as well.

borisson_’s picture

StatusFileSize
new4.02 KB
new10.84 KB

This is a first stab at an implementation for core search + a small improvement of the ListItemProcessor but not yet an implementation of the new api there (I don't really know how to do that... that processor has become a beast of complexity that we should improve) + extra comments in the kernel test.

So what's next now?

  1. Add a test for core search's translate entity or list item processor
  2. Fix the implementation in ListItemProcessor to use the new API to make sure that the implementation is sufficent
  3. Profit?
borisson_’s picture

StatusFileSize
new1.31 KB
new11.33 KB

Adds more docs on the interface.

borisson_’s picture

StatusFileSize
new6.86 KB
new17.94 KB

Also fixed the list item processor, now all we need to do is make sure that the implementation for core works.

Status: Needs review » Needs work

The last submitted patch, 11: facet_source_plugins-2851851-11.patch, failed testing.

fago’s picture

That looks great! A few remarks below:

  1. +++ b/modules/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
    @@ -354,4 +355,21 @@ public function calculateDependencies() {
    +    foreach ($field_configs as $id => $config) {
    

    The $config object is already the field definition, which is a typed data definition also. Thus, just returning $config / $configs should be fine here.

  2. +++ b/src/Plugin/facets/processor/TranslateEntityProcessor.php
    @@ -80,35 +81,24 @@ public static function create(ContainerInterface $container, array $configuratio
    +    if ($field_definition->getPropertyDefinition('entity') === NULL) {
    

    Even more generic would be if you loop over the item definitions and check them for being of type "entity", or if you require the entity type to be known: "entity:some-type".

    All core references use "entity" though, but strictly speaking field types could have properties named "entity" which are something completely different, e.g. some html entity character string.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new791 bytes
new17.83 KB

I don't understand .2

The last submitted patch, 11: facet_source_plugins-2851851-11.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 14: facet_source_plugins-2851851-14.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new13.75 KB

Can't get the list item processor to work with the new getters, but I think we can commit this and open a follow-up for the list item processor. #2851845: List item processor does not work with language references is already changing that processor so that sounds like a better place to refactor the whole thing.

borisson_’s picture

Issue tags: +beta blocker

Doing this will break the API, so we should do this before we tag the first beta.

albertski’s picture

FYI once I apply this patch it breaks the core_views_facets module. I get the following error:

Fatal error: Class Drupal\core_views_facets\Plugin\facets\facet_source\CoreViewsContextualFilter contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Drupal\facets\FacetSource\FacetSourcePluginInterface::getDataDefinitions) in /var/www/mysite/web/modules/contrib/core_views_facets/src/Plugin/facets/facet_source/CoreViewsContextualFilter.php on line 24
borisson_’s picture

@albertski: Yeah, that's why it's an api break. Sorry about that but we since we're still in alpha we can break API's still and this is an improvement for all other code.

Status: Needs review » Needs work

The last submitted patch, 17: facet_source_plugins-2851851-17.patch, failed testing. View results

edurenye’s picture

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

Rebased.

Status: Needs review » Needs work

The last submitted patch, 22: facet_source_plugins-2851851-22.patch, failed testing. View results

borisson_’s picture

Those 2 fails are unrelated and fixed as a part of #2877989: Module depends on a search api service and it shouldn't

edurenye’s picture

Status: Needs work » Needs review

The test passes again.

edurenye’s picture

StatusFileSize
new15.42 KB

Rebased again.

joachim’s picture

Status: Needs review » Needs work

This is just an eyeball review. Mostly nitpicks:

  1. +++ b/modules/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
    @@ -21,7 +21,8 @@ use Symfony\Component\HttpFoundation\Request;
    + *   deriver =
    + *   "Drupal\core_search_facets\Plugin\facets\facet_source\CoreNodeSearchFacetSourceDeriver"
    

    I'm not sure annotations like line breaks like that.

  2. +++ b/modules/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
    @@ -240,7 +241,8 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
    -    $allowed_field_types = $this->moduleHandler->invokeAll('facets_core_allowed_field_types', [$field_types = []]);
    +    $allowed_field_types = \Drupal::moduleHandler()
    +      ->invokeAll('facets_core_allowed_field_types', [$field_types = []]);
    

    This looks like an unrelated change.

  3. +++ b/src/FacetSource/FacetSourcePluginInterface.php
    @@ -96,4 +96,32 @@ interface FacetSourcePluginInterface extends PluginFormInterface, DependentPlugi
    +   * For search api this means that we load the index and call it's getFields
    

    Should be 'Search API' for the module name.

    'its' should have no apostrophe.

    Name of a method should have a () after it.

    Though I'm not sure implementation details should go on the interface -- I would move these to inline comments in the implementations.

  4. +++ b/src/Plugin/facets/facet_source/SearchApiDisplay.php
    @@ -4,7 +4,6 @@ namespace Drupal\facets\Plugin\facets\facet_source;
    -use Drupal\Core\Url;
    

    Unrelated change.

  5. +++ b/tests/src/Unit/Plugin/processor/ListItemProcessorTest.php
    @@ -90,12 +122,14 @@ class ListItemProcessorTest extends UnitTestCase {
    +
    
    @@ -133,12 +167,14 @@ class ListItemProcessorTest extends UnitTestCase {
    +
    

    Unrelated whitespace changes.

    (Yes, I'm being a stickler for these, but when you're doing archaeology in the git log in six month's time to work out when and why something changed, it really helps if commits are as simple as possible!)

borisson_’s picture

#27.3: I know that's an implementation detail, but it's also a great example to show what this method should do. Not sure if we should remove that. I prefer putting such docs in the interface, so we don't have to copy the rest of the docs to the implementation. (As inheritdoc and doc comments can't be mixed.)

The other points are all valid, so we should change those.

joachim’s picture

> #27.3: I know that's an implementation detail, but it's also a great example to show what this method should do. Not sure if we should remove that.

Fair enough :)

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new14.04 KB

I couldn't find the original changes for .4 and .5. Reroll attached.

borisson_’s picture

StatusFileSize
new1.57 KB
new14.39 KB

Status: Needs review » Needs work

The last submitted patch, 31: facet_source_plugins-2851851-31.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new13.51 KB

Reroll because of removing core search.

Status: Needs review » Needs work

The last submitted patch, 33: facet_source_plugins-2851851-33.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.42 KB
new14.48 KB

This should fix the failing test.

strykaizer’s picture

Assigned: Unassigned » strykaizer
Status: Needs review » Needs work

Can we move the getDataDefenition to the Facet instead of the Facet source?

I dont think there is any need in requesting the entire data definition at once (and if so, we can always add an extra method looping over all fields for this).
Working on this

strykaizer’s picture

Status: Needs work » Needs review
StatusFileSize
new8.23 KB
new14.05 KB

WIP, tests need to be fixed.

Status: Needs review » Needs work

The last submitted patch, 37: facet_source_plugins-2851851-37.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB
new14.05 KB
strykaizer’s picture

Status: Needs review » Reviewed & tested by the community

  • StryKaizer committed bbb9cf7 on 8.x-1.x authored by borisson_
    Issue #2851851 by borisson_, edurenye, StryKaizer: Facet source plugins...
strykaizer’s picture

Assigned: strykaizer » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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