Problem/Motivation

Upgrading views exposed filters from the 'as a reference filter' does not automatically convert the version of the patch that had the 'as a reference' suffix on each label.

Steps to reproduce

With core 10.2.7 and this patch https://www.drupal.org/files/issues/2024-04-17/3347343-comment156-10.2.x...
I had updated my views exposed filters as needed to use this patch's "field_name as a reference filter" method.

Now that a fix has been backported to 10.4, I remove the patch, installed module views_core_entity_reference 1.0.0-alpha2 and upgraded core to 10.4.0-rc1, then enabled views_core_entity_reference

Expected: My views exposed filters using the 'field_name as a reference filter" method would be upgraded to the new "Related..." versions provided by the fix (ideally). Or at least I could edit the filters to use the new method.

Actual: My views exposed filters using the 'field_name as a reference filter" method are listed as 'Broken/Missing handler', there is no way for me to edit those filters, and if I try to 'Add' I don't see the new "Related...." filters as mentioned in the change notice https://www.drupal.org/node/3403710

Proposed resolution

Trigger the update from hook_install

Remaining tasks

MR

User interface changes

N/A

API changes

N/A

Data model changes

N/A

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

en-cc-org created an issue. See original summary.

scott_euser’s picture

Could be one of two things.

  1. Update hook not running on fresh install, maybe we need to call it from hook install, but for now you can run it manually https://drupal.stackexchange.com/a/179811
  2. Your version of the patch differs from the update hook. There were so many versions of the patch over the years, contributions are needed to cover more versions (see module homepage) but for now if you check the source code, the test submodule has configuration for one 'as a Reference' version, if your version matches that then (1) should work.

Thanks

en-cc-org’s picture

Thank you for the quick reply!

I don't think it's #2 because mine fits what I see in the module & test submodule code, for example (looks the same before and after this module):
field_topics_target_id_reference:
id: field_topics_target_id_reference
table: node__field_topics
field: field_topics_target_id_reference
relationship: none
group_type: group
admin_label: ''
plugin_id: entity_reference
operator: or
value: { }
group: 1
exposed: true
expose:
operator_id: field_topics_target_id_reference_op

Looks like this module attempts to remove the '_reference' but that didn't happen for me. I wasn't sure if this line was a factor:
if (
$filter['plugin_id'] !== 'entity_reference'

Either way, I am able to delete the broken exposed filters and add them again, and they work as expected.

Question:
I am able to add the filters by adding 'field_name' but NOT the 'Related field_name..' as illustrated in the change record at https://www.drupal.org/node/3403710 Is that expected? Maybe because this module successfully opted me in?

Thanks again, appreciate all your efforts

scott_euser’s picture

Question:
I am able to add the filters by adding 'field_name' but NOT the 'Related field_name..' as illustrated in the change record at https://www.drupal.org/node/3403710 Is that expected? Maybe because this module successfully opted me in?

Yeah when I made those screenshots I had actually named the fields 'Related articles' that's all. At the moment in core, there is no option to choose between them other than programmatically (like this module does for you) until #3438054: Configurable views filters to allow for different widgets.

Looks like this module attempts to remove the '_reference' but that didn't happen for me. I wasn't sure if this line was a factor:
if (
$filter['plugin_id'] !== 'entity_reference'

That condition ends in a continue; as in don't proceed if not entity_reference filter (along with the other criteria). From what I can see from your config, your code should pass that condition so I think it is more that the install hook should trigger the same update.

You said you resolved it manually, so that means you did not try the https://drupal.stackexchange.com/a/179811 - is that correct? I think yes.

scott_euser’s picture

Title: Upgrade from 'as a reference filter' not working with core 10.4.0-rc1 » Automated update from 'as a reference filter' not triggered on fresh install
Version: 1.0.0-alpha2 » 1.0.x-dev
Issue summary: View changes

  • scott_euser committed c053cdad on 1.0.x
    Issue #3492343 by scott_euser, en-cc-org: Automated update from 'as a...
scott_euser’s picture

Status: Active » Fixed

Had to fix a gitlab CI deprecation but updated the install process to also trigger the update now.

en-cc-org’s picture

Thanks Scott! Correct, I did not try the https://drupal.stackexchange.com/a/179811 as I didn't want to add to my own confusion lol. Thanks for the clarifications! I'm almost done manually re-adding my filters & they're working as expected. Thanks again for your help.

scott_euser’s picture

Sure no problem at all

scott_euser’s picture

And thanks for raising in the first place, always helps make things better for the next person!

znerol’s picture

This MR introduced the following chunk in views_core_entity_reference.install:

/**
 * Implements hook_install().
 */
function views_core_entity_reference_update_install($is_syncing) {
  _views_core_entity_reference_update_as_a_reference();
}

If I'm not mistaken, the new hook_install() implementation is in fact a hook_update_N implementation (where N = install instead of a number).

scott_euser’s picture

Hook install should be called on initial install for new installations (according to the docs at least) whereas hook updates are only called when a module is already installed and is then subsequently updated to a new version.

znerol’s picture

True. But the function is named like this: views_core_entity_reference_update_install.

The module name is: views_core_entity_reference. Hence, module handler will interpret the remaining _update_install as hook_update_N instead of hook_install.

  • scott_euser committed 9f2edc8b on 1.0.x
    Issue #3492343 by scott_euser, en-cc-org: Automated update from 'as a...
scott_euser’s picture

Aha I see, thank you! Updated hook name, manually tested. Thanks

scott_euser’s picture

znerol’s picture

Thank you!

Status: Fixed » Closed (fixed)

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