From a00fab348f6be484085c777ff4060f4dc0c34254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Wed, 2 Mar 2022 18:07:00 +0300 Subject: [PATCH 01/11] Update CheckboxField.php --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 401d42db277a0..ed7066b9913ea 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -138,7 +138,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - $data['value'] = $this->default ?: '1'; + $data['value'] = $this->default || $this->default === '0' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; return $data; From 6b50a5049b46a7a42c3caaf99b7a3ad6113aa1f4 Mon Sep 17 00:00:00 2001 From: Joomla! Bot Date: Mon, 27 Jun 2022 23:05:11 +0200 Subject: [PATCH 02/11] Phase 1 convert BRANCH to PSR-12 --- libraries/src/Form/Field/CheckboxField.php | 237 ++++++++++----------- 1 file changed, 117 insertions(+), 120 deletions(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index ed7066b9913ea..4f8b594979ffd 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -1,4 +1,5 @@ checked; - } - - return parent::__get($name); - } - - /** - * Method to set certain otherwise inaccessible properties of the form field object. - * - * @param string $name The property name for which to set the value. - * @param mixed $value The value of the property. - * - * @return void - * - * @since 3.2 - */ - public function __set($name, $value) - { - if ($name === 'checked') - { - $value = (string) $value; - $this->checked = ($value === 'true' || $value == $name || $value === '1'); - - return; - } - - parent::__set($name, $value); - } - - /** - * Method to attach a Form object to the field. - * - * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. - * @param mixed $value The form field value to validate. - * @param string $group The field name group control value. This acts as an array container for the field. - * For example if the field has name="foo" and the group value is set to "bar" then the - * full field name would end up being "bar[foo]". - * - * @return boolean True on success. - * - * @see FormField::setup() - * @since 3.2 - */ - public function setup(\SimpleXMLElement $element, $value, $group = null) - { - // Handle the default attribute - $default = (string) $element['default']; - - if ($default) - { - $test = $this->form->getValue((string) $element['name'], $group); - - $value = ($test == $default) ? $default : null; - } - - $return = parent::setup($element, $value, $group); - - if ($return) - { - $checked = (string) $this->element['checked']; - $this->checked = ($checked === 'true' || $checked === 'checked' || $checked === '1'); - - empty($this->value) || $this->checked ? null : $this->checked = true; - } - - return $return; - } - - /** - * Method to get the data to be passed to the layout for rendering. - * - * @return array - * - * @since 4.0.0 - */ - protected function getLayoutData() - { - $data = parent::getLayoutData(); - $data['value'] = $this->default || $this->default === '0' ? $this->default : '1'; - $data['checked'] = $this->checked || $this->value; - - return $data; - } + /** + * The form field type. + * + * @var string + * @since 1.7.0 + */ + protected $type = 'Checkbox'; + + /** + * Name of the layout being used to render the field + * + * @var string + * @since 4.0.0 + */ + protected $layout = 'joomla.form.field.checkbox'; + + /** + * The checked state of checkbox field. + * + * @var boolean + * @since 3.2 + */ + protected $checked = false; + + /** + * Method to get certain otherwise inaccessible properties from the form field object. + * + * @param string $name The property name for which to get the value. + * + * @return mixed The property value or null. + * + * @since 3.2 + */ + public function __get($name) + { + if ($name === 'checked') { + return $this->checked; + } + + return parent::__get($name); + } + + /** + * Method to set certain otherwise inaccessible properties of the form field object. + * + * @param string $name The property name for which to set the value. + * @param mixed $value The value of the property. + * + * @return void + * + * @since 3.2 + */ + public function __set($name, $value) + { + if ($name === 'checked') { + $value = (string) $value; + $this->checked = ($value === 'true' || $value == $name || $value === '1'); + + return; + } + + parent::__set($name, $value); + } + + /** + * Method to attach a Form object to the field. + * + * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * + * @return boolean True on success. + * + * @see FormField::setup() + * @since 3.2 + */ + public function setup(\SimpleXMLElement $element, $value, $group = null) + { + // Handle the default attribute + $default = (string) $element['default']; + + if ($default) { + $test = $this->form->getValue((string) $element['name'], $group); + + $value = ($test == $default) ? $default : null; + } + + $return = parent::setup($element, $value, $group); + + if ($return) { + $checked = (string) $this->element['checked']; + $this->checked = ($checked === 'true' || $checked === 'checked' || $checked === '1'); + + empty($this->value) || $this->checked ? null : $this->checked = true; + } + + return $return; + } + + /** + * Method to get the data to be passed to the layout for rendering. + * + * @return array + * + * @since 4.0.0 + */ + protected function getLayoutData() + { + $data = parent::getLayoutData(); + $data['value'] = $this->default || $this->default === '0' ? $this->default : '1'; + $data['checked'] = $this->checked || $this->value; + + return $data; + } } From e78c5602b1e2e00fe10f60f019796ec3eb9e427a Mon Sep 17 00:00:00 2001 From: Joomla! Bot Date: Mon, 27 Jun 2022 23:05:11 +0200 Subject: [PATCH 03/11] Phase 2 convert BRANCH to PSR-12 --- libraries/src/Form/Field/CheckboxField.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 4f8b594979ffd..c872ee1b820b9 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -9,8 +9,6 @@ namespace Joomla\CMS\Form\Field; -\defined('JPATH_PLATFORM') or die; - use Joomla\CMS\Form\FormField; /** From 9902b63424a91706cb146fe1b273af802cf57da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Mon, 24 Oct 2022 04:04:57 +0300 Subject: [PATCH 04/11] Update libraries/src/Form/Field/CheckboxField.php Co-authored-by: Benjamin Trenkle --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 64c0fe8df6109..41b540bcede62 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - $data['value'] = $this->default || $this->default === '0' ? $this->default : '1'; + $data['value'] = strlen($this->default) ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; return $data; From 116ed66fda5c5f20ca6046b535ca5dd1307a39cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Thu, 13 Jul 2023 12:31:14 +0300 Subject: [PATCH 05/11] Update CheckboxField.php --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 41b540bcede62..519727d2f0920 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - $data['value'] = strlen($this->default) ? $this->default : '1'; + $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; return $data; From 62dbe916050c99462cecf8aef24d7e8110e1bc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Thu, 13 Jul 2023 13:17:17 +0300 Subject: [PATCH 06/11] Update CheckboxField.php --- libraries/src/Form/Field/CheckboxField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 2bfe8e037fc3c..c14e70d061782 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,6 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); + // The explicitly set default value is '0' for using index definitions in arrays and tables of form values. $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; From 57af46d7d4311ae8ff66d0972be81a020508b072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Thu, 13 Jul 2023 13:19:31 +0300 Subject: [PATCH 07/11] Update CheckboxField.php --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index c14e70d061782..9290a893bcc1d 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - // The explicitly set default value is '0' for using index definitions in arrays and tables of form values. + // The explicitly set default value is '0' for using index definitions in arrays and tables of form fields. $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; From 8b05ef3365f0303c0d226e1d9ada114720310805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9?= Date: Thu, 13 Jul 2023 13:30:19 +0300 Subject: [PATCH 08/11] Update CheckboxField.php --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 9290a893bcc1d..3cf5dbd0ab69e 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - // The explicitly set default value is '0' for using index definitions in arrays and tables of form fields. + // The explicitly set default value is '0' for using index definitions in arrays and tables of form fields $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; From 17dd35322a14906fe65229ef1867cc1ea279d29f Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 19 Jan 2025 10:12:09 +0100 Subject: [PATCH 09/11] Improve code comment Co-authored-by: Tuan Pham Ngoc --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 836547a952c3c..3095c9bb34438 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - // The explicitly set default value is '0' for using index definitions in arrays and tables of form fields + // Allow using any none empty string like '0' as default value for checkbox $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; From cc9f262ae93c04a37ae943268f01fd7f1cfb7b23 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 19 Jan 2025 10:16:41 +0100 Subject: [PATCH 10/11] Again improvement of comment --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index 3095c9bb34438..e7ffcf8d00c53 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - // Allow using any none empty string like '0' as default value for checkbox + // Allow any non-empty string, such as '0,' to be used as the default value for a checkbox $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value; From 76a3db2041e6dc4464e118b338854da6787fdb04 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Sun, 19 Jan 2025 10:21:36 +0100 Subject: [PATCH 11/11] Fix typo in comment --- libraries/src/Form/Field/CheckboxField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Form/Field/CheckboxField.php b/libraries/src/Form/Field/CheckboxField.php index e7ffcf8d00c53..39b81ed0f6753 100644 --- a/libraries/src/Form/Field/CheckboxField.php +++ b/libraries/src/Form/Field/CheckboxField.php @@ -137,7 +137,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null) protected function getLayoutData() { $data = parent::getLayoutData(); - // Allow any non-empty string, such as '0,' to be used as the default value for a checkbox + // Allow any non-empty string, such as '0', to be used as the default value for a checkbox $data['value'] = $this->default !== null && $this->default !== '' ? $this->default : '1'; $data['checked'] = $this->checked || $this->value;