Problem/Motivation

When using token replacement for a value coming from a view argument in a view area, for example if passing field_tags as an argument, both possible tokens produce the passed term id. The documentation says:
{{ arguments.field_tags_target_id }} == Content: Tags (field_tags) title
{{ raw_arguments.field_tags_target_id }} == Content: Tags (field_tags) input

Steps to reproduce

  1. New installation with the standard profile
  2. create a node with a few tags
  3. create a content view, add field_tags as an argument.
  4. create a text area header block, choose to use Use replacement tokens from the first row, then add both proposed tokens to the text area {{ arguments.field_tags_target_id }} {{ raw_arguments.field_tags_target_id }} in the preview area, supply 1 as argument, you should get the title of the tag, and the ID. You get two IDs.

Proposed resolution

Consolidate all the different entity argument plugins (a few of which handle title replacement correctly, most of which do not), into a single Drupal\views\Plugin\views\argument\EntityArgument. This base plugin correctly handles label replacement tokens.

This removes a bunch of (nearly) duplicate code, improves consistency and functionality, while reducing technical debt.

  • MR !7091 is the 11.x version, clean and shiny
  • MR !7571 is the 10.3.x version with a BC layer and deprecation tests
  • MR !7572 is the 10.2.x version with a silent BC layer

Remaining tasks

  1. Deal with validate-able config test failures?
  2. Ensure pipelines are green on all branches
  3. Reviews
  4. RTBC
  5. Commit / rejoice
  6. Unblock #3442227: Use labels in Views argument summaries for entity references and fix that, too

User interface changes

There's no user-visible change in the backend views UI. But views that are configured to have titles with human-readable labels will see those labels, not the numeric IDs you currently see, regardless of which token you reference.

Before

View with the title '4' from a contextual filter

After

The same view where the title is now 'Arts and Culture'

API changes

Add Drupal\views\Plugin\views\argument\EntityArgument (ID: entity_id) to handle entity ID values that are directly part of an entity.

Add Drupal\views\Plugin\views\argument\EntityReferenceArgument (ID: entity_target_id) to handle entity ID values from an entity reference.

All of the following now simply extend the EntityArgument base with no other code:

  • core/modules/file/src/Plugin/views/argument/Fid.php
  • core/modules/node/src/Plugin/views/argument/Nid.php
  • core/modules/taxonomy/src/Plugin/views/argument/Taxonomy.php
  • core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php
  • core/modules/user/src/Plugin/views/argument/Uid.php

A BC layer lives in the 10.x versions of EntityArgument to handle all the legacy ways these plugins were constructed or their protected properties accessed. See the change record for this issue for details.

Data model changes

New views_post_update_views_data_argument_plugin_id() goes through existing Views on the site that are configured to use a numeric argument plugin that points to an entity ID property and updates them to use the new entity_target_id plugin and set the target_entity_type_id option correctly.

Release notes snippet

When using a Views contextual filter (aka "argument") on an entity reference field, there is an option to override the title of the view using tokens based on the contextual filter value. There are separate tokens for the raw ID and the label of the entity that ID points to. These separate tokens did not work until Drupal version X. views_post_update_views_data_argument_plugin_id() is provided to update the configuration of any impacted Views on existing sites.

CommentFileSizeAuthor
#170 2640994-nr-bot.txt9.24 KBneeds-review-queue-bot
#167 2640994-nr-bot.txt90 bytesneeds-review-queue-bot
#155 drupal-2640994-154-10.1.x.patch39.97 KBalex.bukach
#154 drupal-2640994-154-11.x.patch39.98 KBalex.bukach
#154 drupal-2640994-154-10.1.x.patch39.97 KBalex.bukach
#151 2640994-151.patch39.91 KBnicxvan
#148 interdiff_146-148.txt1.46 KBravi.shankar
#148 2640994-148.patch40.01 KBravi.shankar
#146 interdiff_145_146.txt889 bytesameymudras
#146 2640994-146.patch40 KBameymudras
#145 2640994-145.patch40 KBameymudras
#144 2640994-144.patch39.9 KBameymudras
#143 interdiff_142-143.txt1.85 KBpradhumanjain2311
#143 2640994-143.patch17.55 KBpradhumanjain2311
#142 reroll_diff_137-142.txt7.09 KBravi.shankar
#142 2640994-142.patch40.06 KBravi.shankar
#139 Screen Shot 2022-10-06 at 12.45.06 pm.png24.09 KBpameeela
#139 Screen Shot 2022-10-06 at 12.42.43 pm.png20.4 KBpameeela
#137 interdiff_133_137.txt1.73 KBameymudras
#137 2640994-137.patch44.53 KBameymudras
#135 interdiff_2640994_133-134.txt840 bytesanchal_gupta
#135 2640994_133-134.patch46.86 KBanchal_gupta
#133 2640994-133.patch44.49 KBameymudras
#129 patch-122-test-example-view-with-contextual-filter.png207.61 KBtechnoveltyco
#123 drupal-2640994-122-9.2.patch44.35 KBalex.bukach
#123 drupal-2640994-122-9.3.patch44.42 KBalex.bukach
#122 drupal-2640994-122-9.4.patch44.44 KBalex.bukach
#120 drupal-2640994-118-9.4.patch42.99 KBalex.bukach
#117 interdiff-117-110-9.2.txt13.11 KBalex.bukach
#117 drupal-2640994-117-9.3.patch40.69 KBalex.bukach
#117 drupal-2640994-117-9.3.patch40.69 KBalex.bukach
#117 drupal-2640994-117-9.2.patch40.63 KBalex.bukach
#115 reroll_diff_2640994_110-115.txt3.93 KBankithashetty
#115 2640994-115.patch44.77 KBankithashetty
#110 2640994-110.patch44.72 KBcatch
#110 2640994-110-9.2.x.patch39.78 KBcatch
#109 2640994-9-2-x.patch40.81 KBcatch
#108 2640994-108.patch45.71 KBcatch
#101 interdiff_100-101.txt2.04 KBraman.b
#101 2640994-101.patch40.76 KBraman.b
#100 interdiff_93-100.txt6.03 KBraman.b
#100 2640994-100.patch40.67 KBraman.b
#93 2640994-93.patch40.14 KBnikitagupta
#86 2640994-85.patch20.08 KBfeyp
#84 token_replacement_tax_arg-2640994-84.patch39.86 KBBen Buske
#80 2640994-80.patch39.73 KBBen Buske
#76 2640994-75.patch39.88 KBjofitz
#76 interdiff-74-75.txt2.07 KBjofitz
#74 2640994-74.patch39.9 KBjofitz
#69 token_replacement_tax_arg-2640994-69-interdiff.txt16.03 KBberdir
#69 token_replacement_tax_arg-2640994-69.patch40.33 KBberdir
#68 token_replacement_tax_arg-2640994-68-interdiff.txt843 bytesberdir
#68 token_replacement_tax_arg-2640994-68.patch24.96 KBberdir
#66 token_replacement_tax_arg-2640994-66-interdiff.txt10.92 KBberdir
#66 token_replacement_tax_arg-2640994-66.patch25.32 KBberdir
#63 token_replacement_tax_arg-2640994-61.patch16.17 KBberdir
#61 token_replacement_tax_arg-2640994-61-interdiff.txt4.49 KBberdir
#61 token_replacement_tax_arg-2640994-61.patch16.17 KBberdir
#59 token_replacement_tax_arg-2640994-59.patch18.16 KBtduong
#59 interdiff-2640994-57-59.txt3.35 KBtduong
#57 token_replacement_tax_arg-2640994-57.patch18.16 KBtduong
#57 interdiff-2640994-55-57.txt3.38 KBtduong
#55 token_replacement_tax_arg-2640994-55.patch18.24 KBtduong
#55 interdiff-2640994-54-55.txt6.27 KBtduong
#54 token_replacement_tax_arg-2640994-54.patch17.15 KBtduong
#54 interdiff-2640994-52-54.txt3.48 KBtduong
#52 token_replacement_tax_arg-2640994-52.patch15.92 KBtduong
#52 interdiff-2640994-45-52.txt1.51 KBtduong
#45 token_replacement_tax_arg-2640994-45.patch15.93 KBtduong
#45 token_replacement_tax_arg-2640994-45-test_only.patch3.85 KBtduong
#45 interdiff-2640994-42-45.txt1.74 KBtduong
#42 token_replacement_tax_arg-2640994-42.patch14.42 KBtduong
#42 token_replacement_tax_arg-2640994-42-test_only.patch3.85 KBtduong
#42 interdiff-2640994-37-42.txt362 bytestduong
#37 token_replacement_tax_arg-2640994-37.patch13.99 KBtduong
#37 token_replacement_tax_arg-2640994-37-test_only.patch2.87 KBtduong
#37 interdiff-2640994-33-37.txt1.7 KBtduong
#33 token_replacement_tax_arg-2640994-33.patch14.52 KBtduong
#33 interdiff-2640994-31-33.txt491 bytestduong
#8 token_replacement_tax_arg-2640994-8.patch2.59 KBtduong
#10 interdiff-2640994-8-10.txt9.75 KBtduong
#10 token_replacement_tax_arg-2640994-10.patch11.42 KBtduong
#13 interdiff-2640994-10-13.txt5.03 KBtduong
#13 token_replacement_tax_arg-2640994-13-test_only.patch2.01 KBtduong
#13 token_replacement_tax_arg-2640994-13.patch11.83 KBtduong
#16 interdiff-2640994-13-16.txt452 bytestduong
#16 token_replacement_tax_arg-2640994-16.patch11.26 KBtduong
#18 interdiff-2640994-16-18.txt1.32 KBtduong
#18 token_replacement_tax_arg-2640994-18.patch11.38 KBtduong
#22 interdiff-2640994-18-22.txt5.57 KBtduong
#22 token_replacement_tax_arg-2640994-22.patch13.16 KBtduong
#24 interdiff-2640994-22-24.txt1.92 KBtduong
#24 token_replacement_tax_arg-2640994-24.patch13.57 KBtduong
#27 interdiff-2640994-24-27.txt3.33 KBtduong
#27 token_replacement_tax_arg-2640994-27.patch12.89 KBtduong
#29 interdiff-2640994-27-29.txt597 bytestduong
#29 token_replacement_tax_arg-2640994-29.patch13.6 KBtduong
#31 interdiff-2640994-29-31.txt5.37 KBtduong
#31 token_replacement_tax_arg-2640994-31.patch13.96 KBtduong

