Gives FormWidgets the ability to say: "No labels, please"

ping @keiosweb
This commit is contained in:
Samuel Georges 2015-03-03 20:24:14 +11:00
parent 89434928f1
commit f869b8cc94
3 changed files with 33 additions and 6 deletions

View File

@ -41,6 +41,11 @@ abstract class FormWidgetBase extends WidgetBase
*/
public $previewMode = false;
/**
* @var bool Determines if this form field should display comments and labels.
*/
public $showLabels = true;
/**
* Constructor
* @param $controller Controller Active controller object.

View File

@ -738,7 +738,7 @@ class Form extends WidgetBase
* @param string $field Field name
* @return array [columnName, context]
*/
public function getFieldName($field)
protected function getFieldName($field)
{
if (strpos($field, '@') === false) {
return [$field, null];
@ -748,9 +748,11 @@ class Form extends WidgetBase
}
/**
* Looks up the column
* Looks up the field value.
* @param use Backend\Classes\FormField $field
* @return string
*/
public function getFieldValue($field)
protected function getFieldValue($field)
{
if (is_string($field)) {
if (!isset($this->allFields[$field])) {
@ -776,7 +778,7 @@ class Form extends WidgetBase
* @param use Backend\Classes\FormField $field
* @return string
*/
public function getFieldDepends($field)
protected function getFieldDepends($field)
{
if (!$field->dependsOn) {
return;
@ -787,6 +789,26 @@ class Form extends WidgetBase
return $dependsOn;
}
/**
* Helper method to determine if field should be rendered
* with label and comments.
* @param use Backend\Classes\FormField $field
* @return boolean
*/
protected function showFieldLabels($field)
{
if (in_array($field->type, ['checkbox', 'switch', 'section'])) {
return false;
}
if ($field->type == 'widget') {
$widget = $this->makeFormWidget($field);
return $widget->showLabels;
}
return true;
}
/**
* Returns postback data from a submitted form.
*/

View File

@ -1,8 +1,8 @@
<?php if (!$field->hidden): ?>
<?php if (in_array($field->type, ['checkbox', 'switch', 'section'])): ?>
<?php if (!$this->showFieldLabels($field)): ?>
<?= $this->makePartial('field_'.$field->type, ['field' => $field]) ?>
<?= $this->renderFieldElement($field) ?>
<?php else: ?>