mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Gives FormWidgets the ability to say: "No labels, please"
ping @keiosweb
This commit is contained in:
parent
89434928f1
commit
f869b8cc94
@ -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.
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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: ?>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user