From 1c0fd1b419891c89bd154780d479ac4d441d4e9b Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Thu, 10 Jan 2019 18:59:29 -0600 Subject: [PATCH] Yet another change to perfect the getParentForm() method --- modules/backend/classes/FormField.php | 18 +----------------- modules/backend/classes/FormWidgetBase.php | 18 +++++++++++++++++- modules/backend/widgets/Form.php | 3 ++- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index bb646fba9..84196e433 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -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. */ diff --git a/modules/backend/classes/FormWidgetBase.php b/modules/backend/classes/FormWidgetBase.php index a9616e32f..91bbf2be2 100644 --- a/modules/backend/classes/FormWidgetBase.php +++ b/modules/backend/classes/FormWidgetBase.php @@ -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. diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 12ea21455..e34bc234e 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -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);