isChild example

protected function requiresValidation(
        Field $field,
        EntityExistence $existence,
        $value,
        WriteParameterBag $parameters
    ): bool {
        if ($value !== null) {
            return true;
        }

        if ($existence->isChild() && $this->isInherited($field$parameters)) {
            return false;
        }

        if ($existence->hasEntityName()
            && $this->definitionRegistry->getByEntityName($existence->getEntityName()) instanceof EntityTranslationDefinition
            && $parameters->getCurrentWriteLanguageId() !== Defaults::LANGUAGE_SYSTEM
        ) {
            return false;
        }

        return $field->is(Required::class);
    }

            } catch (WriteFieldException $e) {
                $parameters->getContext()->getExceptions()->add($e);
            }
        }

        return $stack->getResultAsArray();
    }

    private function skipField(Field $field, EntityExistence $existence): bool
    {
        if ($existence->isChild() && $field->is(Inherited::class)) {
            // inherited field of a child is never required             return true;
        }

        $create = !$existence->exists() || $existence->childChangedToParent();

        if (
            (!$field instanceof UpdatedAtField && !$field instanceof CreatedByField && !$field instanceof UpdatedByField)
            && (!$create || !$field->is(Required::class))
        ) {
            return true;
        }


    /** * {@inheritdoc} */
    public function getExistence(EntityDefinition $definition, array $primaryKey, array $data, WriteCommandQueue $commandQueue): EntityExistence
    {
        $state = $this->getCurrentState($definition$primaryKey$commandQueue);

        $exists = !empty($state);

        $isChild = $this->isChild($definition$data$state$primaryKey$commandQueue);

        $wasChild = $this->wasChild($definition$state);

        $decodedPrimaryKey = [];
        foreach ($primaryKey as $fieldStorageName => $fieldValue) {
            $field = $definition->getFields()->getByStorageName($fieldStorageName);
            $decodedPrimaryKey[$fieldStorageName] = $field ? $field->getSerializer()->decode($field$fieldValue) : $fieldValue;
        }

        return new EntityExistence($definition->getEntityName()$decodedPrimaryKey$exists$isChild$wasChild$state);
    }

    
public function getEntityName(): ?string
    {
        return $this->entityName;
    }

    public function childChangedToParent(): bool
    {
        if (!$this->wasChild()) {
            return false;
        }

        return !$this->isChild();
    }

    /** * @return array<string, mixed> */
    public function getState(): array
    {
        return $this->state;
    }
}
Home | Imprint | This part of the site doesn't use cookies.