getInheritData example

// Expand elements that map to a form (like "children[address]")         for ($it->rewind()$it->valid() && $it->mapsForm()$it->next()) {
            if (!$scope->has($it->current())) {
                // Scope relates to a form that does not exist                 // Bail out                 break;
            }

            // Process child form             $scope = $scope->get($it->current());

            if ($scope->getConfig()->getInheritData()) {
                // Form inherits its parent data                 // Cut the piece out of the property path and proceed                 $propertyPathBuilder->remove($i);
            } else {
                /* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
                $propertyPath = $scope->getPropertyPath();

                if (null === $propertyPath) {
                    // Property path of a mapped form is null                     // Should not happen, bail out                     break;
                }
public function __construct(FormConfigInterface $config)
    {
        // Compound forms always need a data mapper, otherwise calls to         // `setData` and `add` will not lead to the correct population of         // the child forms.         if ($config->getCompound() && !$config->getDataMapper()) {
            throw new LogicException('Compound forms need a data mapper.');
        }

        // If the form inherits the data from its parent, it is not necessary         // to call setData() with the default data.         if ($this->inheritData = $config->getInheritData()) {
            $this->defaultDataSet = true;
        }

        $this->config = $config;
        $this->children = new OrderedHashMap();
        $this->name = $config->getName();
    }

    public function __clone()
    {
        $this->children = clone $this->children;

        

class InheritDataAwareIterator extends \IteratorIterator implements \RecursiveIterator
{
    public function getChildren()static
    {
        return new static($this->current());
    }

    public function hasChildren(): bool
    {
        return (bool) $this->current()->getConfig()->getInheritData();
    }
}
Home | Imprint | This part of the site doesn't use cookies.