Filter farm location reference by asset type

Created on 19 May 2022, almost 3 years ago
Updated 30 October 2023, over 1 year ago

Problem/Motivation

Right now the farm farm_location_reference view is a simple Entity Reference List of any location asset (where is_location = True). It would be nice if this could also filter by the asset type, so as to only display structure or land asset locations.

I tried configuring the asset_type as an exposed filter but it did not work. Configuring this as a contextual filter should work instead.

Steps to reproduce

N/A

Proposed resolution

Configure an asset_type contextual filter on the farm_location_reference view:

  • If no filter is provided display all (default behavior)
  • Use validation criteria to ensure valid asset_type
  • Allow multiple values to be specified

This can then be configured in a entity_autocomplete form field with the following:

    // Location field.
    $form['location'] = [
      '#type' => 'entity_autocomplete',
      '#title' => $this->t('Structure or land location'),
      '#target_type' => 'asset',
      '#selection_handler' => 'views',
      '#selection_settings' => [
        'view' => [
          'view_name' => 'farm_location_reference',
          'display_name' => 'entity_reference',
          'arguments' => ['structure+land'],
        ],
        'match_operator' => 'CONTAINS',
        'match_limit' => 10,
      ],
      '#multiple' => TRUE,
    ];

Remaining tasks

Implement

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States paul121 Spokane, WA

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.

Production build 0.71.5 2024