Rescoped

We have some processors that absolutely require a processor or setting to be enabled to work correctly.
This issue adds the ability for a widget to say what settings / prcoessors are required.

original scope

At this moment we always show all processors in the widget display UI.

Since there are many processors which are not relevant for e.g. a range widget, it might be a good idea to hide them in the UI (and not enable them either for performance reasons).

2 options we can do to tackle this

  • Create a notCompatibleProcessorIds() function in the widget interface/base class, which certain widgets can implement.
  • The other way around, create a nonCompatibleWidget() function in the processor interface/base class.

For me it makes the most sense to implement this function on the widget level.
We can create a hook_alter in this function, so contrib can add their own non-compatible processors to existing widgets.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

StryKaizer created an issue. See original summary.

StryKaizer’s picture

Issue summary: View changes
borisson_’s picture

Issue tags: +Needs committer feedback
StryKaizer’s picture

Postponed, I'll investigate if there are processors which will break the widget if activated.

StryKaizer’s picture

Status: Active » Postponed
borisson_’s picture

Issue tags: -Needs committer feedback

Removing tag, was discussed in the facetapi hangout of 09/11.

If there are processors that'll break a widget, we could add this.
Otherwise, we could add "not recommended".

borisson_’s picture

Version: » 8.x-1.x-dev
Category: Task » Feature request
Issue summary: View changes
Status: Postponed » Active

Changing category to reflect that this is a feature.

StryKaizer’s picture

Priority: Normal » Minor
borisson_’s picture

I started working on this, because I figured we were going to need this to make sure only 1 active item was shown for the dropdown widget, turns out that limiting to only 1 active item is something that's not a processor. So leaving my work here but not doing any more work on this for now. This works but needs extra tests before it can be committed and an alter hook in the methods.

joshi.rohit100’s picture

That sounds great. Don't know if already exist or not or right place but there should also be some way to define if a plugin is compatible to the the field/data type (may be by annotation). I am porting range slider (https://github.com/joshirohit100/facet_slider) and seems like it should only be available for number or date/timestamp field/datatype

mollux’s picture

@borisson_ and I discussed this, and we agreed that for the moment we only see a use case for requiring certain processors or settings to be active.
I created a wip patch that provides the basics for this functionality.

it lacks the functionality to require the processors and settings when changing the widget. This should be done with some ajax (just as the widget specific settings).

This functionality is needed for the slider widget, as the 'Make sure only one result can be shown.' widget setting should always be enabled.

borisson_’s picture

Priority: Minor » Normal
Status: Active » Needs review

Setting to needs review for the testbot. Also changing priority now that we have a use-case.

The last submitted patch, 9: mark_certain_processors-2611198-9.patch, failed testing.

The last submitted patch, 9: mark_certain_processors-2611198-9.patch, failed testing.

mollux’s picture

I made a typo, added new patch an interdiff

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I'd love to also get tests for this functionality, I can work on those if needed. Back to NW for tests.

borisson_’s picture

FileSize
4.99 KB

This only applied with git apply -C 2 mark_certain_processors-2611198-13.patch. So new patch attached.

borisson_’s picture

FileSize
632 bytes
5.04 KB

cs fixes.

borisson_’s picture

Status: Needs work » Needs review

NR, for tests.

borisson_’s picture

FileSize
5.4 KB
10.05 KB

Start of integration test, but nothing happens really. Not sure if I did it right.

borisson_’s picture

Status: Needs review » Needs work

Back to NW for the additional tests.

borisson_’s picture

Status: Needs work » Needs review
FileSize
1.08 KB
10.44 KB

Test's red now. @mollux, am I doing it right?

Status: Needs review » Needs work

The last submitted patch, 22: mark_certain_processors-2611198-22.patch, failed testing.

The last submitted patch, 22: mark_certain_processors-2611198-22.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
10.5 KB

Rebased.

Status: Needs review » Needs work

The last submitted patch, 25: mark_certain_processors-2611198-25.patch, failed testing.

borisson_’s picture

Title: Mark certain processors non-compatible with certain widgets » Mark certain processors required for certain widgets
Issue summary: View changes

Updated IS to say what we're actually working on here.

borisson_’s picture

Status: Needs work » Needs review
FileSize
682 bytes
10.38 KB

Status: Needs review » Needs work

The last submitted patch, 28: mark_certain_processors-2611198-28.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
2.93 KB
10.71 KB

The new test is green locally. So that's great. Let's see how the bots feel

borisson_’s picture

borisson_’s picture

It took me ~5 months but the tests here are green again! I feel this is sufficient for now. Since this is an API break - I'd like to get this in before tagging the first beta.

Nick_vh’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/FacetForm.php
    @@ -137,6 +137,7 @@ class FacetForm extends EntityForm {
    +    $widget = $facet->getWidgetInstance();
    

    Should this get a phpstorm codehint?

  2. +++ b/src/Form/FacetForm.php
    @@ -218,7 +219,7 @@ class FacetForm extends EntityForm {
    +          '#default_value' => $processor->isLocked() || $widget->isPropertyRequired($processor_id, 'processors') || !empty($enabled_processors[$processor_id]),
    

    This code gets quite long, should we break it out?

  3. +++ b/src/Widget/WidgetPluginBase.php
    @@ -212,4 +212,33 @@ abstract class WidgetPluginBase extends PluginBase implements WidgetPluginInterf
    +  public function isPropertyRequired($name, $type) {
    

    When using api functions it is preferable they follow the chain. Eg, first define the type and then the variable to check.

    isPropertyRequired('processor', 'processor-to-check') instead of the reverse.

  4. +++ b/src/Form/FacetForm.php
    @@ -313,14 +314,16 @@ class FacetForm extends EntityForm {
    +      '#default_value' => ($widget->isPropertyRequired('show_only_one_result', 'settings') ?: $facet->getShowOnlyOneResult()),
    

    Are the ( and ) needed here? Doesn't add much for readability.

  5. +++ b/src/Form/FacetForm.php
    @@ -313,14 +314,16 @@ class FacetForm extends EntityForm {
    +      '#disabled' => ($widget->isPropertyRequired('show_only_one_result', 'settings') ?: 0),
    

    Are the ( and ) needed here? Doesn't add much for readability.

  6. +++ b/src/Widget/WidgetPluginBase.php
    @@ -212,4 +212,33 @@ abstract class WidgetPluginBase extends PluginBase implements WidgetPluginInterf
    +      return $this->requiredFacetProperties()[$type][$name];
    

    Does this actually return true or a value? Careful to pass unexpected values. Certainly because this is a plugin type that developers can create themselves.

borisson_’s picture

Status: Needs work » Needs review
Issue tags: +SprintWeekend2017
FileSize
6.74 KB
10.87 KB

@Nick_vh

  1. No, phpstorm understands the @return typehint.
  2. Done!
  3. Not sure I agree here, I think it makes sense like this as well.
  4. done
  5. done
  6. Should return a boolean. That's how it's documented, I don't think we should defend against improper api usage here.

Reroll attached

Status: Needs review » Needs work

The last submitted patch, 34: mark_certain_processors-2611198-34.patch, failed testing.

borisson_’s picture

Discussed this with nick, we should use a value object instead of an array here.

borisson_’s picture

Status: Needs work » Needs review
FileSize
5.11 KB
8.81 KB

Discussed this with @mollux, we decided to trash requiredFacetProperties

Status: Needs review » Needs work

The last submitted patch, 37: mark_certain_processors-2611198-37.patch, failed testing.

borisson_’s picture

Title: Mark certain processors required for certain widgets » Give widgets the ability to require settings

Updated IS.

borisson_’s picture

Status: Needs work » Needs review
FileSize
659 bytes
9.16 KB

Fixes the test.

borisson_’s picture

FileSize
968 bytes
9.47 KB

Adds extra docs.

  • borisson_ committed aa8cbf6 on 8.x-1.x
    Issue #2611198 by borisson_, mollux, StryKaizer: Give widgets the...
borisson_’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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