Verified Commit bb5178f2 authored by Dave Long's avatar Dave Long
Browse files

refactor: #3228209 Move hasRole() method from UserInterface to AccountInterface

By: matroskeen
By: dww
By: alexpott
By: berdir
By: catch
By: rosk0
By: pritishkumar
By: shalini_jha
(cherry picked from commit 83869c4f)
parent 74b86289
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -53,6 +53,17 @@ public function getRoles($exclude_locked_roles = FALSE);
   */
  public function hasPermission(string $permission);

  /**
   * Whether a user has a certain role.
   *
   * @param string $rid
   *   The role ID to check.
   *
   * @return bool
   *   Returns TRUE if the user has the role, otherwise FALSE.
   */
  public function hasRole(string $rid);

  /**
   * Returns TRUE if the account is authenticated.
   *
+0 −3
Original line number Diff line number Diff line
@@ -106,9 +106,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
   *
   * @return bool
   *   Returns TRUE if the user has the role, otherwise FALSE.
   *
   * @todo in Drupal 11, add method to Drupal\Core\Session\AccountInterface.
   * @see https://www.drupal.org/node/3228209
   */
  public function hasRole(string $rid): bool {
    return $this->getAccount()->hasRole($rid);
+0 −3
Original line number Diff line number Diff line
@@ -108,9 +108,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
   *
   * @return bool
   *   Returns TRUE if the user has the role, otherwise FALSE.
   *
   * @todo in Drupal 11, add method to Drupal\Core\Session\AccountInterface.
   * @see https://www.drupal.org/node/3228209
   */
  public function hasRole(string $rid): bool {
    return in_array($rid, $this->getRoles(), TRUE);
+1 −1
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ public function getRoles($exclude_locked_roles = FALSE) {
  /**
   * {@inheritdoc}
   */
  public function hasRole($rid) {
  public function hasRole(string $rid) {
    return in_array($rid, $this->getRoles());
  }

+0 −14
Original line number Diff line number Diff line
@@ -50,20 +50,6 @@ interface UserInterface extends ContentEntityInterface, EntityChangedInterface,
   */
  const TIMEZONE_SELECT = 2;

  /**
   * Whether a user has a certain role.
   *
   * @param string $rid
   *   The role ID to check.
   *
   * @return bool
   *   Returns TRUE if the user has the role, otherwise FALSE.
   *
   * @todo in Drupal 11, move method to Drupal\Core\Session\AccountInterface.
   * @see https://www.drupal.org/node/3228209
   */
  public function hasRole($rid);

  /**
   * Add a role to a user.
   *