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?
Comments
Comment #2
alan ridgway commentedDoes this cause any problems for views? I am unsure of what this line is used for so context would be appreciated!
Comment #3
alan ridgway commentedI will create an issue fork for this as a starter
Comment #5
joewhitsittComment #6
alan ridgway commentedIncluding patch so we can use in `composer.json`
Comment #7
eelkeblokHm. 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.
Comment #8
eelkeblok