public function getAssociatedTags(EntityDefinition $definition, Entity $entity, Context $context): array
    {
        $associations = $definition->getFields()->filterInstance(AssociationField::class);

        $keys = [$this->getEntityTag($entity->getUniqueIdentifier(), $definition)];

        foreach ($context->getLanguageIdChain() as $languageId) {
            $keys[] = $this->getEntityTag($languageId, $this->languageDefinition);
        }

        $translationDefinition = $definition->getTranslationDefinition();

        if ($translationDefinition) {
            /* @var EntityDefinition $translationDefinition */
            $keys[] = $translationDefinition->getEntityName() . '.language_id';
        }

        /** @var AssociationField[] $associations */
        foreach ($associations as $association) {
            if ($association->is(Extension::class)) {
                $value = $entity->getExtension($association->getPropertyName());
            } else {
                try {
                    $value = $entity->get($association->getPropertyName());
                } catch (\Exception $e) {
                    continue;
                }
            }

            if (!$value) {
                continue;
            }

            if ($association instanceof ManyToOneAssociationField || $association instanceof OneToOneAssociationField) {
                /* @var Entity $value */
                $nested = $this->getAssociatedTags($association->getReferenceDefinition(), $value, $context);
                foreach ($nested as $key) {
                    $keys[] = $key;
                }

                continue;
            }

            if ($association instanceof OneToManyAssociationField) {
                /** @var Entity[] $value */
                foreach ($value as $item) {
                    $nested = $this->getAssociatedTags($association->getReferenceDefinition(), $item, $context);
                    foreach ($nested as $key) {
                        $keys[] = $key;
                    }
                }

                continue;
            }

            if ($association instanceof ManyToManyAssociationField) {
                /** @var Entity[] $value */
                foreach ($value as $item) {
                    $nested = $this->getAssociatedTags($association->getToManyReferenceDefinition(), $item, $context);
                    foreach ($nested as $key) {
                        $keys[] = $key;
                    }
                }
            }
        }

        return array_keys(array_flip($keys));
    }
public function getAssociatedTags(EntityDefinition $definition, Entity $entity, Context $context): array
    {
        $associations = $definition->getFields()->filterInstance(AssociationField::class);

        $keys = [$this->getEntityTag($entity->getUniqueIdentifier(), $definition)];

        foreach ($context->getLanguageIdChain() as $languageId) {
            $keys[] = $this->getEntityTag($languageId, $this->languageDefinition);
        }

        $translationDefinition = $definition->getTranslationDefinition();

        if ($translationDefinition) {
            /* @var EntityDefinition $translationDefinition */
            $keys[] = $translationDefinition->getEntityName() . '.language_id';
        }

        /** @var AssociationField[] $associations */
        foreach ($associations as $association) {
            if ($association->is(Extension::class)) {
                $value = $entity->getExtension($association->getPropertyName());
            } else {
                try {
                    $value = $entity->get($association->getPropertyName());
                } catch (\Exception $e) {
                    continue;
                }
            }

            if (!$value) {
                continue;
            }

            if ($association instanceof ManyToOneAssociationField || $association instanceof OneToOneAssociationField) {
                /* @var Entity $value */
                $nested = $this->getAssociatedTags($association->getReferenceDefinition(), $value, $context);
                foreach ($nested as $key) {
                    $keys[] = $key;
                }

                continue;
            }

            if ($association instanceof OneToManyAssociationField) {
                /** @var Entity[] $value */
                foreach ($value as $item) {
                    $nested = $this->getAssociatedTags($association->getReferenceDefinition(), $item, $context);
                    foreach ($nested as $key) {
                        $keys[] = $key;
                    }
                }

                continue;
            }

            if ($association instanceof ManyToManyAssociationField) {
                /** @var Entity[] $value */
                foreach ($value as $item) {
                    $nested = $this->getAssociatedTags($association->getToManyReferenceDefinition(), $item, $context);
                    foreach ($nested as $key) {
                        $keys[] = $key;
                    }
                }
            }
        }

        return array_keys(array_flip($keys));
    }
public function getAssociatedTags ( EntityDefinition $ definition , Entity $ entity , Context $ context ) : array { $ associations = $ definition -> getFields ( ) -> filterInstance ( AssociationField :: class ) ; $ keys = [ $ this -> getEntityTag ( $ entity -> getUniqueIdentifier ( ) , $ definition ) ] ; foreach ( $ context -> getLanguageIdChain ( ) as $ languageId ) { $ keys [ ] = $ this -> getEntityTag ( $ languageId , $ this -> languageDefinition ) ; } $ translationDefinition = $ definition -> getTranslationDefinition ( ) ; if ( $ translationDefinition ) { /* @var EntityDefinition $translationDefinition */ $ keys [ ] = $ translationDefinition -> getEntityName ( ) . '.language_id' ; } /** @var AssociationField[] $associations */ foreach ( $ associations as $ association ) { if ( $ association -> is ( Extension :: class ) ) { $ value = $ entity -> getExtension ( $ association -> getPropertyName ( ) ) ; } else { try { $ value = $ entity -> get ( $ association -> getPropertyName ( ) ) ; } catch ( \ Exception $ e ) { continue ; } } if ( ! $ value ) { continue ; } if ( $ association instanceof ManyToOneAssociationField || $ association instanceof OneToOneAssociationField ) { /* @var Entity $value */ $ nested = $ this -> getAssociatedTags ( $ association -> getReferenceDefinition ( ) , $ value , $ context ) ; foreach ( $ nested as $ key ) { $ keys [ ] = $ key ; } continue ; } if ( $ association instanceof OneToManyAssociationField ) { /** @var Entity[] $value */ foreach ( $ value as $ item ) { $ nested = $ this -> getAssociatedTags ( $ association -> getReferenceDefinition ( ) , $ item , $ context ) ; foreach ( $ nested as $ key ) { $ keys [ ] = $ key ; } } continue ; } if ( $ association instanceof ManyToManyAssociationField ) { /** @var Entity[] $value */ foreach ( $ value as $ item ) { $ nested = $ this -> getAssociatedTags ( $ association -> getToManyReferenceDefinition ( ) , $ item , $ context ) ; foreach ( $ nested as $ key ) { $ keys [ ] = $ key ; } } } } return array_keys ( array_flip ( $ keys ) ) ; }
Calculates all tags for a single entity. Considers the language chain, context states and loaded associations
Calculates all tags for a single entity . Considers the language chain context states and loaded associations