Skip to content

[Form] Fix FormView API #4371

Closed
Closed
@webmozart

Description

@webmozart

In the course of the Form API clean-up, I would like to propose a fix that unfortunately has a pretty bad impact, BC-wise.

The API of FormView is inconsistent with the API of FormBuilder and Form in the following aspect:

<?php

// FormBuilder
$builder->add($child);
$builder->get('childName');
$builder->setAttribute('foo', 'bar');
$builder->getAttribute('foo');

// FormInterface
$form->add($child); // or $form[] = $child
$form->get('childName'); // or $form['childName']
// no setAttribute()
$form->getAttribute('foo');

// FormView
$view->addChild($child); // or $view[] = $child
$view->getChild('childName'); // or $view['childName']
$view->set('foo', 'bar');
$view->get('foo');
$view->all(); // or $view->getVars()

I think that this is confusing and should be made consistent before marking the API as stable.

<?php

$view->add($child); // or $view[] = $child
$view->get('childName'); // or $view['childName']
$view->setVar('foo', 'bar');
$view->getVar('foo');
$view->setVars(array(
    'foo' => ...
    'bar' => ...
));
$view->getVars();

Impact:

  • FormTypes setting variables in the FormView must be adapted
  • PHP templates must be adapted (to access getVar() instead of get())

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions