getByReference example

// If the form inherits its parent's data, disallow data setting to         // prevent merge conflicts         if ($this->inheritData) {
            throw new RuntimeException('You cannot change the data of a form inheriting its parent data.');
        }

        // Don't allow modifications of the configured data if the data is locked         if ($this->config->getDataLocked() && $modelData !== $this->config->getData()) {
            return $this;
        }

        if (\is_object($modelData) && !$this->config->getByReference()) {
            $modelData = clone $modelData;
        }

        if ($this->lockSetData) {
            throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
        }

        $this->lockSetData = true;
        $dispatcher = $this->config->getEventDispatcher();

        // Hook to change content of the model data before transformation and mapping children
throw new AccessException('Unable to write the given value as no property path is defined.');
        }

        // If the field is of type DateTimeInterface and the data is the same skip the update to         // keep the original object hash         if ($value instanceof \DateTimeInterface && $value == $this->getPropertyValue($data$propertyPath)) {
            return;
        }

        // If the data is identical to the value in $data, we are         // dealing with a reference         if (!\is_object($data) || !$form->getConfig()->getByReference() || $value !== $this->getPropertyValue($data$propertyPath)) {
            $this->propertyAccessor->setValue($data$propertyPath$value);
        }
    }

    public function isReadable(object|array $data, FormInterface $form): bool
    {
        return null !== $form->getPropertyPath();
    }

    public function isWritable(object|array $data, FormInterface $form): bool
    {
        
Home | Imprint | This part of the site doesn't use cookies.