Skip to content
Merged
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
46 changes: 38 additions & 8 deletions administrator/components/com_fields/src/Model/FieldsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryServiceInterface;
use Joomla\CMS\Categories\SectionNotFoundException;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
Expand Down Expand Up @@ -199,14 +200,43 @@ protected function getListQuery()

if ($parts)
{
// Get the category
$cat = Categories::getInstance(str_replace('com_', '', $parts[0]) . '.' . $parts[1]);
// Get the categories for this component (and optionally this section, if available)
$cat = (
function () use ($parts) {
// Get the CategoryService for this component
$componentObject = $this->bootComponent($parts[0]);

// If there is no category for the component and section, so check the component only
if (!$cat)
{
$cat = Categories::getInstance(str_replace('com_', '', $parts[0]));
}
if (!$componentObject instanceof CategoryServiceInterface)
{
// No CategoryService -> no categories
return null;
}

$cat = null;

// Try to get the categories for this component and section
try
{
$cat = $componentObject->getCategory([], $parts[1] ?: '');
}
catch (SectionNotFoundException $e)
{
// Not found for component and section -> Now try once more without the section, so only component
try
{
$cat = $componentObject->getCategory();
}
catch (SectionNotFoundException $e)
{
// If we haven't found it now, return (no categories available for this component)
return null;
}
}

// So we found categories for at least the component, return them
return $cat;
}
)();

if ($cat)
{
Expand Down