Issue fork drupal-2640994

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

alayham created an issue. See original summary.

cilefen’s picture

Version: 8.1.x-dev » 8.0.x-dev

Bugs can be fixed in 8.0.x.

berdir’s picture

Except I'm not sure it's a bug, or where that bug is.

Yes it says title there, but this is about the *argument* title, not the term name. And it is whatever the argument plugin happens to implement, which I guess in this case, isn't much.

In short, it's not a token problem, that very likely returns correctly whatever the argument plugin's getTitle()/title() method returns.

alayham’s picture

Here is what the plugin does for title()

  function title() {
    // There might be no valid argument.
    if ($this->argument) {
      $term = $this->termStorage->load($this->argument);
      if (!empty($term)) {
        return $term->getName();
      }
    }
    // TODO review text
    return $this->t('No name');
  }

I don't think this method is called in this context.

I am not an expert in views or D8, but I believe there might be something bigger behind this bug.

dawehner’s picture

Yeah for the custom integrations we had in d6/d7 there have been all kind of custom code. Now we deal with a generic entity reference field, I believe,
in which case there is no such integration. Maybe though for entity reference arguments we might want to provide that possiblity using $entity->label().

In case we want to get that route, we would also invent an update path which converts all the existing one to use the raw ID first.

berdir’s picture

Discussed this with @dawehner.

The mentioned code is only used for arguments on the taxonomy term table itself and the special node <-> term arguments.

This means we need a new special entity reference argument plugin that is set in core_field_views_data instead of the default numeric plugin which implements title similar to above.

Note that there's also titleQuery() in IndexTid which actually looks a lot better to me because it uses getTranslationFromContext(). We'll need a mix of those two. (a title() method that uses getTranslationFromContext()).

alayham’s picture

Thanks Berdir and dawehner. This looks more complex that I first thought.

My workaround to get the term name of the argument is:
1- Add the term name as a field, you can keep it hidden, and you might need to add a relationship for that in some complex setups.
2- add a header component, set it to "Use replacement tokens from the first row". then use the token for the term name inside that header.

Using this workaround I managed to get the term name where I wanted it, except in the block or page title.

tduong’s picture

Status: Active » Needs review
StatusFileSize
new2.59 KB

Added new plugin EntityTargetIdArgument and implemented title() method.

berdir’s picture

Issue tags: +Needs tests

We should add a comment to the $data that we're changing (something about providing a argument plugin that has a meaningful title() implementation.

We'll also need a test.

The only close thing that I could find is RolesRidArgumentTest, which uses a test_user_roles_rid test view.

We'll need something like that in taxonomy tests, with a node + term or so. Apparently we have no such test yet or we would have noticed when converting to entity_reference I guess.

tduong’s picture

Exported the view previously created (manual token test worked). Providing test coverage using this test view, but somehow it does not properly call our plugin. As discussed with Berdir it may be a missing schema bug, I'll do it asap.

Status: Needs review » Needs work

The last submitted patch, 10: token_replacement_tax_arg-2640994-10.patch, failed testing.

berdir’s picture

It doesn't work because the argument is broken and doesn't do anything. You always see all results.

That's because in your view, you used field_tags. That's from standard.profile. The test uses a different field name, see mockStandardInstall() in the parent. You need to update your view to use a field with that name.

tduong’s picture

Assigned: Unassigned » tduong
Status: Needs work » Needs review
StatusFileSize
new5.03 KB
new2.01 KB
new11.83 KB

Fixed test with the suggestion above, added a check in form.inc since it seems there is a "PHP Notice" in core.

Status: Needs review » Needs work

The last submitted patch, 13: token_replacement_tax_arg-2640994-13.patch, failed testing.

The last submitted patch, 13: token_replacement_tax_arg-2640994-13-test_only.patch, failed testing.

tduong’s picture

StatusFileSize
new452 bytes
new11.26 KB

Test to be run after this #2665202: PHP Notice bug due to the recent #2595613 commit issue is committed.

dawehner’s picture

