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;
|
public $preset;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var object The parent object that contains this field
|
|
||||||
*/
|
|
||||||
protected $parent = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param string $fieldName The name of the field
|
* @param string $fieldName The name of the field
|
||||||
* @param string $label The label 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->fieldName = $fieldName;
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
$this->parent = $parent;
|
$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.
|
* If this field belongs to a tab.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@ abstract class FormWidgetBase extends WidgetBase
|
||||||
*/
|
*/
|
||||||
protected $formField;
|
protected $formField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Backend\Widgets\Form The parent form that contains this field
|
||||||
|
*/
|
||||||
|
protected $parentForm = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Form field name.
|
* @var string Form field name.
|
||||||
*/
|
*/
|
||||||
|
|
@ -79,12 +84,23 @@ abstract class FormWidgetBase extends WidgetBase
|
||||||
'data',
|
'data',
|
||||||
'sessionKey',
|
'sessionKey',
|
||||||
'previewMode',
|
'previewMode',
|
||||||
'showLabels'
|
'showLabels',
|
||||||
|
'parentForm',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
parent::__construct($controller, $configuration);
|
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
|
* Returns the HTML element field name for this widget, used for capturing
|
||||||
* user input, passed back to the getSaveValue method when saving.
|
* user input, passed back to the getSaveValue method when saving.
|
||||||
|
|
|
||||||
|
|
@ -783,7 +783,7 @@ class Form extends WidgetBase
|
||||||
$label = $config['label'] ?? null;
|
$label = $config['label'] ?? null;
|
||||||
list($fieldName, $fieldContext) = $this->getFieldName($name);
|
list($fieldName, $fieldContext) = $this->getFieldName($name);
|
||||||
|
|
||||||
$field = new FormField($fieldName, $label, $this);
|
$field = new FormField($fieldName, $label);
|
||||||
|
|
||||||
if ($fieldContext) {
|
if ($fieldContext) {
|
||||||
$field->context = $fieldContext;
|
$field->context = $fieldContext;
|
||||||
|
|
@ -934,6 +934,7 @@ class Form extends WidgetBase
|
||||||
$widgetConfig->previewMode = $this->previewMode;
|
$widgetConfig->previewMode = $this->previewMode;
|
||||||
$widgetConfig->model = $this->model;
|
$widgetConfig->model = $this->model;
|
||||||
$widgetConfig->data = $this->data;
|
$widgetConfig->data = $this->data;
|
||||||
|
$widgetConfig->parentForm = $this;
|
||||||
|
|
||||||
$widgetName = $widgetConfig->widget;
|
$widgetName = $widgetConfig->widget;
|
||||||
$widgetClass = $this->widgetManager->resolveFormWidget($widgetName);
|
$widgetClass = $this->widgetManager->resolveFormWidget($widgetName);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue