Problem/Motivation

User roles views argument definition specifies that roles_target_id is numeric, but it's machine name (string).

$data['user__roles']['roles_target_id'] = array(
  'title' => $this->t('Roles'),
  'help' => $this->t('Roles that a user belongs to.'),
  'field' => array(
    'id' => 'user_roles',
    'no group by' => TRUE,
  ),
  'filter' => array(
    'id' => 'user_roles',
    'allow empty' => TRUE,
  ),
  'argument' => array(
    'id' => 'user__roles_rid',
    'name table' => 'role',
    'name field' => 'name',
    'empty field name' => $this->t('No role'),
    'zero is null' => TRUE,
    <strong>'numeric' => TRUE,</strong>
  ),
);

Proposed resolution

Remove numeric definition, so the argument will be considered a string.

Remaining tasks

  • Create a patch

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Taran2L created an issue. See original summary.

Taran2L’s picture

Status: Active » Needs review
FileSize
436 bytes
dawehner’s picture

Maybe some testcoverage would be nice here? This could have caught the issue before ...

Taran2L’s picture

Maybe some testcoverage would be nice here? This could have caught the issue before ...

I believe test is related issue #2595025: None validator incorrectly handles numeric arguments covers exactly what you are asking for.

Do you think creating a test/assertion that checks the plugin definition is a good idea?

dawehner’s picture

Well, then let's postpone this issue on the other one?

Taran2L’s picture

I can work on this issue further, because it's very small can be easily fixed. I'm willing to help, just show me the direction.

I'm just asking: are there any tests (you are aware of) that tests views plugin definition?

If yes - I will update patch. If no - should we start writing such kind of tests? Should we create a meta issue to add tests for all the plugin definitions?

Thanks!

Taran2L’s picture

Seems like general entity tests for views data exist only: see EntityViewsDataTest. There are no tests for particular entity types' views data. I think either create a separate issue(s) for adding those tests or leave it as is.

matslats’s picture

Thought I would point out that roles currently appear twice by the end of Drupal\user\UserViewsData::getViewsData();
One is defined in the parent, taken ultimately from the entity definition. Then the users__roles table is explicitly added in Drupal\user\UserViewsData::getViewsData();

Chi’s picture

dawehner’s picture

Status: Needs review » Needs work

We need at least tests here.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Taran2L’s picture

Version: 8.3.x-dev » 8.4.x-dev
FileSize
1.34 KB
1.59 KB

New patch with tests included. Please review

Taran2L’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: incorrect_definition_of-2799201-12.patch, failed testing.

Taran2L’s picture

Status: Needs work » Needs review

Actually it does pass tests. Some test bot glitch I guess ...

Setting back to Needs review

Lendude’s picture

FileSize
49.26 KB

Looking into this, I would say that$data['user__roles']['roles_target_id'] just needs to be taken out as a whole. As @matslats pointed out in #8, we currently have two Roles contextual filters, neither of which works!

We should only need the one provided by EntityViewsData I would think, but that currently runs into #2837843: EntityViewsData::mapFieldDefinition incorrectly maps entity reference fields which might be a duplicate of #2846614: Incorrect field name is used in views integration for multi-value base fields.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

robybala’s picture

Version: 8.8.x-dev » 8.5.x-dev
FileSize
499 bytes

Patch updated for 8.5.x

robybala’s picture

robybala’s picture

Version: 8.5.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
neclimdul’s picture

Status: Needs review » Closed (duplicate)