Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
18 changes: 8 additions & 10 deletions administrator/components/com_fields/src/Helper/FieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,15 @@ 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');
// Choose the first category available
$catOptions = $formField->options;

if ($catOptions && !empty($catOptions[0]->value))
{
$assignedCatids = (int) $catOptions[0]->value;
}
}

$data->fieldscatid = $assignedCatids;
Expand Down
18 changes: 8 additions & 10 deletions libraries/src/MVC/Model/WorkflowBehaviorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down