Comments

mbovan’s picture

Status: Active » Needs review
StatusFileSize
new2.05 KB

Here is the patch with the same implementation for the validateAutocompleteInput() as in SelectionBase class.

berdir’s picture

Issue tags: +Needs tests

Note that the code is identical to SelectionBase, but ViewsSelection currently doesn't extend from that (which makes sense, because it's not actually a base class).

We could add a real base class or a trait for this as well... And we need tests.

mbovan’s picture

Since #2482625: Views entity reference selection with autocomplete widget broken is committed we can continue with this issue.

Added SelectionValidateTrait and now we call validateAutocomplete() in both SelectionBase and ViewsSelection classes.

Providing test only patch too...

berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php
@@ -248,21 +249,39 @@ public function testFieldAdminHandler() {
+    $edit = array(
+      'title[0][value]' => 'Test',
+      'field_test_entity_ref_field[0][target_id]' => $node->getTitle()
+    );
+    $this->drupalPostForm('node/add/' . $this->type, $edit, t('Save'));
+    $this->assertLink($node->getTitle());

Wondering if we should also test the more advanced cases of that method, for example when there are two nodes with the same title (as then this can't work anymore).

It's a trait now, so we could say it's covered elsewhere but it probably doesn't hurt to have that covered here as well? The test shouldn't assume that we're using the same code..

+++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
@@ -263,7 +266,7 @@ public function validateReferenceableEntities(array $ids) {
    */
   public function validateAutocompleteInput($input, &$element, FormStateInterface $form_state, $form, $strict = TRUE) {
-    return NULL;
+    return $this->validateAutocomplete($input, $element, $form_state, $form, $strict);
   }

Can't we just directly implement the public method in the interface? Then you don't need duplicated documentation there.

You can't implement the interface there, but you can say something like Implements \Drupal\.... in the docblock.. I think that's fine for such cases?

mbovan’s picture

dawehner’s picture

Just some small points ...

  1. +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionValidateTrait.php
    @@ -0,0 +1,56 @@
    +  /**
    +   * Implements \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::validateAutocompleteInput().
    +   */
    

    Use {@inheritdoc} instead

  2. +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php
    index 7b4d424..47a946c 100644
    --- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    
    --- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    +++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    

    Should we introduce some dedicated test coverage for the views selection plugin?

berdir’s picture

1. is @inheritdoc really allowed in a trait that doesn't extend from the interface? That's impossible to resolve, thats why I suggested an explicit reference.

2. dedicated as in how exactly? The tests that we are adding are views selection specific, they extend the tests that @mbovan wrote for #2482625: Views entity reference selection with autocomplete widget broken, which are creating a entity reference view and using it for the field we are testing.

jhodgdon’s picture

Yeah, we cannot use @inheritdoc because the trait doesn't technically implement the interface, so PhpStorm, other IDEs, and/or API module cannot figure that out.

So using the old "Implements..." as in this patch is fine.

Another possibility would be to do something like this:

/**
 * First line description from interface method goes here.
 *
 * See \full\name\of\interface::methodName() for documentation.
 */
function methodName() {
...

I think either way is fine, but @inheritdoc, not so much.

berdir’s picture

Assigned: Unassigned » amateescu

Assigning to @amateescu for his review :)

amateescu’s picture

Assigned: amateescu » Unassigned

I would prefer adding a real base class rather than a trait with just one method :)

And we should rename Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase to Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection, but if the api change is deemed not acceptable at this point, we'll have to try and find a good name for the new base class.

But if everyone else thinks the trait is fine, I'm ok with the current patch as well (i.e. feel free to rtbc :P).

berdir’s picture

Status: Needs review » Needs work

Asked @alexpott but I don't think renaming that is still an option.

However, what if we just extend from SelectionBase? We can override anything we don't need and extending from another plugin doesn't prevent us from being exposed as a completely different plugin in anyway. And there are actually quite a few methods that are identical...

@mbovan, care to try that?

mbovan’s picture

mbovan’s picture

ViewsSelection extends SelectionBase now, so removing implementation of SelectionInterface and ContainerFactoryPluginInterface.

alexpott’s picture

re #13 Yeah renaming would need to be justified by something critical. Perhaps we can solve the naming issues with food documentation on both classes?

amateescu’s picture

StatusFileSize
new8.36 KB
new777 bytes

How about this? I can't think of a better way of saying that the views selection plugin is not based on entity query :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Discussed with @amateescu, he's ok in general with extending like that. Patch looks good to me now.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The issue summary could do with an update. Patch looks good to me.

jibran’s picture

Issue tags: +VDC

I'd like to see what @dawehner thinks about this patch.

jibran queued 19: 2482705-19.patch for re-testing.

mbovan’s picture

Issue summary: View changes
Status: Needs work » Needs review

Updated the issue summary.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

I think the issue summary covers what this is doing.

Also not sure there's anything that @dawehner needs to look at. If I find the time, great, but there's nothing complicated going on here.

jibran’s picture

RTBC +1

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed a1b24c2 and pushed to 8.0.x. Thanks!

  • alexpott committed a1b24c2 on 8.0.x
    Issue #2482705 by mbovan, amateescu, Berdir: ViewsSelection::...

Status: Fixed » Closed (fixed)

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