Problem/Motivation

It is not reliable to deploy configuration of Views that reference taxonomy terms when the local site and production site are not exactly matching because they reference the Term ID (content) rather than the UUID. Creating a view which has a filter on a term from a node field should export to configuration with UUID filter values rather than taxonomy term entity IDs.

Steps to reproduce

  1. Create a term in a local site
  2. Content editor creates multiple a term in production in a different order than local
  3. Term IDs don't match but UUIDs would
  4. Since Term IDs don't match, the View is unexpectedly configured to filter by the wrong term.

Proposed resolution

Views configuration with filters on taxonomy terms should use the UUID of the entity chosen. On the front-end, keep everything using entity IDs. On the back-end (storage), store IDs as UUIDs, and convert them when passing between the front-end.

Remaining tasks

None:

  1. Support viewing, editing and saving the filter form with text/autocomplete.
  2. Support viewing, editing and saving the filter form with select options.
  3. Ensure that views are displaying the correct results.
  4. Update existing schema: Ensure that views can be saved and re-read properly, with the same config.
  5. Migrate existing data: Add update hook to convert entity IDs in config to UUIDs.
  6. Fix test failures.

User interface changes

None

Introduced terminology

N/A

API changes

N/A

Data model changes

Views configuration will store references to taxonomy terms as UUIDs not IDs.

Release notes snippet

Change record added here: https://www.drupal.org/node/3464158

Original proposal

Add a checkbox to the filter configuration form to allow users to use the uuid of the term as the filter value rather than the tid.

As a stop-gap until this is implemented in core, I implemented it as a custom filter which extends the current taxonomy term id filter. This may help in determining which parts of the code need to be touched when implementing https://gist.github.com/acbramley/1127c4698a9ae86885e03716f47e3281

CommentFileSizeAuthor
#136 2761157-136.patch30.28 KBduaelfr
#129 2761157-129.patch31.72 KBduaelfr
#18 drupal-views_filters_store_uuids-2761157-17.patch4.98 KBcolan
#20 interdiff-2761157-17-20.diff2.4 KBcolan
#20 drupal-views_filters_store_uuids-2761157-20.patch5.82 KBcolan
#24 drupal-views_filters_store_uuids-2761157-24.patch12.86 KBcolan
#24 interdiff-2761157-20-24.diff9.33 KBcolan
#28 interdiff-2761157-24-28.diff4.02 KBcolan
#28 drupal-views_filters_store_uuids-2761157-28.patch13.78 KBcolan
#30 drupal-views_filters_store_uuids-2761157-30.patch13.82 KBcolan
#30 interdiff-2761157-28-30.diff704 bytescolan
#34 drupal-views_filters_store_uuids-2761157-34.patch16.46 KBcolan
#34 interdiff-2761157-30-34.diff499 bytescolan
#38 drupal-views_filters_store_uuids-2761157-38.patch15.15 KBcolan
#40 drupal-views_filter_store_uuids-2761157-40.patch13.35 KBlisa.rae
#42 drupal-views_filter_store_uuids-2761157-42.patch13.77 KBsja112
#44 interdiff-2761157-42-44.txt1.21 KBsja112
#44 drupal-views_filter_store_uuids-2761157-44.patch13.77 KBsja112
#46 drupal-views-filter-store-uuids-2761157-45.patch13.43 KBlisa.rae
#48 drupal-views-filter-store-uuids-2761157-46.patch13.58 KBlisa.rae
#52 drupal-views-filter-store-uuids-2761157-52.patch13.63 KBvsujeetkumar
#52 interdiff_46-52.txt361 bytesvsujeetkumar
#54 2761157-54.patch13.94 KBravi.shankar
#54 interdiff_52-54.txt643 bytesravi.shankar
#57 2761157-57.patch13.97 KBvsujeetkumar
#59 2761157-59.patch16.01 KBvsujeetkumar
#59 interdiff_57-59.txt2.17 KBvsujeetkumar
#61 2761157-61.patch16.04 KBvsujeetkumar
#61 interdiff_59-61.txt537 bytesvsujeetkumar
#63 2761157-63.patch16.05 KBvsujeetkumar
#63 interdiff_61-63.txt487 bytesvsujeetkumar
#64 2761157-64.patch16.11 KBduaelfr
#69 drupal-views-use-taxonomy-uuids-2761157-69.patch17.69 KBscott_euser
#70 2761157-70.patch17.62 KBerikbrgn
#70 interdiff_69-70.txt1.79 KBerikbrgn
#72 2761157-72.patch24.32 KBrassoni
#72 interdiff-70-72.txt7.92 KBrassoni
#77 2761157-77.patch20.97 KBrosk0
#79 2761157-79.patch21 KBpooja saraah
#79 interdiff_77-79.txt960 bytespooja saraah
#80 2761157-80.patch21.1 KBshital.mahajan
#82 2761157-82.patch21.07 KBanchal_gupta
#82 interdiff-2761157-80_82.txt596 bytesanchal_gupta
#83 2761157_views_patch.patch716 bytestushar1
#84 interdiff_83-84.txt739 bytes_utsavsharma
#84 2761157-84.patch716 bytes_utsavsharma
#87 2761157-87.patch21.04 KBmanuel garcia
#90 2761157-88.patch21.08 KBPrudhvi32
#90 interdiff_87-88.txt558 bytesPrudhvi32
#91 2761157-89.patch21.03 KBvasike
#92 2761157-90.patch21.1 KBvasike
#92 2761157-90-10.1.x.patch21.11 KBvasike
#102 2761157-nr-bot.txt90 bytesneeds-review-queue-bot
#103 2761157-91-10.3.x.patch21.17 KBmefianf
#106 2761157-nr-bot.txt90 bytesneeds-review-queue-bot
#116 2761157-116.patch19.07 KBtonibarbera
#120 2761157-116-custom.patch17.22 KBolmyr
#121 2761157-121-10.3.4.patch17.22 KBolmyr

