-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for label/fieldset in serializer #30
base: master
Are you sure you want to change the base?
Changes from 2 commits
b4a60db
50fceb3
0b68342
09f8bf2
3f24d4a
45a48c9
ccd8e26
0d580d3
16f079e
ac1ba08
3dc02f5
5f2d560
62b7001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,11 @@ protected function serializeBlock(\DOMElement $parentElement, FormView $view, $b | |
} | ||
} | ||
|
||
if ($variables['label']) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CS issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow the PSR-2 CS. |
||
$this->serializeLabel($parentElement, $type, $variables); | ||
} | ||
|
||
if ($view->isRendered()) { | ||
return; | ||
} | ||
|
@@ -78,7 +83,15 @@ protected function serializeBlock(\DOMElement $parentElement, FormView $view, $b | |
$this->serializeUrlWidget($parentElement, $view, $variables); | ||
break; | ||
case 'choice': | ||
$this->serializeChoiceWidget($parentElement, $view, $variables); | ||
if ($variables['expanded']) | ||
{ | ||
$this->serializeFieldset($parentElement, $view, $variables); | ||
} | ||
else | ||
{ | ||
$this->serializeChoiceWidget($parentElement, $view, $variables); | ||
} | ||
|
||
break; | ||
case 'hidden': | ||
$this->serializeHiddenWidget($parentElement, $view, $variables); | ||
|
@@ -174,6 +187,7 @@ protected function serializeWidgetSimple(\DOMElement $parentElement, FormView $v | |
$parentElement->appendChild($inputElement); | ||
|
||
$inputElement->setAttribute('type', $variables['type']); | ||
$inputElement->setAttribute('id', $variables['id']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only be done once in |
||
|
||
if (!empty($variables['value'])) { | ||
$inputElement->setAttribute('value', $variables['value']); | ||
|
@@ -182,6 +196,15 @@ protected function serializeWidgetSimple(\DOMElement $parentElement, FormView $v | |
$this->addWidgetAttributes($inputElement, $view, $variables); | ||
} | ||
|
||
protected function serializeLabel(\DOMElement $parentElement, $type, $variables) | ||
{ | ||
$labelElement = $parentElement->ownerDocument->createElement('label',$variables['label']); | ||
$parentElement->appendChild($labelElement); | ||
|
||
$labelElement->setAttribute('for', $variables['id']); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line |
||
} | ||
|
||
/* | ||
id="{{ id }}" | ||
name="{{ full_name }}" | ||
|
@@ -237,6 +260,7 @@ protected function addWidgetAttributes(\DOMElement $widgetElement, FormView $vie | |
protected function serializeTextareaWidget(\DOMElement $parentElement, FormView $view, $variables) | ||
{ | ||
$textareaElement = $parentElement->ownerDocument->createElement('textarea', $variables['value']); | ||
$textareaElement->setAttribute('id', $variables['id']); | ||
$parentElement->appendChild($textareaElement); | ||
|
||
$this->addWidgetAttributes($textareaElement, $view, $variables); | ||
|
@@ -320,6 +344,15 @@ protected function serializeUrlWidget(\DOMElement $parentElement, FormView $view | |
$this->serializeWidgetSimple($parentElement, $view, $variables); | ||
} | ||
|
||
protected function serializeFieldset(\DOMElement $parentElement, FormView $view, $variables) | ||
{ | ||
$fieldsetElement = $parentElement->ownerDocument->createElement('fieldset'); | ||
$parentElement->appendChild($fieldsetElement); | ||
|
||
$fieldsetElement->setAttribute('id', $variables['id']); | ||
|
||
$this->serializeChoiceWidget($fieldsetElement, $view, $variables); | ||
} | ||
/* | ||
{% if expanded %} | ||
{{ block('choice_widget_expanded') }} | ||
|
@@ -329,6 +362,7 @@ protected function serializeUrlWidget(\DOMElement $parentElement, FormView $view | |
*/ | ||
protected function serializeChoiceWidget(\DOMElement $parentElement, FormView $view, $variables) | ||
{ | ||
|
||
return isset($variables['expanded']) && $variables['expanded'] | ||
? $this->serializeChoiceWidgetExpanded($parentElement, $view, $variables) | ||
: $this->serializeChoiceWidgetCollapsed($parentElement, $view, $variables) | ||
|
@@ -373,6 +407,8 @@ protected function serializeChoiceWidgetCollapsed(\DOMElement $parentElement, Fo | |
|
||
$this->addWidgetAttributes($selectElement, $view, $variables); | ||
|
||
$selectElement->setAttribute('id', $variables['id']); | ||
|
||
if (isset($variables['multiple']) && $variables['multiple']) { | ||
$selectElement->setAttribute('multiple', 'multiple'); | ||
} | ||
|
@@ -497,6 +533,7 @@ protected function serializeCheckboxWidget(\DOMElement $parentElement, FormView | |
{ | ||
$inputElement = $parentElement->ownerDocument->createElement('input'); | ||
$inputElement->setAttribute('type', 'checkbox'); | ||
$inputElement->setAttribute('id', $variables['id']); | ||
|
||
if (isset($variables['value'])) { | ||
$inputElement->setAttribute('value', $variables['value']); | ||
|
@@ -518,6 +555,7 @@ protected function serializeRadioWidget(\DOMElement $parentElement, FormView $vi | |
{ | ||
$inputElement = $parentElement->ownerDocument->createElement('input'); | ||
$inputElement->setAttribute('type', 'radio'); | ||
$inputElement->setAttribute('id', $variables['id']); | ||
|
||
if (isset($variables['value'])) { | ||
$inputElement->setAttribute('value', $variables['value']); | ||
|
@@ -567,6 +605,7 @@ protected function serializeDatetimeWidget(\DOMElement $parentElement, FormView | |
</div> | ||
{% endif %} | ||
*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separating the method from its phpdoc is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. involuntary ^^ |
||
protected function serializeDateWidget(\DOMElement $parentElement, FormView $view, $variables) | ||
{ | ||
if ('single_text' == $variables['widget']) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not consistent with the behavior of Symfony.
null
means that the label should be generated by humanizing the name.Disabling the label is only done when the value is
false
(as of Symfony 2.2, never done before)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good idea