Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.

See the detailed explanations there and look at the issues that already have patches or were commited.

Add get*, set* and additional methods as it makes sense to replace the public properties (e.g. isSomething() and something())

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

undertext’s picture

Assigned: Unassigned » undertext
steeloctopus’s picture

Assigned: undertext » steeloctopus
Issue summary: View changes
steeloctopus’s picture

Assigned: steeloctopus » Unassigned
steeloctopus’s picture

Assigned: Unassigned » steeloctopus

I believe I should be able to resolve this issue soon, but I'm very new to the drupal community so I will have a chat will drupal core mentoring team to find out more before I can resolve this problem

artem_sylchuk’s picture

Assigned: steeloctopus » Unassigned
Status: Active » Needs review
FileSize
1.93 KB

Hm, I started work on this month ago and created patch, but haven't posted here. I think it may be helpfull. I'll try to continue work on this.

Status: Needs review » Needs work

The last submitted patch, 5: drupal-role-entity-expand-methods-2030655-5.patch, failed testing.

The last submitted patch, 5: drupal-role-entity-expand-methods-2030655-5.patch, failed testing.

daffie’s picture

@james_kerrigan: I have reviewed your patch and it looks promising.
There are a couple of points I would like to make.

1. In the file: core/modules/user/lib/Drupal/user/RoleInterface.php

I have changed the documentation a bit to bring it in line with the drupal standard

  /**
   * Returns the role's weight.
   *
   * @return int
   *   The weight of this role.
   */
  public function getWeight();

  /**
   * Sets the role's weight.
   *
   * @param int $weight
   *   The desired weight.
   *
   * @return static
   *   The modified role.
   */
  public function setWeight($weight);

2. In the file: core/modules/user/lib/Drupal/user/Entity/Role.php

My suggestion for the function definitions would be:

  /**
   * {@inheritdoc}
   */
  public function getWeight() {
    return $this->get('weight')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setWeight($description) {
    $this->set('weight', $weight);
    return $this;
  }

Some of the public variables have to change to protected.

  protected $weight;
  protected $permissions = array();

And on line 128 you missed !isset($this->weight) to !$this->getWeight()

rdatar’s picture

Status: Needs work » Patch (to be ported)
FileSize
2.14 KB

Added call to getWeight() line 128.

rdatar’s picture

Status: Patch (to be ported) » Needs review
Sharique’s picture

@daffie documentation seems correct to me, same as in other parts of D8.

Status: Needs review » Needs work

The last submitted patch, 9: drupal-role-entity-expand-methods-2030655-9.patch, failed testing.

InternetDevels’s picture

Status: Needs work » Needs review
FileSize
2.08 KB

I've got some problems with changing class properties ro protected.
First of all fails core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php 114 here:

$this->assertEqual($role->weight, $new_role_weights[$role->id()]);

Looks like it is something with role save. I'll try to continue work but maybe somebody else find a solution for this faster.

Status: Needs review » Needs work

The last submitted patch, 13: drupal-role-entity-expand-methods-2030655-13.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
FileSize
14.09 KB

Status: Needs review » Needs work

The last submitted patch, 15: expand-role-with-methods-2030655-15.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review
FileSize
13.61 KB
pcambra’s picture

Just a plain reroll of this.

Alumei’s picture

And again a plain re-roll.

dawehner’s picture

  1. +++ b/core/modules/user/lib/Drupal/user/Plugin/views/argument_validator/User.php
    @@ -10,6 +10,7 @@
    @@ -157,7 +158,7 @@ public function validateArgument($argument) {
    
    @@ -157,7 +158,7 @@ public function validateArgument($argument) {
    +    $this->argument->validated_title = String::checkPlain(user_format_name($account));
    

    If you change this you can also use $account->getUsername();

  2. +++ b/core/modules/user/lib/Drupal/user/RoleInterface.php
    @@ -55,4 +55,23 @@ public function grantPermission($permission);
    +  /**
    +   * Returns the weight.
    +   *
    

    Maybe it would be a little bit helpful to explain what a weight of a role means.

Alumei’s picture

Contains fix of #20.1 but for #20.2 I'm at loss. I actually do not know about the weight part of user roles.

jamesquinton’s picture

Assigned: Unassigned » jamesquinton
Status: Needs review » Needs work
Issue tags: +Needs reroll

I'm going to reroll the patch.

jamesquinton’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
12.54 KB

Reroll for patch in #21

jamesquinton’s picture

Assigned: jamesquinton » Unassigned
dawehner’s picture

All those check_plain => String::checkPlain changes are certainly fine, thought they seem to be a little bit out of scope.

  1. +++ b/core/modules/user/lib/Drupal/user/Entity/Role.php
    @@ -150,4 +150,25 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
    +    return $this->get('weight') ? TRUE : FALSE;
    

    You could simply go with return (bool) $this->get('weight')/$this->getWeight()

  2. +++ b/core/modules/user/lib/Drupal/user/RoleInterface.php
    @@ -55,4 +55,31 @@ public function grantPermission($permission);
    +   * @return \Drupal\user\RoleInterface
    +   *   The class instance this method is called on.
    

    We do use now just @return $this and no doc line below

cosmicdreams’s picture

Issue tags: +Needs followup
ericduran’s picture

Issue tags: +Needs reroll
justafish’s picture

I rerolled and removed the hasWeight function as I don't think it makes sense - something could have a weight of 0 and this method would return false. I also changed the documentation as per #25. Everything else looks good to me.

Status: Needs review » Needs work

The last submitted patch, 28: expand-role-with-methods-reroll-2030655-27.patch, failed testing.

justafish’s picture

justafish’s picture

Status: Needs work » Needs review
justafish’s picture

Status: Needs review » Needs work

The last submitted patch, 30: expand-role-with-methods-reroll-2030655-30.patch, failed testing.

justafish’s picture

Status: Needs work » Needs review
justafish’s picture

Status: Needs review » Needs work
justafish’s picture

Status: Needs work » Needs review
justafish’s picture

same patch, testbot isn't picking it up from #32 :|

justafish’s picture

Coding standards and spelling correction

mtift’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/src/RoleInterface.php
@@ -39,8 +39,7 @@ public function hasPermission($permission);
+   * @return $this

@@ -55,4 +54,23 @@ public function grantPermission($permission);
+   * @return \Drupal\user\RoleInterface
+   *   The class instance this method is called on.

These should both be @return self

These should both be @return $this: https://drupal.org/node/1354#types

justafish’s picture

I've removed the conversion of check_plain as it's already being done in #2089331: [meta] Replace calls to check_plain() with Drupal\Component\Utility\String::checkPlain()
New patch also switches the property visibility to protected.

justafish’s picture

Status: Needs work » Needs review
justafish’s picture

justafish’s picture

justafish’s picture

justafish’s picture

Assigned: Unassigned » justafish
justafish’s picture

FileSize
4.99 KB
alexpott’s picture

Issue tags: -Needs followup, -Needs reroll
FileSize
1.2 KB
4.91 KB

wwhurley queued 47: 2030655.47.patch for re-testing.

wwhurley’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.8 KB

Patch applies mostly cleanly, just a little fuzz on a couple of hunks. Attached is a re-roll moving the start lines down a bit. Tested manually manipulating user roles and the patched version works as intended.

  • catch committed 028920c on 8.x
    Issue #2030655 by justafish, Alumei, daffie, alexpott, wwhurley,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.