Problem/Motivation

Currently the operators() method on views isn't included in the base class \Drupal\views\Plugin\views\filter\FilterPluginBase nor in an interface.

I figured there wouldn't be that many filter plugins without operators so we might add the method to the base class, but it turns out there are quite a few of them

@Lendude in #3

Proposed resolution

Is it worth a followup to try and convert these to interfaces? We can implement the interface in core now, and warn users that implement the method without the interface that they will have to add the interface for Drupal 11?

@longwave in #4

I think the interface idea is fantastic.

@alexpott in #5

Issue fork drupal-3320569

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new3.22 KB
lendude’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
@@ -691,6 +691,9 @@ public function validateExposeForm($form, FormStateInterface $form_state) {
     $operators = $this->operators();

I figured there wouldn't be that many filter plugins without operators so we might add the method to the base class, but it turns out there are quite a few of them so checking for the method sounds like the best way to do this.

longwave’s picture

Is it worth a followup to try and convert these to interfaces? We can implement the interface in core now, and warn users that implement the method without the interface that they will have to add the interface for Drupal 11?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think the interface idea is fantastic. I think we should do that here rather than in a follow up as this issue on it's own doesn't really improve too much.

+++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
@@ -691,6 +691,9 @@ public function validateExposeForm($form, FormStateInterface $form_state) {
+    if (!method_exists($this, 'operators')) {
+      throw new \LogicException(get_class($this) . '::operators() not implemented');
+    }

Would become

    if (!method_exists($this, 'operators')) {
      throw new \LogicException(get_class($this) . '::operators() not implemented');
    }
    elseif (!$this instanceof FilterOperatorsInterface) {
      @trigger_error('Something about having to implement the interface in D11 or else a LogicException will be thrown', E_USER_DEPRECATED);
    }
akram khan’s picture

StatusFileSize
new3.99 KB
new4.02 KB

Address #5 and Updated Patch

akram khan’s picture

StatusFileSize
new4.26 KB
new2.03 KB

try to fix

nitin shrivastava’s picture

StatusFileSize
new601 bytes

try to fix #7

nitin shrivastava’s picture

StatusFileSize
new19.02 KB

try to fix #8

nitin shrivastava’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB

removed CCF error.

smustgrave’s picture

Status: Needs review » Needs work

The last patch doesn't pass commit checks, could you make sure to run ./core/scripts/dev/commit-code-check.sh before uploading a patch to make sure there are no issues with code formatting. see https://www.drupal.org/docs/develop/development-tools/running-core-devel...

Also please include an interdiff

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Spokje made their first commit to this issue’s fork.

spokje’s picture

Assigned: Unassigned » spokje

Rerolled 3320569-2.patch against 11.x in new MR.

All patches after that show that c/p-ing rough example code isn't really helping, not even when tried repeatedly.

spokje’s picture

spokje’s picture

Assigned: spokje » Unassigned
spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

Title: Fix views plugins PHPStan L0 issues » Add an interface to
Issue summary: View changes
spokje’s picture

Title: Add an interface to » Add an interface to operators() on views
spokje’s picture

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

Updated IS and MR and added draft CR.

That's enough two-lettered capitalized words for me to put it on NR.

spokje’s picture

Category: Bug report » Task
spokje’s picture

Title: Add an interface to operators() on views » Add an interface for operators() on views
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

CR reads well, IS is clear and matches MR.

So I believe this is OK.

Couldn't think of anyone two letter word to use haha.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some feedback on the MR. Maybe we should split this into two issues.

spokje’s picture

Status: Needs work » Needs review

Resolved all threads.

smustgrave’s picture

Status: Needs review » Needs work

2 small nitpicky stuff.

Rest looks fine though

Probably good to self RTBC after those 2.

spokje’s picture

Status: Needs work » Reviewed & tested by the community

Not a big fan os self-RTBCing (read: I hate it), but we need @longwave to enlighten us no matter what.

quietone’s picture

I'm triaging RTBC issues. I read the IS, the comments and MR. I didn't find any unanswered questions or other work to do.

The change record does need to be updated. It should state that using the operator method without the interface will throw an exception in Drupal 11.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

And the title of the CR could be more specific about where the operators method is used. Perhaps this is better, "Classes using operators() when extending \Drupal\views\Plugin\views\filter\FilterPluginBase must implement FilterOperatorsInterface'?

spokje’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record updates

Thanks @quietone, updated CR.

catch made their first commit to this issue’s fork.

  • catch committed 024d1d87 on 10.3.x
    Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone,...

  • catch committed 5c82c988 on 11.x
    Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone,...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

I updated the deprecation to throwing an exception in 12.0.0 instead of 11.0.0, otherwise looks great. Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

Status: Fixed » Closed (fixed)

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