Yet another change to perfect the getParentForm() method

This commit is contained in:
Luke Towers 2019-01-10 18:59:29 -06:00
parent 39987677f0
commit 1c0fd1b419
3 changed files with 20 additions and 19 deletions

View File

@ -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.
*/

View File

@ -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.

View File

@ -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);