mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Yet another change to perfect the getParentForm() method
This commit is contained in:
parent
39987677f0
commit
1c0fd1b419
@ -176,34 +176,18 @@ class FormField
|
||||
*/
|
||||
public $preset;
|
||||
|
||||
/**
|
||||
* @var object The parent object that contains this field
|
||||
*/
|
||||
protected $parent = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param string $fieldName The name of the field
|
||||
* @param string $label The label of the field
|
||||
* @param object $parent The containing object instance, defaults to null
|
||||
*/
|
||||
public function __construct($fieldName, $label, $parent = null)
|
||||
public function __construct($fieldName, $label)
|
||||
{
|
||||
$this->fieldName = $fieldName;
|
||||
$this->label = $label;
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the parent object for the field
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this field belongs to a tab.
|
||||
*/
|
||||
|
@ -50,6 +50,11 @@ abstract class FormWidgetBase extends WidgetBase
|
||||
*/
|
||||
protected $formField;
|
||||
|
||||
/**
|
||||
* @var Backend\Widgets\Form The parent form that contains this field
|
||||
*/
|
||||
protected $parentForm = null;
|
||||
|
||||
/**
|
||||
* @var string Form field name.
|
||||
*/
|
||||
@ -79,12 +84,23 @@ abstract class FormWidgetBase extends WidgetBase
|
||||
'data',
|
||||
'sessionKey',
|
||||
'previewMode',
|
||||
'showLabels'
|
||||
'showLabels',
|
||||
'parentForm',
|
||||
]);
|
||||
|
||||
parent::__construct($controller, $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the parent form for this formwidget
|
||||
*
|
||||
* @return Backend\Widgets\Form|null
|
||||
*/
|
||||
public function getParentForm()
|
||||
{
|
||||
return $this->parentForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML element field name for this widget, used for capturing
|
||||
* user input, passed back to the getSaveValue method when saving.
|
||||
|
@ -783,7 +783,7 @@ class Form extends WidgetBase
|
||||
$label = $config['label'] ?? null;
|
||||
list($fieldName, $fieldContext) = $this->getFieldName($name);
|
||||
|
||||
$field = new FormField($fieldName, $label, $this);
|
||||
$field = new FormField($fieldName, $label);
|
||||
|
||||
if ($fieldContext) {
|
||||
$field->context = $fieldContext;
|
||||
@ -934,6 +934,7 @@ class Form extends WidgetBase
|
||||
$widgetConfig->previewMode = $this->previewMode;
|
||||
$widgetConfig->model = $this->model;
|
||||
$widgetConfig->data = $this->data;
|
||||
$widgetConfig->parentForm = $this;
|
||||
|
||||
$widgetName = $widgetConfig->widget;
|
||||
$widgetClass = $this->widgetManager->resolveFormWidget($widgetName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user