From 4cb7b8206bdd589b246a5cdcad7ce836316e8932 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Aug 2020 18:57:50 +0300 Subject: [PATCH 1/4] Choose the first category available correctly --- .../com_fields/src/Helper/FieldsHelper.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/administrator/components/com_fields/src/Helper/FieldsHelper.php b/administrator/components/com_fields/src/Helper/FieldsHelper.php index 06138479a76c3..98a59cfe70979 100644 --- a/administrator/components/com_fields/src/Helper/FieldsHelper.php +++ b/administrator/components/com_fields/src/Helper/FieldsHelper.php @@ -316,17 +316,14 @@ public static function prepareForm($context, Form $form, $data) { $assignedCatids = $formField->getAttribute('default', null); - // Choose the first category available - $xml = new \DOMDocument; - libxml_use_internal_errors(true); - $xml->loadHTML($formField->__get('input')); - libxml_clear_errors(); - libxml_use_internal_errors(false); - $options = $xml->getElementsByTagName('option'); - - if (!$assignedCatids && $firstChoice = $options->item(0)) + if (!$assignedCatids) { - $assignedCatids = $firstChoice->getAttribute('value'); + $catOptions = $formField->options; + + if (!empty($catOptions[0]->value)) + { + $assignedCatids = (int) $catOptions[0]->value; + } } $data->fieldscatid = $assignedCatids; From a5eef98a9fe97f5cf261ec71aece8aee97ea8941 Mon Sep 17 00:00:00 2001 From: Fedik Date: Mon, 3 Aug 2020 19:10:14 +0300 Subject: [PATCH 2/4] Restore comment --- .../components/com_fields/src/Helper/FieldsHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_fields/src/Helper/FieldsHelper.php b/administrator/components/com_fields/src/Helper/FieldsHelper.php index 98a59cfe70979..f76d1af08e50d 100644 --- a/administrator/components/com_fields/src/Helper/FieldsHelper.php +++ b/administrator/components/com_fields/src/Helper/FieldsHelper.php @@ -318,9 +318,10 @@ public static function prepareForm($context, Form $form, $data) if (!$assignedCatids) { + // Choose the first category available $catOptions = $formField->options; - if (!empty($catOptions[0]->value)) + if ($catOptions && !empty($catOptions[0]->value)) { $assignedCatids = (int) $catOptions[0]->value; } From cd257725c45dba1c56a03cc9171ac06c67cee1d8 Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 11 Aug 2020 18:40:37 +0300 Subject: [PATCH 3/4] Update ArticleModel --- .../com_content/src/Model/ArticleModel.php | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index 72f440b073676..d9ed91e78050f 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -524,22 +524,20 @@ public function getForm($data = array(), $loadData = true) ? (int) reset($assignedCatids) : (int) $assignedCatids; - // Try to get the category from the html code of the field + // Try to get the category from the category field if (empty($assignedCatids)) { $assignedCatids = $formField->getAttribute('default', null); - // Choose the first category available - $xml = new \DOMDocument; - libxml_use_internal_errors(true); - $xml->loadHTML($formField->__get('input')); - libxml_clear_errors(); - libxml_use_internal_errors(false); - $options = $xml->getElementsByTagName('option'); - - if (!$assignedCatids && $firstChoice = $options->item(0)) + if (!$assignedCatids) { - $assignedCatids = $firstChoice->getAttribute('value'); + // Choose the first category available + $catOptions = $formField->options; + + if ($catOptions && !empty($catOptions[0]->value)) + { + $assignedCatids = (int) $catOptions[0]->value; + } } } From 861f892125cc0a3dab628adef1a5ca5e2367a928 Mon Sep 17 00:00:00 2001 From: Fedik Date: Tue, 11 Aug 2020 18:46:40 +0300 Subject: [PATCH 4/4] Update WorkflowBehaviorTrait --- .../src/MVC/Model/WorkflowBehaviorTrait.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libraries/src/MVC/Model/WorkflowBehaviorTrait.php b/libraries/src/MVC/Model/WorkflowBehaviorTrait.php index 29aea89551f3a..788d00324ec42 100644 --- a/libraries/src/MVC/Model/WorkflowBehaviorTrait.php +++ b/libraries/src/MVC/Model/WorkflowBehaviorTrait.php @@ -411,17 +411,15 @@ protected function getStageForNewItem(Form $form, $data) { $catId = $field->getAttribute('default', null); - // Choose the first category available - $xml = new \DOMDocument; - libxml_use_internal_errors(true); - $xml->loadHTML($field->__get('input')); - libxml_clear_errors(); - libxml_use_internal_errors(false); - $options = $xml->getElementsByTagName('option'); - - if (!$catId && $firstChoice = $options->item(0)) + if (!$catId) { - $catId = $firstChoice->getAttribute('value'); + // Choose the first category available + $catOptions = $field->options; + + if ($catOptions && !empty($catOptions[0]->value)) + { + $catId = (int) $catOptions[0]->value; + } } }