extractViewVariables example

public function collectViewVariables(FormView $view): void
    {
        $hash = spl_object_hash($view);

        if (!isset($this->dataByView[$hash])) {
            $this->dataByView[$hash] = [];
        }

        $this->dataByView[$hash] = array_replace(
            $this->dataByView[$hash],
            $this->dataExtractor->extractViewVariables($view)
        );

        foreach ($view->children as $child) {
            $this->collectViewVariables($child);
        }
    }

    public function buildPreliminaryFormTree(FormInterface $form): void
    {
        $this->data['forms'][$form->getName()] = &$this->recursiveBuildPreliminaryFormTree($form$this->data['forms_by_hash']);
    }

    
$this->assertSame([
            'id' => 'foo_bar',
            'name' => 'bar',
            'view_vars' => [
                'a' => 'bar',
                'b' => 'foo',
                'c' => 'baz',
                'id' => 'foo_bar',
                'name' => 'bar',
            ],
        ]$this->dataExtractor->extractViewVariables($view));
    }

    private function createBuilder(string $name, array $options = []): FormBuilder
    {
        return new FormBuilder($name, null, new EventDispatcher()new FormFactory(new FormRegistry([]new ResolvedFormTypeFactory()))$options);
    }
}
Home | Imprint | This part of the site doesn't use cookies.