Not sure that this was not fixed but I think that roles should also be fieldable entities.

Comments

claudiu.cristea’s picture

Issue tags: +Fields in Core

Tagging

SeanBannister’s picture

Version: 7.x-dev » 8.x-dev

Unfortunately setting this to D8 as we're in Code Freeze.

claudiu.cristea’s picture

Title: Fieldable roles » Role as fieldable entity
Component: field system » user system
Assigned: Unassigned » claudiu.cristea

Title changed.

claudiu.cristea’s picture

Status: Active » Needs review
StatusFileSize
new13.43 KB

And a first patch.

claudiu.cristea’s picture

StatusFileSize
new14.29 KB

New patch with some minor changes.

Status: Needs review » Needs work

The last submitted patch, role-entity-775734-5.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -Fields in Core
StatusFileSize
new12.72 KB

Fixing test failures.

Status: Needs review » Needs work

The last submitted patch, role-entity-775734-7.patch, failed testing.

claudiu.cristea’s picture

The test from #7 failed because I have a new class in an .inc file that needs loading with lazy loading but the class is missed from {registry} table.

Tried to add it in .install with registry_rebuild() but it does not show in the table.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new13.64 KB

Previous tests failed because the test UserRoleAdminTestCase::testRoleWeightChange() is still keeping the old $role object in its static cache. While the test is running in other PHP memory-space, user_role_save() doesn't clear the static cache of the caller PHP space. I changed user.test so that user_role_load() is called now with the "reset cache" flag.

claudiu.cristea’s picture

Tagging

claudiu.cristea’s picture

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice
xjm’s picture

Status: Needs work » Needs review

Sorry, crosspost. :)

chx’s picture

Status: Needs review » Needs work
Issue tags: -Novice

I think xjm crossposted on this issue, so that's not relevant here. What this issue needs (in the future) is tests but most of all: reasoning. Why do you think roles should be entities? What are the use cases?

xjm’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

fixing tags

xjm’s picture

Status: Needs review » Needs work

Okay for real. :)

claudiu.cristea’s picture

Status: Needs work » Needs review

@chx,

Reason: Roles should be fieldable too.

Use case? I had a project where I need to attach to each role an image (like a logo) and a description. I had to workaround using other method.

As a possible use case: exposing roles in Views as any entities?

Tests: What specific should we test on a user role entity?

claudiu.cristea’s picture

Status: Needs review » Needs work

Cross posting. Sorry!

chx’s picture

This gets tricky -- and i know somewhat frustrating but I am not out to put your work down rather I want to work together towards a better Drupal. Thanks for bearing with me.

That said, is that a valid use case? Didnt you want og for that? What are roles? Arent roles just an implementation of access control? are they really groups?

johnv’s picture

My use case for a Role Entity would be for determining Node Access on a Node Edit page.

With Content Access (CA), you have to FIRST: create and save a node, and THEN: remember to go to the Access Control tab.
I prefer something like Access By Term (ABT) does: grant access if both node and user share the same term: user ->term<-node.
Taxonomy Access Control (TAC) does similar, but does not contain the user->term part)

So, the plan is to evaluate ABT to ABR (Access by Entity Reference) . Grant access if both user and node share the same Entity.
Now you can grant access to all documents (content type) for all managers (role) of department HR (a term in vocabulary Departments) , by just setting the Role-field and the Department field in the Node Edit page.
With TAC I would need a 'manager' role for each department; with CA I have an extra tab and ean extra step.

johnv’s picture

Everett Zufelt’s picture

I just worked on a project using roleReference module. Couldn't you field a vocabulary with roleReference (entity or not) and then use that to evaluate access?

I don't really see a compelling use case for making Role an entity. It seems much more a property of User.

johnv’s picture

Everett, Entity-fying everything makes all kind of stuff more generic. No separate contribs for term/nodes/user/xyz-references.
I will test the Role reference-field (and the role_vocabulary-module, if necesary).

johnv’s picture

ITMT, I applied patch #12 with D7.9 and Entity API (7.x-1.x-dev d.d. 07-dec-2011). With every cache-refresh I get the following messages 3x:

  • Warning: in_array() [function.in-array]: Wrong datatype for second argument in entity_type_supports()
  • Warning: class_implements() [function.class-implements]: Class UserRoleController does not exist and could not be loaded in entity_type_supports()

Both in line 72 of ...\sites\all\modules\entity\entity.module.

  • Warning: class_implements() [function.class-implements]: Class UserRoleController does not exist and could not be loaded in entity_crud_get_info()
  • Warning: in_array() [function.in-array]: Wrong datatype for second argument in entity_crud_get_info()

Both in line 494 of ...\sites\all\modules\entity\entity.module.

johnv’s picture

When adding a new role, the following error appears:
Fatal error: Class 'UserRoleController' not found in \includes\common.inc on line 7526

BTW. I applied the patch in D7.9. Does it rely on other D8 patches?

sun’s picture

Issue tags: -entity API, -entity cleanup

Standardizing on "entity" tag, which will be renamed to "Entity system".

ParisLiakos’s picture

Any chance this could get backported to d7?

ParisLiakos’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Entity system

#12: role-entity-775734-12.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests, +Entity system

The last submitted patch, role-entity-775734-12.patch, failed testing.

dagmar’s picture

Marked #1780122: Add role description and notes as a duplicated of this issue.

hass’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Entity system

#12: role-entity-775734-12.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests, +Entity system

The last submitted patch, role-entity-775734-12.patch, failed testing.

dagmar’s picture

Tagging.

pcambra’s picture

I'd say this is covered on #1479454: Convert user roles to configurables, duplicated?

claudiu.cristea’s picture

Status: Needs work » Closed (duplicate)
David_Rothstein’s picture

Version: 8.0.x-dev » 9.x-dev
Issue summary: View changes
Status: Closed (duplicate) » Needs work

Correct me if I'm wrong, but I thought config entities aren't fieldable. That would mean this issue is still valid, right? Presumably this kind of conversion couldn't happen until Drupal 9 though.

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned

@David_Rothstein, that means making config entities fieldable. Hm.

xjm’s picture

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

Under our continuous upgrade path and deprecation policy, feature and API additions should be added with backwards compatibility in minor releases, so moving to 8.8.x. Thanks!

Config entities were made not fieldable by choice, FWIW.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

AS of #39 should we perhaps close this won't fix? Or at least postpone it on an issue to make config entities fieldable (if it exists)?

Just came here from #256287: Give roles a description value.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.