From 69c322daa30c27607e27884ccd6b272b4db04957 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Tue, 4 Mar 2025 17:39:05 +0200 Subject: [PATCH 1/8] 44962: remove trashed status from new article page --- administrator/components/com_content/forms/article.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/administrator/components/com_content/forms/article.xml b/administrator/components/com_content/forms/article.xml index 3552fd15608ec..28b819f6c283b 100644 --- a/administrator/components/com_content/forms/article.xml +++ b/administrator/components/com_content/forms/article.xml @@ -77,7 +77,6 @@ - Date: Tue, 4 Mar 2025 20:24:14 +0200 Subject: [PATCH 2/8] 44962: remove trashed status from new article page only --- .../components/com_content/forms/article.xml | 1 + .../com_content/tmpl/article/edit.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/administrator/components/com_content/forms/article.xml b/administrator/components/com_content/forms/article.xml index 28b819f6c283b..3552fd15608ec 100644 --- a/administrator/components/com_content/forms/article.xml +++ b/administrator/components/com_content/forms/article.xml @@ -77,6 +77,7 @@ + + + \ No newline at end of file From ecb2959592129dfa0b37dcf2252e7562bab4b1e6 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Tue, 4 Mar 2025 22:12:32 +0200 Subject: [PATCH 3/8] 44962: remove trashed status from new article page --- administrator/components/com_content/tmpl/article/edit.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index 4a68e022d1506..cb8fc0efd6378 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -193,10 +193,9 @@ if (articleIdField.value == "0") { var stateDropdown = document.querySelector("select[name='jform[state]']"); if (stateDropdown) { - for (var i = 0; i < stateDropdown.options.length; i++) { - if (stateDropdown.options[i].value == "-2") { - stateDropdown.options[i].remove(); // Remove "Trashed" - } + let trashedOption = stateDropdown.querySelector("option[value='-2']"); + if (trashedOption) { + trashedOption.remove(); } } } From aff099bb75247a89bf6feab53ad83df868c2325a Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Wed, 5 Mar 2025 14:39:44 +0200 Subject: [PATCH 4/8] centrelize the remove trash option method --- .../com_content/src/Model/ArticleModel.php | 5 +++++ .../com_content/tmpl/article/edit.php | 16 -------------- libraries/src/Form/Field/ListField.php | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index 4414e43079d02..fa04d9aecf17f 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -483,6 +483,11 @@ public function getForm($data = [], $loadData = true) $record->id = $id; + if ($id == 0) { + $stateField = $form->getField('state'); + $stateField->removeTrashedOption(); + } + // For new articles we load the potential state + associations if ($id == 0 && $formField = $form->getField('catid')) { $assignedCatids = $data['catid'] ?? $form->getValue('catid'); diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index cb8fc0efd6378..e794dfd8cc4bc 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -185,19 +185,3 @@ - - \ No newline at end of file diff --git a/libraries/src/Form/Field/ListField.php b/libraries/src/Form/Field/ListField.php index 191eb0b909c60..9ddf0535c5bc6 100644 --- a/libraries/src/Form/Field/ListField.php +++ b/libraries/src/Form/Field/ListField.php @@ -231,6 +231,27 @@ public function addOption($text, $attributes = []) return $this; } + /** + * Method to remove the trashed option from the list field. + * + * @return ListField For chaining. + * + * @since 3.7.0 + */ + public function removeTrashedOption() + { + if ($this->element instanceof \SimpleXMLElement && ($list = $this->element->xpath('option'))) { + foreach ($list as $option) { + if ((string) $option['value'] === '-2') { + $dom = dom_import_simplexml($option); + $dom->parentNode->removeChild($dom); + + break; + } + } + } + } + /** * Method to get certain otherwise inaccessible properties from the form field object. * From 113e563798d7e689780732042d7fcd2a51f92401 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Wed, 5 Mar 2025 15:05:42 +0200 Subject: [PATCH 5/8] centrelize the remove trash option method in FormField --- libraries/src/Form/Field/ListField.php | 21 --------------------- libraries/src/Form/FormField.php | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/libraries/src/Form/Field/ListField.php b/libraries/src/Form/Field/ListField.php index 9ddf0535c5bc6..191eb0b909c60 100644 --- a/libraries/src/Form/Field/ListField.php +++ b/libraries/src/Form/Field/ListField.php @@ -231,27 +231,6 @@ public function addOption($text, $attributes = []) return $this; } - /** - * Method to remove the trashed option from the list field. - * - * @return ListField For chaining. - * - * @since 3.7.0 - */ - public function removeTrashedOption() - { - if ($this->element instanceof \SimpleXMLElement && ($list = $this->element->xpath('option'))) { - foreach ($list as $option) { - if ((string) $option['value'] === '-2') { - $dom = dom_import_simplexml($option); - $dom->parentNode->removeChild($dom); - - break; - } - } - } - } - /** * Method to get certain otherwise inaccessible properties from the form field object. * diff --git a/libraries/src/Form/FormField.php b/libraries/src/Form/FormField.php index c0c0c9274662f..47a105b54aa68 100644 --- a/libraries/src/Form/FormField.php +++ b/libraries/src/Form/FormField.php @@ -898,6 +898,24 @@ protected function getName($fieldName) return $name; } + /** + * Method to remove the trashed option from new items in the list field. + * @since __DEPLOY_VERSION__ + */ + public function removeTrashedOption() + { + if ($this->element instanceof \SimpleXMLElement && ($list = $this->element->xpath('option'))) { + foreach ($list as $option) { + if ((string) $option['value'] === '-2') { + $dom = dom_import_simplexml($option); + $dom->parentNode->removeChild($dom); + + break; + } + } + } + } + /** * Method to get the field name used. * From 3c326bb2f78fe1e0aff8df9bc3e9917b54669a96 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Wed, 5 Mar 2025 16:16:57 +0200 Subject: [PATCH 6/8] generalize removeOption method --- .../com_content/src/Model/ArticleModel.php | 12 +++++++--- libraries/src/Form/Field/ListField.php | 23 +++++++++++++++++++ libraries/src/Form/FormField.php | 18 --------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index fa04d9aecf17f..d660a7c2cebea 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -483,9 +483,15 @@ public function getForm($data = [], $loadData = true) $record->id = $id; - if ($id == 0) { - $stateField = $form->getField('state'); - $stateField->removeTrashedOption(); + // Remove trashed option from state field for new article form + if ($id == 0) + { + $field = $form->getField('state'); + + if ($field !== false && $field->type === 'List') + { + $field->removeOption(-2); + } } // For new articles we load the potential state + associations diff --git a/libraries/src/Form/Field/ListField.php b/libraries/src/Form/Field/ListField.php index 191eb0b909c60..9c3d6a1495642 100644 --- a/libraries/src/Form/Field/ListField.php +++ b/libraries/src/Form/Field/ListField.php @@ -231,6 +231,29 @@ public function addOption($text, $attributes = []) return $this; } + /** + * Method to remove an option from list field. + * + * @param string $value The value of the option to remove + * + * @return static For chaining. + * + * @since __DEPLOY_VERSION__ + */ + public function removeOption(string $value): static + { + foreach ($this->element->option as $option) + { + if ((string) $option['value'] === $value) + { + $dom = dom_import_simplexml($option); + $dom->parentNode->removeChild($dom); + } + } + + return $this; + } + /** * Method to get certain otherwise inaccessible properties from the form field object. * diff --git a/libraries/src/Form/FormField.php b/libraries/src/Form/FormField.php index 47a105b54aa68..c0c0c9274662f 100644 --- a/libraries/src/Form/FormField.php +++ b/libraries/src/Form/FormField.php @@ -898,24 +898,6 @@ protected function getName($fieldName) return $name; } - /** - * Method to remove the trashed option from new items in the list field. - * @since __DEPLOY_VERSION__ - */ - public function removeTrashedOption() - { - if ($this->element instanceof \SimpleXMLElement && ($list = $this->element->xpath('option'))) { - foreach ($list as $option) { - if ((string) $option['value'] === '-2') { - $dom = dom_import_simplexml($option); - $dom->parentNode->removeChild($dom); - - break; - } - } - } - } - /** * Method to get the field name used. * From e9b313a1260f47d52a3689eef276d42b50c25387 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Wed, 5 Mar 2025 16:27:53 +0200 Subject: [PATCH 7/8] update for phpcs --- .../components/com_content/src/Model/ArticleModel.php | 6 ++---- libraries/src/Form/Field/ListField.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index d660a7c2cebea..ad6dc1f6b12c1 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -484,12 +484,10 @@ public function getForm($data = [], $loadData = true) $record->id = $id; // Remove trashed option from state field for new article form - if ($id == 0) - { + if ($id == 0) { $field = $form->getField('state'); - if ($field !== false && $field->type === 'List') - { + if ($field !== false && $field->type === 'List') { $field->removeOption(-2); } } diff --git a/libraries/src/Form/Field/ListField.php b/libraries/src/Form/Field/ListField.php index 9c3d6a1495642..712b6c3497af6 100644 --- a/libraries/src/Form/Field/ListField.php +++ b/libraries/src/Form/Field/ListField.php @@ -242,10 +242,8 @@ public function addOption($text, $attributes = []) */ public function removeOption(string $value): static { - foreach ($this->element->option as $option) - { - if ((string) $option['value'] === $value) - { + foreach ($this->element->option as $option) { + if ((string) $option['value'] === $value) { $dom = dom_import_simplexml($option); $dom->parentNode->removeChild($dom); } From 91438ee19f1de3de0dab483ceb8e696f906db919 Mon Sep 17 00:00:00 2001 From: Reem Attallah Date: Thu, 20 Mar 2025 12:47:55 +0200 Subject: [PATCH 8/8] use instance listField instead of list --- .../components/com_content/src/Model/ArticleModel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index ad6dc1f6b12c1..557ba82669cec 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Factory; use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\Form\Field\ListField; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFactoryInterface; use Joomla\CMS\Helper\TagsHelper; @@ -487,7 +488,7 @@ public function getForm($data = [], $loadData = true) if ($id == 0) { $field = $form->getField('state'); - if ($field !== false && $field->type === 'List') { + if ($field instanceof ListField) { $field->removeOption(-2); } }