This is looking pretty good. There are some remarks below.

  1. +++ b/core/includes/form.inc
    @@ -206,7 +206,7 @@ function template_preprocess_fieldset(&$variables) {
    -  if ($element['#title_display'] == 'invisible') {
    +  if (isset($element['#title_display']) && $element['#title_display'] == 'invisible') {
    

    What about adding some sane default value in \Drupal\Core\Render\Element\Fieldset instead?

  2. +++ b/core/modules/views/src/Plugin/views/argument/EntityTargetIdArgument.php
    @@ -0,0 +1,64 @@
    + * Argument handler for basic taxonomy tid.
    

    This doc needs to have some fix.

  3. +++ b/core/modules/views/src/Plugin/views/argument/EntityTargetIdArgument.php
    @@ -0,0 +1,64 @@
    +  function title() {
    +    // There might be no valid argument.
    +    if ($this->argument) {
    +      $entity = $this->entityTypeManager->getStorage($this->definition['target_entity_type_id'])->load($this->argument);
    +      if (!empty($entity)) {
    +        return $entity->label();
    +      }
    +    }
    +    // TODO review text
    +    return $this->t('No name');
    +  }
    

    What about implementing titleQuery() instead and support multiple entity IDs by that automatically?

  4. +++ b/core/modules/views/src/Tests/Plugin/EntityTargetIdArgumentTest.php
    @@ -0,0 +1,68 @@
    +    $this->drupalGet('/entity-tid-argument-test/2');
    +    $this->assertTitle('test: title ' . $this->term2->label() . ', input ' . $this->term2->id() . ' | Drupal');
    

    Once we support more than one entity ID, we should also expand the test coverage with a multiple example.

  5. +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_tid_argument.yml
    index 2efc08c..18e0809 100644
    --- a/core/modules/views/views.views.inc
    
    --- a/core/modules/views/views.views.inc
    +++ b/core/modules/views/views.views.inc
    
    +++ b/core/modules/views/views.views.inc
    +++ b/core/modules/views/views.views.inc
    @@ -732,6 +732,12 @@ function core_field_views_data(FieldStorageConfigInterface $field_storage) {
    

    Beside expanding views_views_inc I guess we also want to do the same stuff in EntityViewsData for entity reference fields?

tduong’s picture

Status: Needs work » Needs review
Related issues: +#2595613: '#title_display' => 'invisible' does not work for composite form elements
StatusFileSize
new1.32 KB
new11.38 KB

Feedback for @dawehner from #17:

1. that won't be in this patch anymore, because it will be fixed by #2595613: '#title_display' => 'invisible' does not work for composite form elements (see #53)
2. I've checked in other files and edited it like Argument handler to accept an entity target id. or what do you suggest ?
3. I've tried to implement this title() to load multiple entities but it does not work. I'm not sure but I guess it's because as in the previous patch it uses only a single entity, the $titles array that I've returned in title() now is not valid with the required array in Drupal\Core\Render\Element::children() or do I miss something ? How can I fix it ?
4. wait for the point 3. to be done
5. I'm quite new with these stuff and I'm not sure what you want to be done in EntityViewsData, can you give me some more details, please ?

Test will fail since the related issue is not fixed yet.

Status: Needs review » Needs work

The last submitted patch, 18: token_replacement_tax_arg-2640994-18.patch, failed testing.

dawehner’s picture

Priority: Major » Normal

@tim.plunkett, @effulgentsia @alexpott @xjm @cottser and @dawehner discussed that.
While we agreed that this is annoying, we don't think this is major, as it doesn't affect too many people. This doesn't mean we cannot fix it.
Thank you @tduong for heads up trying to fix it.

dawehner’s picture

Well I would have suggested to overload titleQuery() instead.
On top of that you are now using TaxonomyTerm::loadMultiple(), better use $entity_storage->loadMultiple()

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new5.57 KB
new13.16 KB

Rerolled. Uploaded patch:

  • implemented titleQuery() instead of title()
  • set break_phrase: true allowing url with multiple values for the extended test
  • extended test coverage for multiple entity IDs examples
    • test still fails because of the last assertion (url: /entity-tid-argument-test/1+2), I'll check it tomorrow
  • extended EntityViewsData
  • the fix in PathPluginBase is temporary because of a bug from a recent commit (#2598502: Double escaping in views attachment titles, see #14)

Status: Needs review » Needs work

The last submitted patch, 22: token_replacement_tax_arg-2640994-22.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB
new13.57 KB
  • fixed EntityTargetIdArgument to get queries with multiple ids either with , or +
  • expanded test coverage for all ids combinations possible
  • note there still is the temporary fix in PathPluginBase::getRoute()
tduong’s picture

I've noticed that in a manual test for /entity-tid-argument-test/1+2 the title I get is test: title tax1 + tax2, input 1 2, while in the test the result is title tax1 + tax2, input 1+2. Does someone have any idea which one is the correct one and where it is processed ?

My local instance:

  • create some terms
  • enable your new vocabulary in Reference Type in /admin/structure/types/manage/article/fields/node.article.field_tags
  • create some articles with some terms in Tags
  • create views adding field_tags as the contextual filter and override the title: test: title {{ arguments.field_tags_target_id }}, input {{ raw_arguments.field_tags_target_id }}
  • if you supply 1+2 as argument in the preview area you'll see "..., input 1 2" instead of "..., input 1+2" like in the test

Status: Needs review » Needs work

The last submitted patch, 24: token_replacement_tax_arg-2640994-24.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new3.33 KB
new12.89 KB

Fixed test.

Status: Needs review » Needs work

The last submitted patch, 27: token_replacement_tax_arg-2640994-27.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new597 bytes
new13.6 KB

Fixed PhpUnit test.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -527,7 +527,8 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt
             ];
             $views_field['field']['id'] = 'field';
    -        $views_field['argument']['id'] = 'numeric';
    +        $views_field['argument']['id'] = 'entity_target_id';
    +        $views_field['argument']['target_entity_type_id'] = $entity_type_id;
    

    This would result in differences exported views as it has a different plugin_id. As we don't have any settings for either, nothing really breaks, but should we write and update function? Is that even possible? Just resaving doesn't help, not until we also fix #2648956: Editing a view leaves old keys hanging, results in invalid schema

  2. +++ b/core/modules/views/src/Plugin/views/argument/EntityTargetIdArgument.php
    @@ -0,0 +1,61 @@
    +class EntityTargetIdArgument extends NumericArgument implements ContainerFactoryPluginInterface {
    

    I'm not sure about the name. I originally suggested this, but it's actually not really limited to the target_id column. Maybe EntityIdArgument or just EntityArgument?

    Also, we have large list of argument classes that could either be replaced completely by this new generic argument plugin or at least extend from it (although some extend from others like ManyOne). Many of those are for example missing the translation context thing and would not be displayed in the right translation. An incomplete list:

    * \Drupal\taxonomy\Plugin\views\argument\Taxonomy (is missing the translation context thing)
    * \Drupal\taxonomy\Plugin\views\argument\VocabularyVid
    * \Drupal\taxonomy\Plugin\views\argument\IndexTid
    * \Drupal\taxonomy\Plugin\views\argument\IndexTidDepth
    * \Drupal\user\Plugin\views\argument\RolesRid
    * \Drupal\comment\Plugin\views\argument\UserUid
    * \Drupal\node\Plugin\views\argument\Nid

    We could make a follow-up for those, but if we have to update views configurations, it might be easier to just do them in one go?

  3. +++ b/core/modules/views/src/Plugin/views/argument/EntityTargetIdArgument.php
    @@ -0,0 +1,61 @@
    +    foreach ($terms as $term) {
    +      $titles[$term->id()] =\Drupal::entityManager()->getTranslationFromContext($term)->label();
    +    }
    

    minor coding standard issue there.

    If we inject the entity type manager, then we should also inject entity.repository for this method.

    Also, you should rename $terms and $term to $entities and $entity. It's no longer just about terms.

  4. +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
    @@ -921,7 +921,7 @@ protected function assertLanguageField($data) {
         $this->assertEquals('numeric', $data['filter']['id']);
    -    $this->assertEquals('numeric', $data['argument']['id']);
    +    $this->assertEquals('entity_target_id', $data['argument']['id']);
    

    you should also check the new target_entity_type_id property that we're adding.

  5. +++ b/core/modules/views/views.views.inc
    @@ -735,6 +735,12 @@ function core_field_views_data(FieldStorageConfigInterface $field_storage) {
    +    // Provide an argument plugin that has a meaningful title() implementation
    +    // getting the node label instead of its ID as implemented in
    +    // \Drupal\taxonomy\Plugin\views\argument\Taxonomy::title().
    

    This comment should be updated and shortened and also duplicated into EntityViewsData.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new13.96 KB
new5.37 KB

Rerolled.

1) discussed with berdir: wait for more details from @bedir and @dawehner
2) renamed class as EntityArgument/-Test, wait for more details for the rest
3-5) fixed

berdir’s picture

Discussed with @dawehner:

1. We need at least an update function that clears the views data cache. Views::viewsData()->clear();
2. We move this to a follow-up, please open one .

tduong’s picture

Created follow up. Added views_update_8005() in views.install, just clear cache line, will work on this tomorrow.

dawehner’s picture

+++ b/core/modules/views/views.install
@@ -347,3 +348,11 @@ function views_update_8004() {
+  // Update views.
+  Views::viewsData()->clear();

Actually an empty update function is enough. The cache is cleared at the end anyway.

dawehner’s picture

Issue tags: +DrupalBCDays

.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tduong’s picture

Painful rebase switching branch to 8.1.x... I saw that meanwhile an update_8005 function has been committed

/**
 * @addtogroup updates-8.1.0
 * @{
 */

/**
 * Clear views data cache.
 */
function views_update_8005() {
  // Empty update function to rebuild the views data.
}

/**
 * @} End of "addtogroup updates-8.1.0".
 */

so I guess it is enough also for us (?)

Let's see first if I've rebased everything right...

dawehner’s picture

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

so I guess it is enough also for us (?)

I agree its not ideal.

But let's please keep this new update function, there might be people which ran their updates in the meantime.

The last submitted patch, 37: token_replacement_tax_arg-2640994-37-test_only.patch, failed testing.

tduong’s picture

Sorry, do you mean that I should add also our update function, another empty views_update_8006() ?

berdir’s picture

Yes, exactly.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new362 bytes
new3.85 KB
new14.42 KB

Added empty update function 8102 since it is for 8.1.x-dev and it is supposed to be the second update function. Didn't change the number of the first one though to not to break anything.

The last submitted patch, 42: token_replacement_tax_arg-2640994-42-test_only.patch, failed testing.

dawehner’s picture

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

We no longer needs tests, yeah!

+++ b/core/modules/views/src/EntityViewsData.php
@@ -532,7 +532,10 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt
         $views_field['field']['id'] = 'field';
-        $views_field['argument']['id'] = 'numeric';
+        // Provide an argument plugin that has a meaningful titleQuery()
+        // implementation getting the node label.
+        $views_field['argument']['id'] = 'entity_target_id';
+        $views_field['argument']['target_entity_type_id'] = $entity_type_id;

Given that we change the used plugin ID, we should also reference that in the configured views ... as this is will be used for config schema validation, so we need a dedicated update function for that.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new1.74 KB
new3.85 KB
new15.93 KB

Added an update function for configured views plugin ID with entity_reference field type.

dawehner’s picture

Sorry :( I fear we aren't ready yet.

I'm a bit sceptical whether this actually works now ...

+++ b/core/modules/views/src/EntityViewsData.php
@@ -532,7 +532,10 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt
         $views_field['field']['id'] = 'field';
-        $views_field['argument']['id'] = 'numeric';
+        // Provide an argument plugin that has a meaningful titleQuery()
+        // implementation getting the node label.
+        $views_field['argument']['id'] = 'entity_target_id';
+        $views_field['argument']['target_entity_type_id'] = $entity_type_id;
         $views_field['filter']['id'] = 'numeric';
         $views_field['sort']['id'] = 'standard';

+++ b/core/modules/views/views.install
@@ -361,5 +363,43 @@ function views_update_8005() {
+ * Update configured views plugin ID.
+ */
+function views_update_8103() {
+  $config_factory = \Drupal::configFactory();
+
+  // Loop through any view, on 'arguments', to update the plugin IDs.
+  foreach ($config_factory->listAll('views.view') as $config_name) {
+    $config = $config_factory->getEditable($config_name);
+    /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
+    $field_storage = FieldStorageConfig::load($config->getStorage());

This code deals with base fields, but the update function deals with configurable fields. Do we need to do the same kind of change in \core_field_views_data?

Status: Needs review » Needs work

The last submitted patch, 45: token_replacement_tax_arg-2640994-45.patch, failed testing.

The last submitted patch, 45: token_replacement_tax_arg-2640994-45-test_only.patch, failed testing.

tduong’s picture

This code deals with base fields, but the update function deals with configurable fields.

how should I fix it ?

Do we need to do the same kind of change in \core_field_views_data?

actually we have already provided it in there:

+++ b/core/modules/views/views.views.inc
@@ -735,6 +735,11 @@ function core_field_views_data(FieldStorageConfigInterface $field_storage) {
+    // Provide an argument plugin that has a meaningful titleQuery()
+    // implementation getting the node label.
+    $data[$table_name][$field_name . '_target_id']['argument']['id'] = 'entity_target_id';
+    $data[$table_name][$field_name . '_target_id']['argument']['target_entity_type_id'] = $target_entity_type_id;

or do you mean something else ?

dawehner’s picture

Lol, I was indeed too lazy to scroll to the end of the patch. But still, you need to take into account base fields as well in your update hook.

berdir’s picture

  1. +++ b/core/modules/views/views.install
    @@ -361,5 +363,43 @@ function views_update_8005() {
    + */
    +function views_update_8102() {
    +  // Empty update function to clear the views data cache.
    +}
    +
    +/**
    

    we don't need an empty function if we also add a real update function. drop this and rename the other to 8102

  2. +++ b/core/modules/views/views.install
    @@ -361,5 +363,43 @@ function views_update_8005() {
    + * Update configured views plugin ID.
    

    this could be a bit more specific and specificy entity reference argument plugin IDs or so.

  3. +++ b/core/modules/views/views.install
    @@ -361,5 +363,43 @@ function views_update_8005() {
    +    /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
    +    $field_storage = FieldStorageConfig::load($config->getStorage());
    

    Yeah, that doesn't make sense :)

    Whta you need to do instead is loop over the fields and inside, for each key, check if that is a field and if it is an entity reference field.

    Not sure what the best way to do that is. Additionally, it is possible that someone is altering views data to something else.

    Maybe we need to change this to a post update function and then compare it with the actual views data?

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB
new15.92 KB

Aaah ok, now I get what you meant.. still not sure how to fix it. I'll check it with @Berdir after lunch :)

Status: Needs review » Needs work

The last submitted patch, 52: token_replacement_tax_arg-2640994-52.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new3.48 KB
new17.15 KB

Added post_update (need implementation), tried to update the views data update function. Still work in progress...

tduong’s picture

StatusFileSize
new6.27 KB
new18.24 KB

Moved the update function code into the post_update one. Still cannot get the values I need to access the views data, tried to get the views through drupal_get_path() but it seems like there are no results for the modules we need (?) Can anyone help me, please ?

dawehner’s picture

  1. +++ b/core/modules/views/src/EntityViewsData.php
    @@ -532,7 +532,10 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt
    +        // implementation getting the node label.
    

    let's use entity label here, because this is not just about nodes.

  2. +++ b/core/modules/views/views.install
    @@ -361,5 +363,40 @@ function views_update_8005() {
     /**
    + * Just a test update function
    + */
    +function views_update_8103() {
    

    I am confused

  3. +++ b/core/modules/views/views.install
    @@ -361,5 +363,40 @@ function views_update_8005() {
    +  foreach ($modules as $module) {
    +    $config_dir = drupal_get_path('module', $module) . '/test_views';
    +    if (!is_dir($config_dir) || !$module_handler->moduleExists($module)) {
    +      $exist = 'nope';
    +      continue;
    +    }
    

    I think we want to iterate over all views using a similar method as above in that file:

        $config_factory = \Drupal::configFactory();
    
    foreach ($config_factory->listAll('views.view.') as $view_config_name) {
    

    This code example here would just update test files, not sure we really want that.

  4. +++ b/core/modules/views/views.post_update.php
    @@ -180,5 +180,62 @@ function views_post_update_taxonomy_index_tid() {
    +      foreach ((array) $config->get('display.' . $display_id . '.display_options.arguments') as $argument_id => $argument_config) {
    +        //var_dump($argument_id);
    +        // This update deals with the Entity reference field type.
    +        if (isset($argument_config['type']) && $argument_config['type'] == 'entity_target_id') {
    

    a) Don't you want to check for 'plugin_id' instead of 'type'?

    b) IMHO we should apply these updates ALSO in the case when the configuration used to point to taxonomy arguments?

tduong’s picture

StatusFileSize
new3.38 KB
new18.16 KB

Trying to do some progress but still cannot get the data that I need... here is just my current test patch

Status: Needs review » Needs work

The last submitted patch, 57: token_replacement_tax_arg-2640994-57.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new3.35 KB
new18.16 KB

Just a reroll. No conflict encountered.

Status: Needs review » Needs work

The last submitted patch, 59: token_replacement_tax_arg-2640994-59.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new16.17 KB
new4.49 KB

Ok, trying to get this back on track. Cleaned up the update code, something like this should work but we have no test view, need to ensure one exists first.

Status: Needs review » Needs work

The last submitted patch, 61: token_replacement_tax_arg-2640994-61.patch, failed testing.

berdir’s picture

Version: 8.1.x-dev » 8.2.x-dev
StatusFileSize
new16.17 KB

does it apply with 8.2?

berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 63: token_replacement_tax_arg-2640994-61.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new25.32 KB
new10.92 KB

Here's a test using a similar test view as the one already added but using the existing field_tags field, also renamed a bunch of stuff.

dawehner’s picture

Nice work in general!

  1. +++ b/core/modules/views/src/Plugin/views/argument/EntityArgument.php
    @@ -0,0 +1,67 @@
    + */
    +class EntityArgument extends NumericArgument implements ContainerFactoryPluginInterface {
    +
    

    Can we open a general followup to address the fact that entity types might have string IDs?

  2. +++ b/core/modules/views/src/Plugin/views/argument/EntityArgument.php
    @@ -0,0 +1,67 @@
    +    foreach ($entities as $entity) {
    +      $titles[$entity->id()] = $this->entityRepository->getTranslationFromContext($entity)->label();
    +    }
    

    I'm wondering whether this should take into account the 'rendering_language' settings in tviews.

  3. +++ b/core/modules/views/src/Tests/Plugin/EntityArgumentTest.php
    @@ -0,0 +1,73 @@
    +
    +
    

    Hyper-nitpick: two empty lines

  4. +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
    @@ -1038,7 +1033,8 @@ protected function assertLanguageField($data) {
    diff --git a/core/modules/views/views.install b/core/modules/views/views.install
    
    diff --git a/core/modules/views/views.install b/core/modules/views/views.install
    index 30ac79c..bd21f37 100644
    
    index 30ac79c..bd21f37 100644
    --- a/core/modules/views/views.install
    
    --- a/core/modules/views/views.install
    +++ b/core/modules/views/views.install
    
    +++ b/core/modules/views/views.install
    +++ b/core/modules/views/views.install
    @@ -5,6 +5,9 @@
    
    @@ -5,6 +5,9 @@
      * Contains install and update functions for Views.
      */
     
    +use Drupal\Core\Config\FileStorage;
    +use Drupal\views\Views;
    +
     /**
      * Implements hook_install().
      */
    

    This seems out of scope now.

berdir’s picture

Assigned: tduong » Unassigned
StatusFileSize
new24.96 KB
new843 bytes

1. Sure, we can ;) Should we name this class EntityArgumentNumeric then, so we can add an EntityArgumentString later?

2. I had a quick look but I think that is not possible. \Drupal\views\Entity\Render\EntityTranslationRendererBase::getLangcode() depends on a result row, we don't have that here. We could pick th first, but that could be entirely wrong. That entity might not have a translation but the term does. I think this is fine for now.

3. Oh no! How could I? :)

4. I love how dreditor manages to end up with 8x "core/modules/views/views.install" in that snippet ;)

I'm still unsure about doing #30.2 here (using this new class in those existing classes to avoid duplicate code) or not. But I'm going to try that now, we can still move it to a follow-up.

berdir’s picture

Impressive how much duplicate code we have in those argument plugins. This just removes the code, we could also officially deprecate them and switch the code that specified them directly to entity_target_id (which as this shows, doesn't really make sense anymore as a name).

Most of those plugins are actually used for the ID field of the base table. Which is something that we could now do generically as well. But again, definitely risking going too far here. Deleting all that code is just so much fun. There are even a few more, that could use a string version (RolesRid, Type in node, VocabularyVid is actually incorrectly extending from NumericArgument).

PS: My personal favorite is Fid::titleQuery().

Status: Needs review » Needs work

The last submitted patch, 69: token_replacement_tax_arg-2640994-69.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jonathanshaw’s picture

Issue tags: +Needs reroll
jofitz’s picture

Assigned: Unassigned » jofitz

I'll take a look at this...

jofitz’s picture

Assigned: jofitz » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new39.9 KB

Re-rolled.

jonathanshaw’s picture

Could you add interdiff?

jofitz’s picture

StatusFileSize
new2.07 KB
new39.88 KB

It is not possible to create an interdiff because it is a relatively complicated re-roll.

1 out of 2 hunks FAILED
interdiff: Error applying patch1 to reconstructed file

Also I managed to forget the new array syntax [] so here's another patch (with an interdiff for this change).

The last submitted patch, 74: 2640994-74.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 76: 2640994-75.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Ben Buske’s picture

Status: Needs work » Needs review
StatusFileSize
new39.73 KB

rerolled for 8.4.0

Status: Needs review » Needs work

The last submitted patch, 80: 2640994-80.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lukasss’s picture

I think the issue is more global than just taxonomy.
I have nowhere this is not working.
I have to do as recommended here:
https://drupal.stackexchange.com/questions/205758/how-do-i-override-the-...

Ben Buske’s picture

StatusFileSize
new39.86 KB

reroll for 8.5. Sorry, I lost track of this ticket.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

feyp’s picture

StatusFileSize
new20.08 KB

Reroll of #84 for 8.6

cbrody’s picture

This is still an issue in 8.7.4; the patch in #86 results in

Fatal error: Class 'Drupal\views\Plugin\views\argument\EntityArgument' not found in /Users/chris/Sites/devdesktop/tomorrowscities/web/core/modules/node/src/Plugin/views/argument/Nid.php on line 12
lukasss’s picture

Version: 8.6.x-dev » 8.8.x-dev

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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: 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.

colan’s picture

Title: Token replacement for views taxonomy arguments not working » Label token replacement for views entity reference arguments not working

Updated title, as this applies to all entity references (not just taxonomy).

#87: The problem with #86 is that it's missing all of the new files so it's a bad patch. I'm not sure which would be easier:

  • Rerolling #84 for 9.1 or
  • adding the missing files to #86 and then rerolling that.

I'd be inclined to start with #84 because it seems more trustworthy.

Related: I postponed #2912332: Allow entity reference views arguments to display the entity label in titles and summaries on this one.

nikitagupta’s picture

Assigned: Unassigned » nikitagupta
nikitagupta’s picture

Status: Needs work » Needs review
StatusFileSize
new40.14 KB

Rerolled patch #84

Status: Needs review » Needs work

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

colan’s picture

#93: Thanks for working on this! Which patch are you working from?

If possible, please provide interdiffs. I know this may not always be possible due to different baselines.

nikitagupta’s picture

Assigned: nikitagupta » Unassigned
nikitagupta’s picture

@colan worked on #84 and interdiff is not possible due to different core versions.

osopolar’s picture

There is a workaround in #7.

Another way to work around the problem might be using preprocess hooks. For example, to set the node title in a views block on a node page. I guess, for taxonomy it would be similar.

/**
 * Implements hook_preprocess_HOOK() for block templates.
 */
function focaer_preprocess_{BLOCK-ID}(&$variables) {
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    $variables['label'] = 'Artikel von ' . $node->label();
  }
}

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.

raman.b’s picture

StatusFileSize
new40.67 KB
new6.03 KB

Not sure why ViewExecutableTest::testArgumentValidatorValueOverride is failing

raman.b’s picture

StatusFileSize
new40.76 KB
new2.04 KB
raman.b’s picture

Status: Needs work » Needs review

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.

fernly’s picture

Tested with Drupal 9.1.10:

Patch #93: working
Patch #101: not working

chrisgross’s picture

Has anybody been able to successfully get this patch working on 8.9? I've tried to re-roll it myself, and it does apply, but I keep getting the following error when I try to view a page with a contextual filter: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 150 of /var/www/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php). This is a really frustrating bug that I need to fix but we're not quite ready for D9 yet. I haven't had luck with any workarounds.

chrisgross’s picture

Has anyone successfully tested this on 9.2? The latest patches do not apply, but even after I manually update the files that failed to patch and then run update.php, this is still not working for me. My title arguments ( arguments.field_tags_target_id ) in views are still rendered as ids.

chrisgross’s picture

A sample workaround for this until it gets fixed might look like this. In this example, I want to display the tag name in a text area if my view shows no results. Since views is rendering the tag id instead of the name like it's supposed to, I have to load the term name and replace the entire token with it. This is pretty sloppy, but it works. Hopefully this bug can be fixed. Currently, any views designed this way in 7 will not work in 8/9.

function MY_MODULE_views_pre_render($view) {
  if ($view->id() == 'VIEW_NAME' && $view->current_display == 'DISPLAY_NAME' && $view->empty['area_text_custom'] && $view->args[0] > 0) {
    $term = Drupal\taxonomy\Entity\Term::load($view->args[0]);
    $term_name = $term->get('name')->value;
    $content = &$view->empty['area_text_custom']->options['content'];
    $content = str_replace('{{ arguments.field_tags_target_id }}', $term_name, $content);
  }
}
catch’s picture

Issue tags: +Bug Smash Initiative
StatusFileSize
new45.71 KB

Straight re-roll since this no longer applied to 9.3.x. Haven't reviewed yet.

catch’s picture

StatusFileSize
new40.81 KB

9.2.x version for manual testing.

catch’s picture

StatusFileSize
new39.78 KB
new44.72 KB

Another re-roll.

Status: Needs review » Needs work

The last submitted patch, 110: 2640994-110.patch, failed testing. View results

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.

volker23’s picture

Patch from #110 does not apply anymore on 9.3.2.

alex.bukach’s picture

@catch @raman.b could you guys explain why you started using $this->definition['entity_type'] as entity type instead of $this->definition['target_entity_type_id']? Looks like target_entity_type_id is the actual referred entity type while entity_type is the base entity type, and till #93 target_entity_type_id was used.

ankithashetty’s picture

Status: Needs work » Needs review
StatusFileSize
new44.77 KB
new3.93 KB

Rerolled the patch in #110, thanks!

Status: Needs review » Needs work

The last submitted patch, 115: 2640994-115.patch, failed testing. View results

alex.bukach’s picture

Status: Needs work » Needs review
StatusFileSize
new40.63 KB
new40.69 KB
new40.69 KB
new13.11 KB

In view of my notes above here's a re-roll of Berdir's patch #69.

The last submitted patch, 117: drupal-2640994-117-9.2.patch, failed testing. View results

The last submitted patch, 117: drupal-2640994-117-9.3.patch, failed testing. View results

alex.bukach’s picture

StatusFileSize
new42.99 KB

Probably the issue is that there are two type of arguments: entity ID (like "nid") and referred entity ID (like e.g. "field_term_target_id"). The initial patches tried to handle the second case, then patches tried to handle the first case. Looks like we should have handle these two cases separately using two different argument types. Here's an attempt to do that.

Status: Needs review » Needs work

The last submitted patch, 120: drupal-2640994-118-9.4.patch, failed testing. View results

alex.bukach’s picture

StatusFileSize
new44.44 KB
alex.bukach’s picture

Status: Needs work » Needs review
StatusFileSize
new44.42 KB
new44.35 KB
el1_1el’s picture

9.3.x in 123 working for me. Thanks!

chrisgross’s picture

I can also confirm that the patch in #123 does finally work as well.

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.

MihaiMiculescu’s picture

This may or may not be right on the spot, but at least related.
I'm on Drupal 9/Commerce Kickstart 3 installed in Romanian only.
I created a view showing product variations only (entities, not nodes) that bear all the same tag. It's a page with the address /taxonomy/term/%
I got inspired by this comment and came up with this no-code solution :
-Added a hidden field with the tag rendered as label and link to the product variation.
-Then, in Relationships, I added the relationship between tag name and tag ID. Marked as required.
-In the contextual filter I enabled the use of the relationship. This triggered the availability of {{ arguments.tid }} for me to use for overwriting the page title, while using tag ID as validation criterion.
And voilà, the tag name instead of tag ID appears in the page title.
I just hope that sharing with you my perspective as a user, not developer, helps.

nicxvan’s picture

The most recent patch applies but does not work for me on 9.4.5

technoveltyco’s picture

I confirm that the patch #122 applies correctly and fix the issue in Drupal Core 9.4.5.

I tested it in a view block that requires to display the author name in its title. The view has a contextual filter of the author field and it is setup to use the token to resolve from the content id to the node title as shown in the attached screenshot

Thanks @alex-bukach

technoveltyco’s picture

Status: Needs review » Reviewed & tested by the community
quietone’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

The issue summary here is simply a statement of the problem. The patch is > 40K and adds schema and a post_update function so let's have a description of the changes in the IS. I see an after screenshot in #129 so it seems that before and after screenshots should be added to the Issue Summary as well. I have added the standard template so it can be completed.

comment #128 states that the patch does not work on Drupal 9.4.5 so it does not seem ready for an RTBC.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new44.49 KB

Patch 122 didn't apply correctly, I have re rolled the patch for 9.5.x

alex.bukach’s picture

Status: Needs review » Needs work

@ameymudras I did not check your patch thoroughly, but the last lines in the patch definitely should be inside a loop (like in #122) while they are outside in your patch. Could you please check it and attach interdiff?

anchal_gupta’s picture

StatusFileSize
new46.86 KB
new840 bytes

Fixed custom command failed error. please review

alex.bukach’s picture

@Anchal_gupta both yours (#135) and @ameymudras (#133) patches contain issues I pointed out in #134. Could you please fix them and attach an interdiff between your patch and #123?

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new44.53 KB
new1.73 KB

Thanks @Alex, I have fixed the issue and fixed phpcs issues

Status: Needs review » Needs work

The last submitted patch, 137: 2640994-137.patch, failed testing. View results

pameeela’s picture

Patch in #122 worked for me on 9.4.7. No manual steps required, just applied the patch.

Before:

After:

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.

nicxvan’s picture

The patch in 137 works for me

ravi.shankar’s picture

StatusFileSize
new40.06 KB
new7.09 KB

Added reroll of patch #137 on Drupal 10.1.x.

pradhumanjain2311’s picture

Status: Needs work » Needs review
StatusFileSize
new17.55 KB
new1.85 KB

Try to fix cs errors.

ameymudras’s picture

StatusFileSize
new39.9 KB

Trying to fix the above issue

ameymudras’s picture

StatusFileSize
new40 KB

My working branch was out of sync which caused the above error, trying to fix the same

ameymudras’s picture

StatusFileSize
new40 KB
new889 bytes

Fixing phpcs issue with the above patch

Status: Needs review » Needs work

The last submitted patch, 146: 2640994-146.patch, failed testing. View results

ravi.shankar’s picture

StatusFileSize
new40.01 KB
new1.46 KB

Tried to address tests of patch #146.

rgnyldz’s picture

#148 did not apply with drupal 10.0.9 and PHP 8.1

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.

nicxvan’s picture

StatusFileSize
new39.91 KB

This should work for 10.x

nathan tsai’s picture

#151 successfully applied for me.

Will follow up if it breaks my website ;)

lendude’s picture

The test failure is in one of the new tests, so that certainly needs fixing.

+++ b/core/modules/views/views.post_update.php
@@ -37,3 +39,33 @@ function views_removed_post_updates() {
+function views_post_update_views_data_argument_plugin_id() {

Ideally this should use the ViewsConfigUpdater and the update patterns used for that, so we also update any newly imported Views coming from modules and install profiles

But this is looking pretty great otherwise!

alex.bukach’s picture

Assigned: Unassigned » alex.bukach
Status: Needs work » Needs review
StatusFileSize
new39.97 KB
new39.98 KB

Rerolled #122 for 10.1.x and 11.x.

alex.bukach’s picture

StatusFileSize
new39.97 KB

Selected correct version.

Status: Needs review » Needs work

The last submitted patch, 155: drupal-2640994-154-10.1.x.patch, failed testing. View results

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

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

dww’s picture

Assigned: alex.bukach » Unassigned
Issue summary: View changes
Issue tags: -Needs issue summary update

I keep running into this bug. Due to attributes vs. annotations, this doesn't backport cleanly, so I opened new branches and MRs for 10.3.x and 10.2.x. Meanwhile, hiding all the old patches in favor of the 3 MRs.

I updated the summary. Hope that's clear enough for review.

Haven't looked into pipeline failures, so leaving at NW.

Let's get https://git.drupalcode.org/project/drupal/-/merge_requests/7091 passing ASAP. I can backport appropriate changes to the other branches / MRs. But they're here for now for other folks like me that need these fixed on 10.2.x sites.

dww’s picture

Issue summary: View changes

Embedding the screenshots from #149 into the summary, too, so we don't need those from anyone else. 😅

Thanks,
-Derek

dww’s picture

Pushed a few more commits to hopefully get more of the pipeline stages passing.

Meanwhile, one of the test failures is a new deprecation test added for #2765297: Return translated term name on views "Content: Has taxonomy term ID (with depth)". Since we haven't shipped 10.3.x, can we remove that test entirely? This is probably a sign we need to be more careful about BC? Adding as related.

dww’s picture

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

Addressed #153 and converted the post_update to use ViewsConfigUpdater. However, EntityArgumentUpdateTest.php was still failing locally. Then determined that the fixture that test is using was based on a stale Views schema. I re-created the fixture view on a clean 10.2.x site, and now that test is passing locally. Pushed fixes to all branches. Let's see what the bot thinks now...

dww’s picture

Priority: Normal » Major

Bumping this to major since I believe this qualifies under:

Render one feature unusable with no workaround

https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...

The entire feature of setting display titles based on argument values converted to labels is broken, and AFAICT there's no workaround.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 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.

dww’s picture

Status: Needs work » Needs review
Related issues: +#3441844: Set budgets rather than exact numbers of asset size assertions

Via Slack, @catch pointed me to #3441844: Set budgets rather than exact numbers of asset size assertions. Rebased the 11.x and 10.3.x MRs so hopefully that should solve the FunctionalJS failures so far. 🤞

Meanwhile, I started a draft CR: https://www.drupal.org/node/3441945

Back to NR...

dww’s picture

Issue summary: View changes

Bah, the validatable config job is such a PITA. For a few weeks, it was failing to find a valid version of drush to install. Now it's complaining about this:

Installing Drupal
In install.core.inc line 966:
                                                                               
  Resolve all issues below to continue the installation. For help configuring  
   your database server, see the <a href="https://www.drupal.org/docs/install  
  ing-drupal">installation handbook</a>, or contact your hosting provider.<ul  
  ><li>The database server version <em class="placeholder">3.40.1</em> is les  
  s than the minimum required version <em class="placeholder">3.45</em>.</li>  
  </ul>                                                                        

I don't have time for this. 😂 I'm going to ignore that for now, and I hope everyone else does, too. Crossing that off from the summary.

So this is really ready for review now. Would love to see this finally smashed, ideally for 10.3.x. I suspect this is probably too potentially disruptive for a 10.2.x backport, but I'm going to keep that MR up to date since I definitely need this working on some 10.2.x sites.

Thanks!
-Derek

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new9.24 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.

dww’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +no-needs-review-bot

I don't know what the bot is doing, but it's confused, so turning it off from this issue.

I realized we don't want to remove ViewsArgumentDeprecationTest, we want to fix it. 😅 I moved the deprecation dance to EntityArgument, so it now supports all the old legacy ways it might be instantiated / used since it's replacing all the other core classes. Updated ViewsArgumentDeprecationTest to trigger all the new deprecations and check for the right ones. I think we should edit the CR from #2765297: Return translated term name on views "Content: Has taxonomy term ID (with depth)" (https://www.drupal.org/node/3427843) to only talk about IndexTidDepth since the Taxonomy one is now gone.

The 10_2_x version safely handles all the legacy stuff but throws no deprecation notices.

Meanwhile I updated the CR here with the full explanation of all the new BC stuff: https://www.drupal.org/node/3441945 Updated the API changes section of the summary.

dww’s picture

Hrm, #3317378: [random test failure] Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews random fail seems to keep happening, or a new problem has arisen, or something. But WidgetViewsTest is randomly failing a lot right now, both on the bot, and locally, with or without this MR branch checked out. 😢

Hopefully that doesn't turn into a huge time-sink.

Meanwhile, I opened 1 thread (in 7091) about the only thing left in this MR that I'm concerned about. Feedback and reviews most welcome. I think we're darn close to RTBC now. 😅 Phew!

Thanks,
-Derek

dww credited kim.pepper.

dww’s picture

Issue summary: View changes

Thanks for the reviews! Crediting kim.pepper and Lendude.

Lendude asked about the difference between EntityArgument vs. EntityReferenceArgument. I wasn't sure. 😂 It was introduced at comment #120. I tried to remove the distinction and make everything use EntityArgument, but then Kernel/ViewExecutableTest::testArgumentValidatorValueOverride() started failing (see pipeline job 1377453):

1) Drupal\Tests\views\Kernel\ViewExecutableTest::testArgumentValidatorValueOverride
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    '{{ arguments.uid }}' => '0I[">&1Z'
+    '{{ arguments.uid }}' => ''
     '{{ raw_arguments.uid }}' => '1'
 )

The test view argument definition ( see core/modules/views/tests/modules/views_test_config/test_views/views.view.test_argument_dependency.yml) seems weird:

        uid:
          id: uid
          table: node_field_revision
          field: uid
          relationship: none
...
          entity_type: node
          entity_field: uid
          plugin_id: numeric

Why entity_type: node if this is pointing to a user? I don't fully understand the use of entity_type in existing definitions...

So maybe it's safer (if a little clumsy) as two separate plugins. Although should one extend the other? Or perhaps we could use one plugin, but make sure it uses target_entity_type_id not entity_type?

For now, reverted the commits to unify the two, and instead pushed docs for both. All the relevant tests are passing locally again. The bot agrees, phew.

Meanwhile, per @catch in #d11readiness the 11.x branch is really 11.x now. We definitely need the separate MRs here. I cleaned up the 11.x MR to remove the deprecation tests and BC layer from EntityArgument. All that only lives in !7571 now. The 10.2.x MR (!7572) has the silent BC layer.

dww’s picture

Opened #3442227: Use labels in Views argument summaries for entity references to help resolve the last of the threads, keep the scope smaller in here, and finish the job that was started at #2912332: Allow entity reference views arguments to display the entity label in titles and summaries.

I believe this is RTBC, but obviously someone else will have to say so at this point. 😂

Thanks!
-Derek

smustgrave’s picture

Status: Needs review » Needs work

Can the MRs be cleaned up?

smustgrave’s picture

dww’s picture

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

Not sure what you mean. The ones I opened are very clean. 😂 I don’t have edit access to 7091, so the title and description are lacking, but does that matter? The summary explains what all 3 are for.

smustgrave’s picture

11.x has consistent functional test failure.

dww’s picture

Issue summary: View changes

Ahh, thanks. The 11.x MR was failing due to #3442172: Remove the 9.4 database dump fixtures from 11.x. 😅 Pushed a commit to use the 10.3.0 fixture instead of 9.4.0. That works locally in the 10.3.x MR. My local can't run 11.x ATM. 😂 Also rebased both MRs to latest 11.x and 10.3.x core. We should be all green again. 🤞

dww’s picture

Issue summary: View changes
dww’s picture

Pipelines are all green again, except the functional JS random fail in the 10.2.x MR mentioned above. I doubt the RMs are actually going to backport this to 10.2.x, and that MR is mostly for folks to patch their own live sites with until 10.3.0 is out and they can upgrade to it...

dww’s picture

The 11.x branch needed a rebase (with some fairly trivial conflicts) due to #3442365: Removed deprecated code in taxonomy module

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

@dww posted about this in #bugsmash so came here.

So following the steps to reproduce I was able to see the issue at hand.

Ran the test-only feature, large output so won't paste here, but here's the link https://git.drupalcode.org/issue/drupal-2640994/-/jobs/1409783

Applied a small nitpicky suggestion for a return type.

Applying the MR the issue does appear to be addressed.

The 1 thread got a response, so believe this is good to go.

dww’s picture

Thanks for the reviews and RTBC! I pushed the bool return type to ViewsConfigUpdater::needsEntityArgumentUpdate() to both 10.3.x and 10.2.x MRs. Thanks for spotting that.

pravesh_poonia’s picture

Applied MR-7572, it looks correct now

quietone’s picture

Title: Label token replacement for views entity reference arguments not working » Fix label token replacement for views entity reference arguments

alexpott changed the visibility of the branch 2640994-10_2_x-label-token-replacement to hidden.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The 11.x MR needs work due to changes in the ViewsConfigUpdater... I think we need to trigger deprecations from the ViewConfigUpdater when it is fixing a view during preSave that's not done as part of the post update. This way modules will know that they have to update their shipped content.

dww’s picture

Status: Needs work » Needs review

Rebased the 11.x MR to resolve conflicts.

@alexpott: Not sure what you mean with this:

I think we need to trigger deprecations from the ViewConfigUpdater when it is fixing a view during preSave that's not done as part of the post update. This way modules will know that they have to update their shipped content.

Sounds like scope creep to me. I don't want to be rewriting ViewConfigUpdater to add new functionality like this to try to fix this bug. Can we address that in a follow-up?

Thanks,
-Derek

dww’s picture

Status: Needs review » Reviewed & tested by the community

I asked in #bugsmash for help on this. @catch pointed me to #3442395: ckeditor5 and editor module test config exports/stubs rely on hook_editor_presave() bc layers, but that issue has nothing to do with ViewsConfigUpdater. I still don't exactly understand what's being asked of me.

Views is doing this:

function views_view_presave(ViewEntityInterface $view) {
  /** @var \Drupal\views\ViewsConfigUpdater $config_updater */
  $config_updater = \Drupal::classResolver(ViewsConfigUpdater::class);
  $config_updater->updateAll($view);
}

@alexpott, are you proposing we should change the API for ViewsConfigUpdater::updateAll() to take a 2nd argument to determine if we're being called from presave or post_update? Or do you propose that views_view_presave() checks the return value from ViewsConfigUpdater::updateAll() and if it ever gets back TRUE it should always trigger a deprecation?

Can we pretty please move all such complications to a dedicated follow-up, and fix this before the 10.3.0-beta1 ships? I still fail to see why this poor bug needs to be the one to deal with all that additional functionality.

Tentatively moving back to RTBC to get more committer eyes on this.

Thanks,
-Derek

dww’s picture

Status: Reviewed & tested by the community » Needs review

I got a bit more clarity from @catch on what's expected here. I pushed some commits to the 11.x and 10.3.x MRs to trigger deprecations when ViewsConfigUpdater::processEntityArgumentUpdate() changes a view outside of post_update. I'm not sure on the wording of the deprecation message, that could use another pair of eyes. Also unclear if we "need" tests that this deprecation plumbing works as expected. I sure hope that's not my responsibility here. 😅

I'll keep an eye on the pipelines to make sure I didn't break anything, but I hope this is now actually RTBC.

dww’s picture

Wow, what a colossal PITA. 😆 Guess it's good I jumped through all those hoops, since:

  1. There were indeed some test views with stale argument plugin definitions that needed to be manually fixed, including the view for testing this new functionality. 😂
  2. EntityArgumentUpdateTest was making some slightly bogus assertions.

However, I had to completely rewrite ViewsConfigUpdater::processEntityArgumentUpdate() to operate on entire View entities, instead of using all the per-handler plumbing we've got. To my great dismay, if you copy the existing patterns, ViewsConfigUpdater process functions make a bunch of changes to handler config, then try to save the view, but that instantiates another ViewsConfigUpdater object (this time, with deprecations enabled) to do all the work again. 🤯 So apparently, The Right Way™️ to update a view with all this plumbing is that your process function has to directly update the $view (which isn't even normally passed in to your process function if you think you're just dealing with handlers), not just fix the $handler. 🤦‍♂️

I guess I'm now in the exclusive club of ~5 people on Earth who understand how this class works. 😬 😂

ANYWAY, we're back to green pipelines on 11.x and 10.3.x. I've given up on the 10.2.x MR at this point. It works great for the project where I needed this fixed, all the additional hassles are irrelevant to that site, and this is clearly not getting backported. I just hope this can still land in 10.3.x!

Thanks,
-Derek

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

I'd be lying if I said I fully understand the view config update (not one of the 5 haha) but running the test-only feature the tests for the update are failing as expected

1) Drupal\Tests\views\Functional\Update\EntityArgumentUpdateTest::testViewsFieldPluginConversion
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'entity_target_id'
+'numeric'

Can see the full list of expected test failures here https://git.drupalcode.org/issue/drupal-2640994/-/jobs/1604882

So believe the addition of that is good

  • catch committed bb543187 on 10.3.x
    Issue #2640994 by dww, tduong, Alex Bukach, Berdir, ameymudras, catch,...
catch’s picture

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

Reviewed this all again:

- constructor deprecations in plugins in the 10.3 branch for removal in 11.x - this is OK during beta given it's plugin constructors to fix a major bug.

- config bc layer has a deprecation in 10.3 for removal in 12.x - this is good since it will make the bugfix non-disruptive for contrib modules.

Also thanks for the work on the config deprecation layer, hopefully we can do this correctly for all config updates from now onwards.

Committed/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!

  • catch committed 46fd5d2d on 10.4.x
    Issue #2640994 by dww, tduong, Alex Bukach, Berdir, ameymudras, catch,...

  • catch committed 3006f2af on 11.0.x
    Issue #2640994 by dww, tduong, Alex Bukach, Berdir, ameymudras, catch,...

  • catch committed 28dac554 on 11.x
    Issue #2640994 by dww, tduong, Alex Bukach, Berdir, ameymudras, catch,...

dww’s picture

Woo hoo! 🎉 Thanks, @catch!!

I got the follow-up ready if anyone following here is interested in reviewing (and hopefully RTBC'ing) that one:

#3442227: Use labels in Views argument summaries for entity references

Thanks again! Very happy to see this fixed.

dww’s picture

p.s. Added 10.3.x versions to the CR and published it:
https://www.drupal.org/node/3441945

smustgrave’s picture

Closed #3087020: Exposed contextual taxonomy filter does not update title as a duplicate and moved over credit.

pameeela’s picture

jonathan1055’s picture

Is there a follow-up issue for how to fix contrib tests that are now broken when the views .yml definition is updated to use the new plugins?

-          plugin_id: numeric
+          plugin_id: entity_target_id
+          target_entity_type_id: user

Tests pass at 10.3 but fail at 10.2 with

Schema errors for __the_view_name_ with the following errors:
display.user_page.display_options.arguments.uid.not
missing schema,

user_page.display_options.arguments.uid.target_entity_type_id
missing schema

More details on #3451750: Fix: The update to convert "numeric" arguments to "entity_target_id" is deprecated

catch’s picture

Replied on #3451750: Fix: The update to convert "numeric" arguments to "entity_target_id" is deprecated but also this is a general problem and one we might hit more often as config validation improves so it'd be good to document the outcome somewhere.

dww’s picture

I also replied there. But for here, TL;DR: the problem isn’t really about strict schema validation. It’s that the plug-ins do not exist in 10.2.x. So until folks can drop 10.2.x support, they’ll have to live with the deprecation warnings in 10.3.x and up that the auto-conversion will be dropped in 12.0.x.

Should we do a quick follow up to silence this deprecation in 10.3+ so folks don’t have to worry about it until they’re on 11.x?

jonathan1055’s picture

Should we do a quick follow up to silence this deprecation in 10.3+ so folks don’t have to worry about it until they’re on 11.x?

I think that would be a very good idea, because currently this is preventing testing at 10.3. The default views provided by a contrib project are loaded in every phpunit test, not just the tests which use the views. So I currently have the scenario which I think is wrong on both sides:

  • If I ignore all deprecations when testing at 10.3 I cannot tell what needs to be fixed
  • If I do not ignore deprecations at 10.3 every phpunit test contains this deprecation warning and it is very hard to read through the noise to see the other deprecations.

I am using the core ignore file in the gitlab CI job

SYMFONY_DEPRECATIONS_HELPER: "ignoreFile=$CI_PROJECT_DIR/$_WEB_ROOT/core/.deprecation-ignore.txt"

Maybe there is a way I could patch that file, or add more deprecations to ignore in a second file, or some other way?

berdir’s picture

There are many new deprecations in 10.3. They are added continuously to the next minor version. You can't expect to be deprecation free for the next minor version, or even the current version if you want to keep support for earlier versions. Sometimes there are workarounds, with if/else constructs, DeprecationHelper and what not, but for some deprecations, that just not possible or only with a lot of effort (you could probably do some magic at config install time if you find a hook/event/wrapped service that's early enough)

That's not a problem, that doesn't need to be fixed. There are no expectations to be deprecation-free at any point, it's an early warning system that something will change in the future, nothing is broken yet. There is a reason that deprecations are off by default in Gitlab CI.

Trying to keep next* test runs deprecation free is just a continuous race against Drupal core development. The only thing you can reliably go for is to be deprecation free on the oldest version you provide support for.

dww’s picture

@berdir: Re #212: That's an extremely compelling case for why trying to "chase HEAD" is a headache. Quoting my advice to @jonathan1055 at #3451750-9: Fix: The update to convert "numeric" arguments to "entity_target_id" is deprecated:

So my recommendation for right now is to leave your views using numeric, tell GitLab CI to ignore the resulting depreciation notices until you’re ready to ship a release that requires at least 10.3.x, then you can convert your shipped views and reconfigure your pipelines to fail on depreciations (if that’s what you actually want). 😅

However, I'm somewhat torn. You can't conditionally include different .yml in your views config based on versions. There really is no work-around if you want to try to keep up. There's 0 harm in silencing this deprecation in 10.3.x -- folks have years to learn about it and switch. I'm a big fan of making it as easy as possible to be as compatible with as many versions as possible, since ultimately, that's best for end users.

When I pinged @catch in Slack about this (before your comment), he replied:

So leave everything in 10.3 so contrib can actually use the new thing when we get to 10.4?
Silencing or just removing the deprecation in 10.3 seems ok yeah.

So I opened #3453318: Remove deprecation about Views argument config conversion from numeric to entity_target_id from 10.3.x with a green MR so we can make things easier before the 10.3.0 final release.

Let's continue to discuss there, if necessary, and let this giant issue finally go silent for the 90 followers that only wanted their entity reference arguments to work. 😂

Thanks!
-Derek

Status: Fixed » Closed (fixed)

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

codebymikey’s picture

One thing of note is that this change breaks existing view definitions of certain argument plugins like file_fid, node_nid, taxonomy, vocabulary_vid, user_uid which directly extend the NumericArgument plugin.

Their hook_views_data() argument definition might not include the entity_type property, and triggers an exception to be called when it tries to fetch the title of the node.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 142 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Drupal\Core\Entity\EntityTypeManager->getHandler(NULL, 'storage') (Line: 195)
Drupal\Core\Entity\EntityTypeManager->getStorage(NULL) (Line: 75)
Drupal\views\Plugin\views\argument\EntityArgument->titleQuery() (Line: 80)
Drupal\views\Plugin\views\argument\NumericArgument->title() (Line: 1048)
Drupal\views\Plugin\views\argument\ArgumentPluginBase->getTitle() (Line: 1169)
Drupal\views\ViewExecutable->_buildArguments() (Line: 1326)
Drupal\views\ViewExecutable->build(NULL) (Line: 1450)
Drupal\views\ViewExecutable->execute(NULL) (Line: 1513)
Drupal\views\ViewExecutable->render() (Line: 133)
Drupal\views\Plugin\views\display\Block->execute() (Line: 1689)
Drupal\views\ViewExecutable->executeDisplay('block_1', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 61)
Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 171)
Drupal\block\BlockViewBuilder::preRender(Array)

I'll open a follow-up issue for this.

saxmeister’s picture

That is the issue that I am dealing with in 10.3, codebymikey.

Now that the hook_views_data() argument definition doesn't include entity_type some of my Views are breaking and causing WSOD - especially using Leaflet in Views.

The warnings I get are:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 142 of /data/drupal/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Warning: Undefined array key "entity_type" in Drupal\views\Plugin\views\argument\EntityArgument->titleQuery() (line 75 of /data/drupal/web/core/modules/views/src/Plugin/views/argument/EntityArgument.php)

Note the empty value of entity type. And since the entity doesn't have a value, the titleQuery() function cannot retrieve a value.

The Drupal site using a View that displays a Leaflet map and uses the Contextual Filter "Provide default value" with the option "Content ID from URL" to grab the latitude and longitude values to feed to this View.

xjm credited effulgentsia.

xjm credited star-szr.

xjm credited tim.plunkett.

xjm’s picture

Adding missing credits for issue triage per #20:

@tim.plunkett, @effulgentsia @alexpott @xjm @cottser and @dawehner discussed that.

For those posting comments more recently, this issue was closed over a year ago, and as a result, maintainers will generally not see your replies. You're better off opening new issues in the core queue referencing this one. Thanks!