Symfony\Component\Form\Extension\DataCollector\FormDataCollector::collectConfiguration PHP Method

collectConfiguration() public method

public collectConfiguration ( Symfony\Component\Form\FormInterface $form )
$form Symfony\Component\Form\FormInterface
    public function collectConfiguration(FormInterface $form)
    {
        $hash = spl_object_hash($form);

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

        $this->dataByForm[$hash] = array_replace(
            $this->dataByForm[$hash],
            $this->dataExtractor->extractConfiguration($form)
        );

        foreach ($form as $child) {
            $this->collectConfiguration($child);
        }
    }

Usage Example

Exemplo n.º 1
0
 public function testChildViewsWithoutCorrespondingChildFormsMayBeExplicitlyAssociated()
 {
     // don't add $this->childForm to $this->form!
     $this->view->children['child'] = $this->childView;
     // but associate the two
     $this->dataCollector->associateFormWithView($this->childForm, $this->childView);
     $this->dataExtractor->expects($this->at(0))->method('extractConfiguration')->with($this->form)->will($this->returnValue(array('config' => 'foo')));
     $this->dataExtractor->expects($this->at(1))->method('extractConfiguration')->with($this->childForm)->will($this->returnValue(array('config' => 'bar')));
     // explicitly call collectConfiguration(), since $this->childForm is not
     // contained in the form tree
     $this->dataCollector->collectConfiguration($this->form);
     $this->dataCollector->collectConfiguration($this->childForm);
     $this->dataCollector->buildFinalFormTree($this->form, $this->view);
     $this->assertSame(array('forms' => array('name' => array('config' => 'foo', 'children' => array('child' => array('config' => 'bar', 'children' => array())))), 'nb_errors' => 0), $this->dataCollector->getData());
 }