getFieldByPublicName example


  public function getRelated(ResourceType $resource_type, FieldableEntityInterface $entity$related, Request $request) {
    /** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $field_list */
    $resource_relationship = $resource_type->getFieldByPublicName($related);
    $field_list = $entity->get($resource_relationship->getInternalName());

    // Remove the entities pointing to a resource that may be disabled. Even     // though the normalizer skips disabled references, we can avoid unnecessary     // work by checking here too.     /** @var \Drupal\Core\Entity\EntityInterface[] $referenced_entities */
    $referenced_entities = array_filter(
      $field_list->referencedEntities(),
      function DEntityInterface $entity) {
        return (bool) $this->resourceTypeRepository->get(
          $entity->getEntityTypeId(),
          

  public function getRelatableResourceTypesByField($field_name) {
    return ($field = $this->getFieldByPublicName($field_name)) && $field instanceof ResourceTypeRelationship && $field->isFieldEnabled()
      ? $field->getRelatableResourceTypes()
      : [];
  }

  /** * Get the resource path. * * @return string * The path to access this resource type. The function * replaces "--" with "/" in the URI path. * Example: "node--article" -> "node/article". * * @see \Drupal\jsonapi\ResourceType\ResourceType::TYPE_NAME_URI_PATH_SEPARATOR * @see jsonapi.base_path */
Home | Imprint | This part of the site doesn't use cookies.