public function getField(string $fieldName, EntityDefinition $definition, string $root): ?Field
    {
        $original = $fieldName;
        $prefix = $root . '.';

        if (strpos($fieldName, $prefix) === 0) {
            $fieldName = substr($fieldName, \strlen($prefix));
        }

        $fields = $definition->getFields();

        $isAssociation = 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) {
            return self::getTranslatedField($definition, $field);
        }

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

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

        return $this->getField(
            $original,
            $referenceDefinition,
            $root . '.' . $field->getPropertyName()
        );
    }
public function getField(string $fieldName, EntityDefinition $definition, string $root): ?Field
    {
        $original = $fieldName;
        $prefix = $root . '.';

        if (strpos($fieldName, $prefix) === 0) {
            $fieldName = substr($fieldName, \strlen($prefix));
        }

        $fields = $definition->getFields();

        $isAssociation = 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) {
            return self::getTranslatedField($definition, $field);
        }

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

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

        return $this->getField(
            $original,
            $referenceDefinition,
            $root . '.' . $field->getPropertyName()
        );
    }
public function getField ( string $ fieldName , EntityDefinition $ definition , string $ root ) : ? Field { $ original = $ fieldName ; $ prefix = $ root . '.' ; if ( strpos ( $ fieldName , $ prefix ) === 0 ) { $ fieldName = substr ( $ fieldName , \ strlen ( $ prefix ) ) ; } $ fields = $ definition -> getFields ( ) ; $ isAssociation = 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 ) { return self :: getTranslatedField ( $ definition , $ field ) ; } if ( ! $ field instanceof AssociationField ) { return $ field ; } $ referenceDefinition = $ field -> getReferenceDefinition ( ) ; if ( $ field instanceof ManyToManyAssociationField ) { $ referenceDefinition = $ field -> getToManyReferenceDefinition ( ) ; } return $ this -> getField ( $ original , $ referenceDefinition , $ root . '.' . $ field -> getPropertyName ( ) ) ; }
Returns the field instance of the provided fieldName.

@example

fieldName => 'product.name'
Returns the (new TranslatedField('name')) declaration

Allows additionally nested referencing

fieldName => 'category.products.name'
Returns as well the above field definition
Returns the field instance of the provided fieldName .