getFieldAccess example

// We have a valid field, so add it to the validated trail of path parts.       $reference_breadcrumbs[] = $field_name;

      // Remove resource types which do not have a candidate definition.       $resource_types = array_filter($resource_typesfunction DResourceType $resource_type) use ($candidate_definitions) {
        return isset($candidate_definitions[$resource_type->getTypeName()]);
      });

      // Check access to execute a query for each field per resource type since       // field definitions are bundle-specific.       foreach ($resource_types as $resource_type) {
        $field_access = $this->getFieldAccess($resource_type$field_name);
        $cacheability->addCacheableDependency($field_access);
        if (!$field_access->isAllowed()) {
          $message = sprintf('The current user is not authorized to filter by the `%s` field, given in the path `%s`.', $field_nameimplode('.', $reference_breadcrumbs));
          if ($field_access instanceof AccessResultReasonInterface && ($reason = $field_access->getReason()) && !empty($reason)) {
            $message .= ' ' . $reason;
          }
          throw new CacheableAccessDeniedHttpException($cacheability$message);
        }
      }

      // Get all of the referenceable resource types.
Home | Imprint | This part of the site doesn't use cookies.