Problem/Motivation

The documentation for \Drupal\views\Plugin\views\join\JoinPluginInterface is incorrect/incomplete:

  • The parameter $select_query asks for an instance of \Drupal\Core\Database\Query\Select, but that should probably be \Drupal\Core\Database\Query\SelectInterface. I don't see a reason why 'Select' was used in #3478172: Add MissingParamType for views.
  • Parameter $table is defined as a string, while in practise it is used as an array.
  • The parameter descriptions are too brief. @joachim mentions this specifically for the $select_query parameter in #29, but I think that the other parameters are brief as well.

Original report by hardik_patel_12

Type hint "\Drupal\Core\Database\Query\SelectInterface" missing for $select_query
Type hint "\Drupal\views\Plugin\views\query\QueryPluginBase" missing for $view_query

Issue fork drupal-3104796

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

Hardik_Patel_12 created an issue. See original summary.

hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new763 bytes

Status: Needs review » Needs work

The last submitted patch, 2: type_hint_missing-3104796-2.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new928 bytes
new1.61 KB

Kindly follow a new patch

Status: Needs review » Needs work

The last submitted patch, 4: type_hint_missing-3104796-4.patch, failed testing. View results

daffie’s picture

@Hardik_Patel_12: You must add: use Drupal\Core\Database\Query\SelectInterface; for your patch to work. Without it PHP thinks that SelectInterface is in the current namespace.

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new965 bytes
new2.1 KB

@daffie , thankyou for help. Kindly review a new patch.

Status: Needs review » Needs work

The last submitted patch, 7: type_hint_missing-3104796-7.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB
new2.1 KB

kindly review a new patch

Status: Needs review » Needs work

The last submitted patch, 9: type_hint_missing-3104796-7.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new4.67 KB
new2.7 KB

kindly review a new patch

naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

#11 looks good to me

naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs review » Reviewed & tested by the community
lendude’s picture

Status: Reviewed & tested by the community » Needs work

Some more clean up can be done here while we are touching this

  1. +++ b/core/modules/views/src/Plugin/views/join/JoinPluginBase.php
    @@ -4,7 +4,7 @@
    +use Drupal\views\Plugin\views\query\QueryPluginBase;
     /**
    

    Needs a newline between the use statement and the docblock

  2. +++ b/core/modules/views/src/Plugin/views/join/JoinPluginInterface.php
    @@ -14,13 +17,13 @@
        *   An select query object.
    

    Can we fix this typo while we are touching this? 'an select' => 'a select'

  3. +++ b/core/modules/views/src/Plugin/views/join/JoinPluginInterface.php
    --- a/core/modules/views/src/Plugin/views/join/Subquery.php
    +++ b/core/modules/views/src/Plugin/views/join/Subquery.php
    
    +++ b/core/modules/views/src/Plugin/views/join/Subquery.php
    @@ -38,7 +41,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
        * @param \Drupal\views\Plugin\views\query\QueryPluginBase $view_query
        *   The source views query.
        */
    -  public function buildJoin($select_query, $table, $view_query) {
    +  public function buildJoin(SelectInterface $select_query, $table, QueryPluginBase $view_query) {
    

    Can we update the docblock for Subquery to just be {@inheritdoc}?

daffie’s picture

@lendude: Do you know if there are contrib modules that extend the buildJoin method? If so, then that would result in a BC-break.

daffie’s picture

I have just one remark:

+++ b/core/modules/views/src/Plugin/views/join/JoinPluginBase.php
@@ -109,10 +109,10 @@
- *     parent::buildJoin($select_query, $table, $view_query);
+ *     parent::buildJoin(SelectInterface $select_query, $table, QueryPluginBase $view_query);

You do not need to add type hints in method calls.

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new5.12 KB

Kindly review a new patch

hardik_patel_12’s picture

lendude’s picture

@lendude: Do you know if there are contrib modules that extend the buildJoin method?

Yeah was thinking about that too. Quick check in my contrib folder:
SearchAPI => \Drupal\search_api\Plugin\views\join\SearchApiJoin

So this a no-go in D8 and since it probably needs a deprecation or something, it probably would need to be announced/deprecated in D9 and then go into D10 :/

So I would probably just advice to leave this and when we start adding return type hints and break everything anyway, we can break this too ¯\_(ツ)_/¯

daffie’s picture

Status: Needs review » Needs work

So this a no-go in D8 and since it probably needs a deprecation or something, it probably would need to be announced/deprecated in D9 and then go into D10 :/

So I would probably just advice to leave this and when we start adding return type hints and break everything anyway, we can break this too ¯\_(ツ)_/¯

The adding of parameter type hints need to go, but what we still can do is the docblock parts.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.

joachim’s picture

+++ b/core/modules/views/src/Plugin/views/join/JoinPluginInterface.php
@@ -14,13 +17,13 @@
-   * @param $select_query
-   *   An select query object.
+   * @param \Drupal\Core\Database\Query\SelectInterface $select_query
+   *   A select query object.
    * @param $table

IMO fixing this typo is out of scope here.

Besides, the docs need more detail -- what about the select query object? What is it here for, what does this method do with it?

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

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

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

megachriz’s picture

Title: SelectInterface and QueryPluginBase type hint missing » Incorrect documentation for \Drupal\views\Plugin\views\join\JoinPluginInterface
Issue summary: View changes
Status: Needs work » Needs review

I came here because the type for the parameter $table is incorrect. In the interface it is documented as a string, but \Drupal\views\Plugin\views\join\JoinPluginBase uses it as if it is an array:

$select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);

On a local project I use a custom ViewsJoin plugin, and now PHPStan complains that $table cannot be an array.

Since I think that also the type of parameter $select_query would better be \Drupal\Core\Database\Query\SelectInterface than \Drupal\Core\Database\Query\Select, I thought the changes to the $table parameter would fit within this issue.

In the MR, the descriptions of the parameters are generated by AI, as I'm not an expert on the Views code. I did attempt to verify if the generated documentation is correct and removed a part generated by AI that looked more like a reaction to my prompt.

joachim’s picture

Component: views.module » documentation
Category: Task » Bug report
Status: Needs review » Needs work

Looks good overall, just a few small suggestions.

megachriz’s picture

Status: Needs work » Needs review

I've attempted to address the feedback by @joachim.

joachim’s picture

Status: Needs review » Needs work

Thanks! Left a few comments.

megachriz’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joachim’s picture

This looks great, just needs a rebase according to the bot.