Issue fork drupal-2761157

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

acbramley created an issue. See original summary.

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

nevergone’s picture

Cool! Please create generic solution (not only taxonomy term, not only filter) and attach patch. Thanks! :)

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

sdrong’s picture

@nevergone should this be optional? seems like it would be better to just use uuid by default unless there is a reason to keep tid/nid as the stored filtered id? Not sure providing a user facing interface to switch between one or other is going to be helpful. We migrated a lot of content and id drift between views and migrations is an issue for us currently.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

leisurman’s picture

Has there been any new information on this topic? We would also like to use the UUID instead of NID and TID in Views filters. Our NID and TIDs are out of sync across server source and destination servers.

pburgh’s picture

This causes an issue for us as well. Some of our view filters break each time configuration is imported.

Hopefully someone can address this.

tomasdev’s picture

Is there a patch that allows this to work? I am also having trouble when migrating configuration to different environments where taxonomies have different ids (but proper uuid)

Orestis Nerantzis’s picture

I don't know if there is a patch for this but i managed to solve this problem with module Default Content , which will import taxonomies to different enviroment with same tid so views won't break.

Hope it helps.

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.

colan’s picture

colan’s picture

As alluded to by the IS, it looks like the IDs are being set in core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid->valueForm(), which is tricky to sift through as it's way too long and has way too many nested ifs. It'll need to be refactored to make it understandable enough to work on.

Add a checkbox to the filter configuration form to allow users to use the uuid of the term as the filter value rather than the tid.

I agree with #7.

Here's the idea: Just use UUIDs, and forget about the checkbox. When reading them back from configuration, convert them to entity IDs. We can implement an update hook that migrates existing configuration with entity IDs to UUIDs. Then we won't need the checkbox.

Would there be any reason not to do that?

colan’s picture

Assigned: Unassigned » colan

I'm trying to see what I can throw together.

colan’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new4.98 KB

There's still work to do, but I'd like to see what the testbot says.

I updated the IS with tasks, and was able to get "Support viewing, editing and saving the filter form with text/autocomplete" working. I'll look at select options next (and keep refactoring).

