Back to LegacyComponent class

Method getCategory

public \Joomla\CMS\Categories\CategoryInterface
getCategory
(array $options = [], mixed $section = '')
Returns the category service.
Parameters
  • array $options The options
  • string $section The section
Returns
  • \Joomla\CMS\Categories\CategoryInterface
Since
  • 4.0.0
-
  • \Joomla\CMS\Categories\SectionNotFoundException

Method getCategory - Source code

/**
 * Returns the category service.
 *
 * @param   array   $options  The options
 * @param   string  $section  The section
 *
 * @return  CategoryInterface
 *
 * @since   4.0.0
 * @throws  SectionNotFoundException
 */
public function getCategory(array $options = [], $section = '') : CategoryInterface
{
    $classname = ucfirst($this->component) . ucfirst($section) . 'Categories';
    if (!class_exists($classname)) {
        $path = JPATH_SITE . '/components/com_' . $this->component . '/helpers/category.php';
        if (!is_file($path)) {
            throw new SectionNotFoundException();
        }
        include_once $path;
    }
    if (!class_exists($classname)) {
        throw new SectionNotFoundException();
    }
    return new $classname($options);
}