hook_options_list_alter for views

Created on 28 January 2020, over 4 years ago
Updated 4 May 2024, 20 days ago

I can't use hook_options_list_alter on views. I'm sharing the same field among different content types. I can limit the options per content type on node page edit page with no problem, but for some reason the ->id() is not recognized properly inside views.

   if ($context['fieldDefinition']
          ->id() == 'node.content_type_name.field_status'

The content_type_name is the same everywhere.

πŸ› Bug report
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡΅πŸ‡±Poland adpo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I assume this is referring to views exposed filters. It's worth noting that hook_options_list_alter is called from \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions so perhaps it's only intended to work on field widgets. The options available in views exposed filters are populated in \Drupal\views\Plugin\views\filter\InOperator::getValueOptions. Either way, I think an allowed_values_function callback might be a better way to achieve this.

  • πŸ‡΅πŸ‡±Poland adpo

    Thank you @mstrelan I was able to determine the route name inside hook_options_list_alter
    $current_route_name = \Drupal::service('current_route_match')->getRouteName();

  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    @adpo so is this resolved? I'm not quite sure I understand the issue. If it's not resolved please provide the steps to reproduce the issue.

  • πŸ‡΅πŸ‡±Poland adpo

    Actually it didn’t (old project). I will try again with different approach. Yes, was reffering to exposed filters.

  • Status changed to Closed: works as designed 20 days ago
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    Marking this works as designed based on the previous comments.

Production build 0.69.0 2024