You are here

public static function MultipleRegistrationController::checkFieldAccess in Multiple Registration 8

Same name and namespace in other branches
  1. 8.2 src/Controller/MultipleRegistrationController.php \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess()
  2. 3.x src/Controller/MultipleRegistrationController.php \Drupal\multiple_registration\Controller\MultipleRegistrationController::checkFieldAccess()

Check is field available for role.

Parameters

array $fieldRoles: Array with assigned roles for the fields.

Return value

bool Returns access result.

2 calls to MultipleRegistrationController::checkFieldAccess()
multiple_registration_field_widget_form_alter in ./multiple_registration.module
Implements hook_field_widget_form_alter().
multiple_registration_form_alter in ./multiple_registration.module
Implements hook_form_alter().

File

src/Controller/MultipleRegistrationController.php, line 245

Class

MultipleRegistrationController
Class MultipleRegistrationController.

Namespace

Drupal\multiple_registration\Controller

Code

public static function checkFieldAccess(array $fieldRoles) {
  $routeMatch = \Drupal::routeMatch();
  $roles = [];
  switch ($routeMatch
    ->getRouteName()) {

    // Role page registration.
    case 'multiple_registration.role_registration_page':
      $roles = [
        $routeMatch
          ->getParameter('rid'),
      ];
      break;

    // Default registration.
    case 'user.register':
      $roles = [
        self::MULTIPLE_REGISTRATION_GENERAL_REGISTRATION_ID,
      ];
      break;

    // User edit page.
    case 'entity.user.edit_form':
      $roles = $routeMatch
        ->getParameter('user')
        ->getRoles();
      if (!static::useRegistrationPage($roles)) {

        // Fall back to 'General registered users' if user does not have any
        // special role.
        $roles = [
          self::MULTIPLE_REGISTRATION_GENERAL_REGISTRATION_ID,
        ];
      }
      break;
  }
  $extractKeys = array_intersect($roles, $fieldRoles);
  if (!empty($extractKeys)) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}