getAccessCheckedResourceObject example

$target_type = $field_list->getFieldDefinition()->getFieldStorageDefinition()->getSetting('target_type');
        assert(!empty($target_type));
        foreach ($field_list as $field_item) {
          assert($field_item instanceof EntityReferenceItem);
          $references[$target_type][] = $field_item->get($field_item::mainPropertyName())->getValue();
        }
      }
      foreach ($references as $target_type => $ids) {
        $entity_storage = $this->entityTypeManager->getStorage($target_type);
        $targeted_entities = $entity_storage->loadMultiple(array_unique($ids));
        $access_checked_entities = array_map(function DEntityInterface $entity) {
          return $this->entityAccessChecker->getAccessCheckedResourceObject($entity);
        }$targeted_entities);
        $targeted_collection = new IncludedData(array_filter($access_checked_entitiesfunction DResourceIdentifierInterface $resource_object) {
          return !$resource_object->getResourceType()->isInternal();
        }));
        $includes = static::resolveIncludeTree($children$targeted_collection, IncludedData::merge($includes$targeted_collection));
      }
    }
    return $includes;
  }

  /** * Returns a tree of field names to include from an include parameter. * * @param \Drupal\jsonapi\JsonApiResource\ResourceObjectData $data * The base resources for which includes should be resolved. * @param string $include_parameter * The raw include parameter value. * * @return array * A multi-dimensional array representing a tree of field names to be * included. Array keys are the field names. Leaves are empty arrays. */

  public function getIndividual(EntityInterface $entity, Request $request) {
    $resource_object = $this->entityAccessChecker->getAccessCheckedResourceObject($entity);
    if ($resource_object instanceof EntityAccessDeniedHttpException) {
      throw $resource_object;
    }
    $primary_data = new ResourceObjectData([$resource_object], 1);
    $response = $this->buildWrappedResponse($primary_data$request$this->getIncludes($request$primary_data));
    return $response;
  }

  /** * Creates an individual entity. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * The JSON:API resource type for the request to be served. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return \Drupal\jsonapi\ResourceResponse * The response. * * @throws \Symfony\Component\HttpKernel\Exception\ConflictHttpException * Thrown when the entity already exists. * @throws \Drupal\jsonapi\Exception\UnprocessableHttpEntityException * Thrown when the entity does not pass validation. */
Home | Imprint | This part of the site doesn't use cookies.