Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
e3e12db3
Commit
e3e12db3
authored
Sep 18, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2044859
by Berdir, klausi: Convert user roles to entity_reference_field.
parent
52a101bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
11 deletions
+23
-11
core/modules/file/src/Tests/FileFieldWidgetTest.php
core/modules/file/src/Tests/FileFieldWidgetTest.php
+1
-1
core/modules/user/src/Entity/User.php
core/modules/user/src/Entity/User.php
+5
-6
core/modules/user/src/Tests/UserValidationTest.php
core/modules/user/src/Tests/UserValidationTest.php
+16
-3
core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php
...dules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php
+1
-1
No files found.
core/modules/file/src/Tests/FileFieldWidgetTest.php
View file @
e3e12db3
...
...
@@ -201,7 +201,7 @@ function testMultiValuedWidget() {
*/
function
testPrivateFileSetting
()
{
// Grant the admin user required permissions.
user_role_grant_permissions
(
$this
->
admin_user
->
roles
[
0
]
->
value
,
array
(
'administer node fields'
));
user_role_grant_permissions
(
$this
->
admin_user
->
roles
[
0
]
->
target_id
,
array
(
'administer node fields'
));
$type_name
=
'article'
;
$field_name
=
strtolower
(
$this
->
randomMachineName
());
...
...
core/modules/user/src/Entity/User.php
View file @
e3e12db3
...
...
@@ -174,8 +174,8 @@ public function getRoles($exclude_locked_roles = FALSE) {
$roles
=
array
();
foreach
(
$this
->
get
(
'roles'
)
as
$role
)
{
if
(
!
(
$exclude_locked_roles
&&
in_array
(
$role
->
value
,
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
))))
{
$roles
[]
=
$role
->
value
;
if
(
!
(
$exclude_locked_roles
&&
in_array
(
$role
->
target_id
,
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
))))
{
$roles
[]
=
$role
->
target_id
;
}
}
...
...
@@ -531,13 +531,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->
setDescription
(
t
(
'The email address used for initial account creation.'
))
->
setDefaultValue
(
''
);
// @todo Convert this to entity_reference_field, see
// https://drupal.org/node/2044859.
$fields
[
'roles'
]
=
BaseFieldDefinition
::
create
(
'string'
)
$fields
[
'roles'
]
=
BaseFieldDefinition
::
create
(
'entity_reference'
)
->
setCustomStorage
(
TRUE
)
->
setLabel
(
t
(
'Roles'
))
->
setCardinality
(
BaseFieldDefinition
::
CARDINALITY_UNLIMITED
)
->
setDescription
(
t
(
'The roles the user has.'
));
->
setDescription
(
t
(
'The roles the user has.'
))
->
setSetting
(
'target_type'
,
'user_role'
);
return
$fields
;
}
...
...
core/modules/user/src/Tests/UserValidationTest.php
View file @
e3e12db3
...
...
@@ -11,6 +11,8 @@
use
Drupal\Core\Field\Plugin\Field\FieldType\EmailItem
;
use
Drupal\Core\Render\Element\Email
;
use
Drupal\simpletest\DrupalUnitTestBase
;
use
Drupal\user\Entity\Role
;
use
Drupal\user\Entity\User
;
/**
* Verify that user validity checks behave as designed.
...
...
@@ -33,6 +35,10 @@ protected function setUp() {
parent
::
setUp
();
$this
->
installEntitySchema
(
'user'
);
$this
->
installSchema
(
'system'
,
array
(
'sequences'
));
// Make sure that the default roles exist.
$this
->
installConfig
(
array
(
'user'
));
}
/**
...
...
@@ -68,7 +74,7 @@ function testUsernames() {
* Runs entity validation checks.
*/
function
testValidation
()
{
$user
=
entity_create
(
'user'
,
array
(
'name'
=>
'test'
));
$user
=
User
::
create
(
array
(
'name'
=>
'test'
));
$violations
=
$user
->
validate
();
$this
->
assertEqual
(
count
(
$violations
),
0
,
'No violations when validating a default user.'
);
...
...
@@ -137,6 +143,9 @@ function testValidation() {
$this
->
assertEqual
(
$violations
[
0
]
->
getPropertyPath
(),
'init.0.value'
);
$this
->
assertEqual
(
$violations
[
0
]
->
getMessage
(),
t
(
'This value is not a valid email address.'
));
Role
::
create
(
array
(
'id'
=>
'role1'
))
->
save
();
Role
::
create
(
array
(
'id'
=>
'role2'
))
->
save
();
// Test cardinality of user roles.
$user
=
entity_create
(
'user'
,
array
(
'name'
=>
'role_test'
,
...
...
@@ -144,8 +153,12 @@ function testValidation() {
));
$violations
=
$user
->
validate
();
$this
->
assertEqual
(
count
(
$violations
),
0
);
// @todo Test user role validation once https://drupal.org/node/2044859 got
// committed.
$user
->
roles
[
1
]
->
target_id
=
'unknown_role'
;
$violations
=
$user
->
validate
();
$this
->
assertEqual
(
count
(
$violations
),
1
);
$this
->
assertEqual
(
$violations
[
0
]
->
getPropertyPath
(),
'roles.1'
);
$this
->
assertEqual
(
$violations
[
0
]
->
getMessage
(),
t
(
'The referenced entity (%entity_type: %name) does not exist.'
,
array
(
'%entity_type'
=>
'user_role'
,
'%name'
=>
'unknown_role'
)));
}
/**
...
...
core/modules/user/tests/src/Unit/Plugin/Core/Entity/UserTest.php
View file @
e3e12db3
...
...
@@ -31,7 +31,7 @@ protected function createUserSession(array $rids = array()) {
$roles
=
array
();
foreach
(
$rids
as
$rid
)
{
$roles
[]
=
(
object
)
array
(
'
value
'
=>
$rid
,
'
target_id
'
=>
$rid
,
);
}
$user
->
expects
(
$this
->
any
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment