getTranslatedField example

if (\in_array($field->getPropertyName()$handled, true)) {
                continue;
            }

            if (!$this->hasProperty($definition$field)) {
                continue;
            }

            $handled[] = $field->getPropertyName();

            if ($field instanceof TranslatedField) {
                $typed = EntityDefinitionQueryHelper::getTranslatedField($definition$field);

                if ($typed instanceof CustomFields) {
                    $calls[] = $this->renderCustomFields($field);
                }

                continue;
            }
            if ($field instanceof ParentAssociationField) {
                continue;
            }
            if ($field instanceof OneToManyAssociationField) {
                

        if (!$field instanceof TranslatedField) {
            throw DataAbstractionLayerException::invalidSerializerField(TranslatedField::class$field);
        }
        $key = $field->getPropertyName();
        if (!\array_key_exists($key$data)) {
            return $data;
        }

        $value = $data[$key];

        $translatedField = EntityDefinitionQueryHelper::getTranslatedField($parameters->getDefinition()$field);

        if (\is_array($value) && $translatedField instanceof JsonField === false) {
            foreach ($value as $translationKey => $translationValue) {
                if (!isset($data['translations'][$translationKey][$key])) {
                    $data['translations'][$translationKey][$key] = $translationValue;
                }
            }

            return $data;
        }

        
return null;
        }

        return implode('.', $path);
    }

    private function parseValue(EntityDefinition $definition, SingleFieldFilter $filter, mixed $value): mixed
    {
        $field = $this->getField($definition$filter->getField());

        if ($field instanceof TranslatedField) {
            $field = EntityDefinitionQueryHelper::getTranslatedField($definition$field);
        }

        if ($field instanceof CustomFields) {
            $accessor = \explode('.', $filter->getField());
            $last = \array_pop($accessor);

            $temp = $this->customFieldService->getCustomField($last);

            $field = $temp ?? $field;
        }

        
continue;
            }

            if (!\array_key_exists($key$row)) {
                continue;
            }

            $value = $row[$key];

            $typed = $field;
            if ($field instanceof TranslatedField) {
                $typed = EntityDefinitionQueryHelper::getTranslatedField($definition$field);
            }

            if ($typed instanceof CustomFields) {
                $this->customFields($definition$row$root$entity$field$context);

                continue;
            }

            if ($field instanceof TranslatedField) {
                // contains the resolved translation chain value                 $decoded = $typed->getSerializer()->decode($typed$value);
                
$isAssociation = mb_strpos($fieldName, '.') !== false;

        if (!$isAssociation && $fields->has($fieldName)) {
            return $fields->get($fieldName);
        }
        $associationKey = explode('.', $fieldName);
        $associationKey = array_shift($associationKey);

        $field = $fields->get($associationKey);

        if ($field instanceof TranslatedField && $resolveTranslated) {
            return self::getTranslatedField($definition$field);
        }
        if ($field instanceof TranslatedField) {
            return $field;
        }

        if (!$field instanceof AssociationField) {
            return $field;
        }

        $referenceDefinition = $field->getReferenceDefinition();
        if ($field instanceof ManyToManyAssociationField) {
            

        /** @var array<string, mixed> $flags */
        $flags = [];
        foreach ($field->getFlags() as $flag) {
            $flags = array_replace_recursive($flagsiterator_to_array($flag->parse()));
        }

        switch (true) {
            case $field instanceof TranslatedField:
                $property = $this->parseField(
                    $definition,
                    EntityDefinitionQueryHelper::getTranslatedField($definition$field)
                );
                $property['flags'] = array_replace_recursive($property['flags']$flags);
                $property['flags']['translatable'] = true;

                return $property;

                // fields with uuid             case $field instanceof VersionField:
            case $field instanceof ReferenceVersionField:
            case $field instanceof ParentFkField:
            case $field instanceof FkField:
            

  public function hasField($field_name) {
    return (bool) $this->getFieldDefinition($field_name);
  }

  /** * {@inheritdoc} */
  public function get($field_name) {
    if (!isset($this->fields[$field_name][$this->activeLangcode])) {
      return $this->getTranslatedField($field_name$this->activeLangcode);
    }
    return $this->fields[$field_name][$this->activeLangcode];
  }

  /** * Gets a translated field. * * @return \Drupal\Core\Field\FieldItemListInterface */
  protected function getTranslatedField($name$langcode) {
    if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) {
      
case $field instanceof ManyToManyAssociationField:
                $uses[] = $this->getUsage($field->getToManyReferenceDefinition()->getCollectionClass());
                $type = $this->getClassTypeHint($field->getToManyReferenceDefinition()->getCollectionClass());

                break;
            case $field instanceof ReferenceVersionField:
            case $field instanceof VersionField:
                return null;
            case $field instanceof TranslatedField:
                return $this->generateProperty(
                    $definition,
                    EntityDefinitionQueryHelper::getTranslatedField($definition$field)
                );
            case $field instanceof CartPriceField:
                $type = 'CartPrice';
                $uses[] = 'use ' . CartPrice::class;

                break;
            case $field instanceof CalculatedPriceField:
                $type = 'CalculatedPrice';
                $uses[] = 'use ' . CalculatedPrice::class;

                break;
            
Home | Imprint | This part of the site doesn't use cookies.