Questions for to-dos:

  • Where in the code does Views save the actual view to config? I noticed that I'm getting small integers like 0, 6 and 20 instead of UUIDs (or even entity IDs, which should be in the hundreds range for my site).
  • Where in the code does Views grab the stored values to execute the query? I'm not getting any results so I'm assuming we have to do a conversion here (although fixing the other item may fix this).
larowlan’s picture

Where in the code does Views grab the stored values to execute the query? I'm not getting any results so I'm assuming we have to do a conversion here (although fixing the other item may fix this).

It happens in the

::init

method - in there it sets $this->value (an array)

Where in the code does Views save the actual view to config? I noticed that I'm getting small integers like 0, 6 and 20 instead of UUIDs (or even entity IDs, which should be in the hundreds range for my site).

You might have a config-schema issue here - taxonomy.views.schema.yml is probably telling the config API that the filter value is an integer

colan’s picture

Issue summary: View changes
Issue tags: +Needs tests
StatusFileSize
new2.4 KB
new5.82 KB

Thanks! init() really did the trick. I believe all that's left (other than tests) is an update hook to update the schema and data within it.

Status: Needs review » Needs work

The last submitted patch, 20: drupal-views_filters_store_uuids-2761157-20.patch, failed testing. View results

colan’s picture

Status: Needs work » Needs review

So, how do I change the data type from an integer to a string in existing config? I can change the values, but they still come out as integers, even though I updated the schema definition. It looks like there's a way to do this with field configuration, but not with views. Views configurations don't seem to have a toArray() method.

Would someone kindly point me to an example?

colan’s picture

Status: Needs review » Needs work

Fixed accidental status change.

colan’s picture

Assigned: colan » Unassigned
Status: Needs work » Needs review
StatusFileSize
new12.86 KB
new9.33 KB

Setting to NR so we're know what test failures come back; will turn to NW shortly.

