getDataReferencePropertyName example


      }

      // Determine if the next part is not a property of $field_name.       if (!static::isCandidateDefinitionProperty($parts[0]$candidate_definitions) && !empty(static::getAllDataReferencePropertyNames($candidate_definitions))) {
        // The next path part is neither a delta nor a field property, so it         // must be a field on a targeted resource type. We need to guess the         // intermediate reference property since one was not provided.         //         // For example, the path `uid.name` for a `node--article` resource type         // will be resolved into `uid.entity.name`.         $reference_breadcrumbs[] = static::getDataReferencePropertyName($candidate_definitions$parts$unresolved_path_parts);
      }
      else {
        // If the property is not a reference property, then all         // remaining parts must be further property specifiers.         if (!static::isCandidateDefinitionReferenceProperty($parts[0]$candidate_definitions)) {
          // If a field property is specified on a field with only one property           // defined, throw an error because in the JSON:API output, it does not           // exist. This is because JSON:API elides single-value properties;           // respecting it would leak this Drupalism out.           if (count($candidate_property_names) === 1) {
            throw new CacheableBadRequestHttpException($cacheabilitysprintf('Invalid nested filtering. The property `%s`, given in the path `%s`, does not exist. Filter by `%s`, not `%s` (the JSON:API module elides property names from single-property fields).', $parts[0]$external_field_namesubstr($external_field_name, 0, strlen($external_field_name) - strlen($parts[0]) - 1)$external_field_name));
          }

  public static function toResourceIdentifier(EntityReferenceItem $item$arity = NULL) {
    $property_name = static::getDataReferencePropertyName($item);
    $target = $item->get($property_name)->getValue();
    if ($target === NULL) {
      return static::getVirtualOrMissingResourceIdentifier($item);
    }
    assert($target instanceof EntityInterface);
    /** @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository */
    $resource_type_repository = \Drupal::service('jsonapi.resource_type.repository');
    $resource_type = $resource_type_repository->get($target->getEntityTypeId()$target->bundle());
    // Remove unwanted properties from the meta value, usually 'entity'     // and 'target_id'.     $properties = TypedDataInternalPropertiesHelper::getNonInternalProperties($item);
    
Home | Imprint | This part of the site doesn't use cookies.