You are here

public function RequiredByRole::getMatches in Required by role 8

Helper method to test if the role exists into the allowed ones.

Parameters

array $user_roles: Roles belonging to the user.

array $required_roles: Roles that are required for this field.

Return value

bool Wether or not the user have a required role.

1 call to RequiredByRole::getMatches()
RequiredByRole::isRequired in src/Plugin/Required/RequiredByRole.php
Determines wether a field is required or not.

File

src/Plugin/Required/RequiredByRole.php, line 58
Contains \Drupal\required_by_role\Plugin\Required\RequiredByRole.

Class

RequiredByRole
Plugin annotation @Required( id = "required_by_role", admin_label = @Translation("Required by role"), label = @Translation("Required by role"), description = @Translation("Required based on current user roles.") )

Namespace

Drupal\required_by_role\Plugin\Required

Code

public function getMatches($user_roles, $required_roles) {
  $match = array_intersect((array) $user_roles, (array) $required_roles);
  return !empty($match);
}