It's possible we won't actually need additional tests for this as there seems to be coverage (given the failures), but it may be worthwhile to check if conversions between the ID types are happening (even though this wouldn't be functional testing).

I'm giving up for now as I spend enough time trying to figure out #22. If someone can provide a hint, I'll pick it up again. Alternately, having someone else figure this out would be great. I left a @todo in the update hook.

Also, I refactored valueForm() some more, which has shrunken significantly. It should be much easier to see what's going on. (I can now see the entire thing in my IDE!)

The last submitted patch, 24: drupal-views_filters_store_uuids-2761157-24.patch, failed testing. View results

colan’s picture

Looks like the last part of views_update_8500() may be helpful here. (Thanks to @larowlan for the idea to look in there!)

colan’s picture

colan’s picture

StatusFileSize
new4.02 KB
new13.78 KB

I think I got it. The filters may be losing their vocabulary IDs, but this could just be my set-up. Further testing is required.

The above plan for an upgrade path wasn't workable because the way views configuration updates are done has changed. These now have to be done in Views post-save hooks. See #2989745: views_update_8500() inlines configuration changes instead of this being done on config save for bc for details.

Please test (as I'll be doing tomorrow) and report back.

Status: Needs review » Needs work

The last submitted patch, 28: drupal-views_filters_store_uuids-2761157-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

colan’s picture

Status: Needs work » Needs review
StatusFileSize
new13.82 KB
new704 bytes

I forgot to check for an unset array index.

The last submitted patch, 30: drupal-views_filters_store_uuids-2761157-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

colan’s picture

Issue summary: View changes
Issue tags: -Needs tests

Ways to test

These are the processes I used to test, in order from top to bottom (as they lead into each other). They all work for me.

Upgrade path

  1. Switch to the latest dev branch.
  2. Apply the patch.
  3. Run DB schema updates.
  4. Re-save all term filters in all Views displays containing them.

Exporting configuration

  1. From the state left above, export the site's configuration.
  2. Diff the configuration directory.
  3. The entity IDs should be replaced by UUIDs.

Importing configuration

  1. Install a new site with the above-generated configuration. (I used Config Profile and drush site-install.)
  2. Import taxonomy terms with Structure Sync (assuming you've exported them there previously).
  3. View/edit filters and Views results to ensure they haven't changed.
  4. See Views results, and notice that filters are working properly.

Drupal.org test failures

There's now only one test failure, which looks like a test needs to be updated. I'll take a closer look. Updating status as not everything is green yet.

Given that, it looks like we have good coverage for this already so I don't believe we needs additional tests. Removing tag.

colan’s picture

Title: Allow taxonomy tid filter to use uuid instead of tid » Have Views' taxonomy term filters use UUIDs instead of entity IDs

Updating title.

colan’s picture

StatusFileSize
new16.46 KB
new499 bytes

Hopefully this does it, changing the test ID value from an integer to a (UUID) string.

The last submitted patch, 34: drupal-views_filters_store_uuids-2761157-34.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

colan’s picture

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

Here's a reroll for 8.9.x.

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.

lisa.rae’s picture

Rerolled patch 38 against Drupal 9.2-dev, commit hash 1bcb278060b75c4f45c82cdb8784262c2f45723b

sja112’s picture

Assigned: Unassigned » sja112
Status: Needs review » Needs work
sja112’s picture

Assigned: sja112 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new13.77 KB

Rerolled patch 40 against Drupal 9.2.x branch

sja112’s picture

Working on issues reported in test

sja112’s picture

Status: Needs review » Needs work

The last submitted patch, 44: drupal-views_filter_store_uuids-2761157-44.patch, failed testing. View results

lisa.rae’s picture

lisa.rae’s picture

Assigned: Unassigned » lisa.rae
lisa.rae’s picture

lisa.rae’s picture

lisa.rae’s picture

lisa.rae’s picture

Assigned: lisa.rae » Unassigned
vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new13.63 KB
new361 bytes

Fixing tests, missing class "Drupal\Core\Config\Entity\ConfigEntityUpdater" addes, Please have a look.

Status: Needs review » Needs work

The last submitted patch, 52: drupal-views-filter-store-uuids-2761157-52.patch, failed testing. View results

ravi.shankar’s picture

StatusFileSize
new13.94 KB
new643 bytes

Fixing failed tests of patch #52.

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.

kkasson’s picture

We've been using the patch from #38 successfully on an 8.9.x installation for a while now. We discovered one bug, using the patch causes the "Limit list to selected items" option to not work. We fixed that by changing line 10 of the getEntityIdsFromUuids function from

      $entity_ids[] = $term->id();

to

      $entity_ids[$term->id()] = $term->id();

Not sure of any other possible consequences of that, but it seems to fix the above option.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new13.97 KB

Re-roll patch to 9.3.x.

Status: Needs review » Needs work

The last submitted patch, 57: 2761157-57.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new16.01 KB
new2.17 KB

Trying to fix Fail test, Not sure these test fix are up to date or not. Please have a look and advise.

Status: Needs review » Needs work

The last submitted patch, 59: 2761157-59.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new16.04 KB
new537 bytes

Fixing the fail tests because of "accessCheck()".

colan’s picture

Status: Needs review » Needs work

Updating status as per #56. Looks like that hasn't been included yet.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new16.05 KB
new487 bytes

Worked on #56 as mentioned in #62, Please have a look.

duaelfr’s picture

StatusFileSize
new16.11 KB

Patch from #63 looks good and is working. I just had to make a quick reroll because taxonomy.post_update.php has been changed in 9.3.x.

Even if there are already a lot of coding standards issues in those files, shouldn't all new functions/methods have docblock comments?


Do not forget to clear cache after applying the patch and before running updates if you plan to use it right now.

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.

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -95,6 +96,10 @@ public static function create(ContainerInterface $container, array $configuratio
    +    if (!empty($options['value'])) {
    +      $options['value'] = $this->getEntityIdsFromUuids($options['value']);
    
    @@ -102,6 +107,22 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +  protected function getEntityIdsFromUuids(array $uuids) {
    +    if (!empty($uuids) && !Uuid::isValid(reset($uuids))) {
    

    empty() called twice for no reason, it could always call function and have empty check inside

    Also protected method needs docblock

    Also reset() validates only first element of values

  2. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -288,6 +246,88 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
     
    +  protected function getFormValueForTextFields() {
    ...
    +
    +  protected function getFormValueOptions() {
    ...
    +
    +  protected function getFormValueOptionsWithHierarchyAndLimit() {
    ...
    +
    +  protected function getFormValueOptionsWithoutHierarchyAndLimit() {
    ...
    +
    +  protected function getDefaultValueForSingleExposedOption($default_value, $options) {
    
    @@ -427,4 +476,12 @@ public function calculateDependencies() {
     
    +  protected function getVocabulary() {
    ...
    +
    +  protected function getTermLabel($term) {
    
    +++ b/core/modules/taxonomy/taxonomy.post_update.php
    @@ -25,3 +29,45 @@ function taxonomy_removed_post_updates() {
    +
    +function taxonomy_convert_entity_ids_to_uuids(array $entity_ids) {
    

    missing doc-block

  3. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -370,6 +410,14 @@ public function validateExposed(&$form, FormStateInterface $form_state) {
    +    foreach ($term_ids as $term_id) {
    +      $uuids[] = $this->termStorage->load($term_id)->uuid();
    

    better use loadMultiple() here

trafo’s picture

Post update hook does not update filters correctly, because it checks wrong array keys. I'd say we could just check for taxonomy_index_tid views filter plugin and update values.

if (($filter['plugin_id'] === 'taxonomy_index_tid') && isset($filter['value'])) {
  $filters[$id]['value'] = taxonomy_convert_entity_ids_to_uuids($filters[$id]['value']);
}

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.

scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new17.69 KB

Updated patch for 9.4.0, addresses feedback in #66 and #67.

An interdiff was not possible because patch was rejected, but other than addressing the feedback, I had to add lines 166-171 in core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php to have tests pass. The stored UUID in core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.test_filter_taxonomy_index_tid.yml does not match the UUIDs available, so no filter is applied. I therefore have the test update the View to select an existing Term and see if filtering works correctly. I feel a bit nervous that perhaps that is defying the point of this work, so please pay attention to that when reviewing. I could not find another way to resolve, but probably there is a better way than what I have done.

erikbrgn’s picture

StatusFileSize
new17.62 KB
new1.79 KB

@scott_euser, just fixing the codesniffer errors in your patch.

Status: Needs review » Needs work

The last submitted patch, 70: 2761157-70.patch, failed testing. View results

rassoni’s picture

Status: Needs work » Needs review
StatusFileSize
new24.32 KB
new7.92 KB
c-logemann’s picture

Issue tags: +UUID
jhedstrom’s picture

Issue summary: View changes

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.

larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -27,6 +29,7 @@ class TaxonomyIndexTid extends ManyToOne {
    +  // @codingStandardsIgnoreLine
    
    @@ -71,6 +74,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    +      // @codingStandardsIgnoreLine
    
    @@ -113,6 +151,9 @@ public function getValueOptions() {
    +  /**
    +   * {@inheritdoc}
    +   */
    
    @@ -125,6 +166,9 @@ protected function defineOptions() {
    +  /**
    +   * {@inheritdoc}
    +   */
    
    @@ -153,7 +197,10 @@ public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
    -      '#options' => ['select' => $this->t('Dropdown'), 'textfield' => $this->t('Autocomplete')],
    +      '#options' => [
    +        'select' => $this->t('Dropdown'),
    +        'textfield' => $this->t('Autocomplete'),
    
    @@ -169,8 +216,11 @@ public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
    +  /**
    +   * {@inheritdoc}
    +   */
    
    @@ -280,7 +267,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
    -      // Retain the helper option
    +      // Retain the helper option.
           $this->helper->buildOptionsForm($form, $form_state);
    
    @@ -303,6 +407,9 @@ protected function valueValidate($form, FormStateInterface $form_state) {
    +  /**
    +   * {@inheritdoc}
    +   */
       public function acceptExposedInput($input) {
    
    @@ -315,7 +422,7 @@ public function acceptExposedInput($input) {
         // If view is an attachment and is inheriting exposed filters, then assume
    -    // exposed input has already been validated
    +    // exposed input has already been validated.
    
    @@ -342,6 +449,9 @@ public function acceptExposedInput($input) {
    +  /**
    +   * {@inheritdoc}
    +   */
    
    @@ -374,10 +484,24 @@ public function validateExposed(&$form, FormStateInterface $form_state) {
    +  /**
    +   * {@inheritdoc}
    +   */
    

    out of scope

  2. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -102,6 +110,36 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +    $terms = $this->termStorage->loadByProperties(['uuid' => $uuids]);
    

    should this use an aggregate query instead of loading the terms or do the terms end up getting loaded anyway?

  3. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -102,6 +110,36 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +      $entity_ids[$term->id()] = $term->id();
    

    pretty sure the return is keyed by tid, so you can just array_combine with array_keys

rosk0’s picture

Status: Needs work » Needs review
StatusFileSize
new20.97 KB

There is no interdiff as the patch from #72 didn't want to apply to latest core on one of the inheritdoc tag that was mentioned in #76 as out of scope.

  • #76.1 - Addressed all items plus couple more inheritdoc which wasn't mentioned but clearly out of scope
  • #76.2 - Used aggregate query as suggested
  • #76.3 - Addressed by aggregate query implementation
  • Replaced {@inheritdoc} with actual description for introduced in the patch getFormValueOptions()
joachim’s picture

Status: Needs review » Needs work

(Incomplete review, as about to serve up dinner.)

  1. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -98,6 +104,38 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +   * Get entity IDs from UUIDs.
    

    Should be 'Gets'.

  2. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -98,6 +104,38 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +        // Abandon conversion if we already have IDs and not UUIDs.
    

    Why would someone call this with IDs? What's the reason for this guard clause?

  3. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -98,6 +104,38 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +      ->getAggregateQuery()
    

    What's the reason for the aggregate query and group by?

  4. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -98,6 +104,38 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +      // Access was already checked during configuration time.
    

    What's configuration time?

  5. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -98,6 +104,38 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
    +    return array_combine($tids, $tids);
    

    Is the return keyed by tid? The @return should say.

  6. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -284,6 +259,123 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
    +   * Get the form value for text fields.
    

    Gets.

  7. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -284,6 +259,123 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
    +   *   Form API render array for text fields.
    

    render array? But returned var is called $form_value, doesn't match up.

  8. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -284,6 +259,123 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
    +   *   Options array suitable for form API.
    

    Written FormAPI, usually.

pooja saraah’s picture

StatusFileSize
new21 KB
new960 bytes

Addressed the comment #78 Point 1,6,8
Keeping it needs work to address other points on #78
Attached patch against Drupal 10.1.x

shital.mahajan’s picture

StatusFileSize
new21.1 KB

The scenario is missed when there is no term associated with the TID which is causing drush updb to fail.
(In our case there are TIDs in the views config files but the same TID wont be present on environment as TID is dynamic)
Modifying patch to handle such scenario

c-logemann’s picture

Status: Needs work » Needs review
anchal_gupta’s picture

StatusFileSize
new21.07 KB
new596 bytes

I fixed CS error, and I have uploaded the patch. Please review it

tushar1’s picture

StatusFileSize
new716 bytes

Our site is running on 9.4.x version and we are facing below issue in build, we have also checked by upgrading platform version to latest 7.24.1 but still no luck

Error: > [notice] Update started: taxonomy_post_update_convert_term_views_filters_to_uuids
> [warning] Undefined array key "plugin_id" taxonomy.post_update.php:48
> [error] TypeError: Drupal\views\Plugin\views\PluginBase::init(): Argument #3 ($options) must be of type ?array, string given, called in /site-archive/pfpfizerforyoudk-1670742508/app/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php on line 1131 in Drupal\views\Plugin\views\PluginBase->init() (line 137 of /site-archive/pfpfizerforyoudk-1670742508/app/core/modules/views/src/Plugin/views/PluginBase.php)

So we have added below patch by adding fix into core view module and that issue is resolved.

_utsavsharma’s picture

StatusFileSize
new739 bytes
new716 bytes

Fixed CCF for #83.
Please review.

rosk0’s picture

Status: Needs review » Needs work

Please stop posting wrong patches.

Patch in #80 introduces a change without the interdiff, comments after reduce patch size from 20 Kb to bytes...

If people want their patches to be helpful, please learn how to work with them first https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... .

Updates to patches must be supplemented with the interdiff to simplify review process.

rosk0’s picture

I believe there is one more thing that needs improvement - at the moment taxonomy_post_update_convert_term_views_filters_to_uuids() needlessly sets filters: { } on all displays views.

We should wrap $display['display_options']['filters'] = $filters; in an empty check to prevent this.

manuel garcia’s picture

StatusFileSize
new21.04 KB

We needed this patch for 9.4.x so I have rerolled #79 here against that. Attaching in case its useful to someone else.

xurizaemon’s picture

This patch may fail in the case of a Views filter configuration referencing a term which no longer exists in the site DB.

In taxonomy_convert_entity_ids_to_uuids():

    $uuids[] = Term::load($entity_id)->uuid();

While that's not a valid configuration state with reference to the DB content, it is possible to encounter it (eg: term was deleted but view configuration was not updated), and the patch could handle it better by checking the result of Term::load() before calling its ->uuid() method.

We could either drop the item from the list of UUIDs (which feels wrong, even though the configuration was already not valid with reference to content), or we could fail the DB update in order to notify the site owners. I believe the latter is safer?

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.

Prudhvi32’s picture

StatusFileSize
new21.08 KB
new558 bytes

Unable to decode output into JSON: Syntax error
Error: Call to a member function uuid() on null in taxonomy_convert_entity_ids_to_uuids().
on line 78 app\core\modules\taxonomy\taxonomy.post_update.php

For this issue, we created a patch and patch is working fine.

vasike’s picture

Status: Needs work » Needs review
StatusFileSize
new21.03 KB

Here it is just a re-roll of previous patch. i hope i didn't miss a thing.

Let's see if it passes. Maybe we'll have also a MR that could help chasing and keep it updated till ... it's done

vasike’s picture

StatusFileSize
new21.1 KB
new21.11 KB

Small update, attempting to fix CS/phpstan errors.

+ A version for 10.1.x, as it seems they are not the same.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Taking a brief look and looks like this is very close.

Seems like changing to UUID should be captured in a change record though, just to let others know.

lendude’s picture

There is still a lot of clean up happening here, which makes it really hard to review. While I like that logic is moved to its own methods instead of having one giant method, it makes reviewing this very hard, because its really hard to see which changes are needed here and which changes are just moving existing logic around. Please please please keep the patch/MR as small as possible

This feels very light on test coverage, but again, since it's hard to see what is actually new code here that should have test coverage, it might be sufficient.

Since we have an update hook, it should have an upgrade path test for that hook.

scott_euser’s picture

Moving to an MR for now, still needs addressing feedback from #94 as next step, ie:

  1. Reduce scope as much as possible
  2. Increase test coverage if needed
scott_euser’s picture

The failure is unrelated it seems. I am not sure why it still fails as it seems @dww had fixed that here https://www.drupal.org/project/drupal/issues/2640994#comment-15597379 and it was committed to 10.3.x through to 11.x. @smustgrave, any chance you have seen this elsewhere as well? The MR/Fork is new from today so I would think it should not have that problem

scott_euser’s picture

Status: Needs work » Needs review

Beyond that I think test coverage actually may not need much change as the existing test coverage before this issue should actually be validating that the existing complete process of updating, saving, filtering by continues to work.

scott_euser’s picture

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

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.

mefianf’s picture

StatusFileSize
new21.17 KB

A small patch update for 10.3.x, as it seems they are not the same.

scott_euser’s picture

Status: Needs work » Needs review

2761157-views-taxonomy-uuid branch still merges and passes fine, with expected config validation change (if I understand that warning right). So back to needs review since I believe #94 has been addressed/responded to. So it would be good if someone could confirm and change to RTBC since I made too many changes to this myself.

(Also hiding patches, for those adding them, please instead follow the documentation for downloading merge requests as patches locally to avoid confusion + avoid issues with needs review bot pushing these issues back to needs work unecessarily)

scott_euser’s picture

Issue summary: View changes
Issue tags: -Needs change record

Change record added here: https://www.drupal.org/node/3464158
Update issue summary to standard template but kept the original solution additional chapter.

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.

scott_euser’s picture

Status: Needs work » Needs review

Resolved conflict.

smustgrave changed the visibility of the branch 2761157-views-taxonomy-uuid--10-3-x to hidden.

smustgrave’s picture

Status: Needs review » Needs work

On the back-end (storage), store IDs as UUIDs

So for the schema update should it be of type: uuid?

Which is validated

scott_euser’s picture

Status: Needs work » Needs review
scott_euser’s picture

Status: Needs review » Needs work

Tests no longer passing, back to NW

smustgrave’s picture

My comment for uuid I could be wrong just seemed like it lined up

scott_euser’s picture

No, it really does look right. All 3 failures pass locally when I re-run so I triggered re-run via gitlab CI now

scott_euser’s picture

:facepalm, I hadn't pulled because the changes were applied via gitlab UI. They do fail locally. Not a valid UUID error, so could be our sample data...

scott_euser’s picture

Issue summary: View changes

Okay its really legitimately showing again what we are seeing now and then, that the Views configuration stored in test views & config install | config optional are not updated by update hooks and therefore out of date and need to be manually update.

However in this case, even when

  1. Import test view single config
  2. Resave
  3. Config export
  4. Running phpunit -c core/phpunit.xml core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyIndexTidFilterTest.php

There is actually a problem with calculateDependencies() in the code itself revealed here. The 'content' key is not getting populated with the references to the UUIDs and therefore does not match the view. We need to fix that first. I updated the issue summary with this.

tonibarbera’s picture

StatusFileSize
new19.07 KB

The patch doesn´t apply to Drupal 10.3.1. Rerolled the patch for that version

tonibarbera’s picture

Status: Needs work » Needs review
scott_euser’s picture

Status: Needs review » Needs work

#115 not yet addressed, let's keep it at needs work as it needs work still. Hiding patches in favour of merge request.

scott_euser’s picture

2761157-views-taxonomy-uuid--10-3-x branch updated to apply to 10.3.2.

olmyr’s picture

StatusFileSize
new17.22 KB

The patch for the 10.3.4

olmyr’s picture

StatusFileSize
new17.22 KB

The patch for the 10.3.4

olmyr changed the visibility of the branch 2761157-views-taxonomy-uuid--10-3-x to active.

olmyr’s picture

scott_euser’s picture

Issue summary: View changes
Status: Needs work » Needs review
  1. Updated views wizard to also respect this
  2. Fixed test failures
  3. Updated issue summary
smustgrave’s picture

Status: Needs review » Needs work

Very neat!

Left some comments on the MR.

scott_euser’s picture

Status: Needs work » Needs review

Thanks for the feedback! Comments address + update test added + 2nd change record added

smustgrave’s picture

Status: Needs review » Needs work

MR appears to need a rebase.

duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new31.72 KB

MR squashed and rerolled.
Patch attached for composer.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Closed the old MRs for. 10.3 as they were failing and probably missed the boat for them.

Rebased 11.x and still all green

All threads appear to be resolved, templated to tag 11.2 highlight but will let committer decide.

catch’s picture

Status: Reviewed & tested by the community » Needs work

One (non-trivial) comment on the MR about the upgrade path.

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.

gaëlg made their first commit to this issue’s fork.

duaelfr’s picture

StatusFileSize
new30.28 KB

MR rerolled
Patch attached for composer

Comment #133 is still to consider