Back to RulesField class

Method getInput

protected string
getInput
()
Method to get the field input markup for Access Control Lists.
Returns
  • string The field input markup.
Since
  • 1.7.0
-
  • Add access check.
Class: RulesField
Project: Joomla

Method getInput - Source code

/**
 * Method to get the field input markup for Access Control Lists.
 * Optionally can be associated with a specific component and section.
 *
 * @return  string  The field input markup.
 *
 * @since   1.7.0
 * @todo:   Add access check.
 */
protected function getInput()
{
    // Initialise some field attributes.
    $section = $this->section;
    $assetField = $this->assetField;
    $component = empty($this->component) ? 'root.1' : $this->component;
    // Current view is global config?
    $this->isGlobalConfig = $component === 'root.1';
    // Get the actions for the asset.
    $this->actions = Access::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml', "/access/section[@name='" . $section . "']/");
    if ($this->actions === false) {
        $this->actions = [];
    }
    // Iterate over the children and add to the actions.
    foreach ($this->element->children() as $el) {
        if ($el->getName() === 'action') {
            $this->actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'], 'description' => (string) $el['description']);
        }
    }
    // Get the asset id.
    // Note that for global configuration, com_config injects asset_id = 1 into the form.
    $this->assetId = (int) $this->form->getValue($assetField);
    $this->newItem = empty($this->assetId) && $this->isGlobalConfig === false && $section !== 'component';
    // If the asset id is empty (component or new item).
    if (empty($this->assetId)) {
        // Get the component asset id as fallback.
        $db = Factory::getDbo();
        $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__assets'))->where($db->quoteName('name') . ' = :component')->bind(':component', $component);
        $db->setQuery($query);
        $this->assetId = (int) $db->loadResult();
        /**
         * @todo: incorrect info
         * When creating a new item (not saving) it uses the calculated permissions from the component (item <-> component <-> global config).
         * But if we have a section too (item <-> section(s) <-> component <-> global config) this is not correct.
         * Also, currently it uses the component permission, but should use the calculated permissions for achild of the component/section.
         */
    }
    // If not in global config we need the parent_id asset to calculate permissions.
    if (!$this->isGlobalConfig) {
        // In this case we need to get the component rules too.
        $db = Factory::getDbo();
        $query = $db->getQuery(true)->select($db->quoteName('parent_id'))->from($db->quoteName('#__assets'))->where($db->quoteName('id') . ' = :assetId')->bind(':assetId', $this->assetId, ParameterType::INTEGER);
        $db->setQuery($query);
        $this->parentAssetId = (int) $db->loadResult();
    }
    // Get the rules for just this asset (non-recursive).
    $this->assetRules = Access::getAssetRules($this->assetId, false, false);
    // Get the available user groups.
    $this->groups = $this->getUserGroups();
    // Trim the trailing line in the layout file
    return trim($this->getRenderer($this->layout)->render($this->getLayoutData()));
}