Contextual filters not working.

Created on 24 August 2022, about 2 years ago
Updated 20 September 2022, about 2 years ago

Problem/Motivation

I would like to use contextual filters within a view of Fragments, but currently there is an error that occurs when trying to add one for `Fragment type`

Steps to reproduce

  • Create multiple types of fragments.
  • Create a view of fragments.
  • try and create a contextual filter, using `Fragment type` as your contextual filter.
  • Observe the error in the image above.

Proposed resolution

Delete the following line in `fragments/src/Entity/FragmentViewsData.php`

<?php

namespace Drupal\fragments\Entity;

use Drupal\views\EntityViewsData;

/**
 * Provides Views data for fragment entities.
 */
class FragmentViewsData extends EntityViewsData {

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
    $data = parent::getViewsData();

    // This one vvv.
    $data['fragment_field_data']['type']['argument']['id'] = 'fragment_type';
    // This one ^^^.

    $data['fragment_field_data']['user_id']['help'] = $this->t('The user authoring the fragment. If you need more fields than the uid add the fragment author relationship');
    $data['fragment_field_data']['user_id']['filter']['id'] = 'user_name';
    $data['fragment_field_data']['user_id']['relationship']['title'] = $this->t('Fragment author');
    $data['fragment_field_data']['user_id']['relationship']['help'] = $this->t('Relate fragments to the user who created them.');
    $data['fragment_field_data']['user_id']['relationship']['label'] = $this->t('author');

    return $data;
  }

}

Remaining tasks

Delete the line listed above.

User interface changes

None that I know of?

API changes

None that I know of?

Data model changes

None that I know of?

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

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

Merge Requests

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