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`

a handler error when trying to use `Fragment type` as a contextual filter

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?

Issue fork fragments-3305851

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

gary-ridgway created an issue. See original summary.

alan ridgway’s picture

Does this cause any problems for views? I am unsure of what this line is used for so context would be appreciated!

alan ridgway’s picture

I will create an issue fork for this as a starter

joewhitsitt’s picture

Version: 2.0.2 » 2.x-dev
alan ridgway’s picture

StatusFileSize
new1.06 KB

Including patch so we can use in `composer.json`

eelkeblok’s picture

Hm. Not entirely sure, to be perfectly honest. The line can be traced back to this commit: https://git.drupalcode.org/project/fragments/-/commit/fea9d081f8b87c0e30.... Seems to have something to do with the administrative view. Would need some more testing with that, I think. Maybe an automated test is in order that tests that View, and another one to catch your use case.

Gut feeling is maybe we need that line, but it needs something more to also accommodate your use case.

eelkeblok’s picture

Status: Active » Needs review