Skip to content

Commit

Permalink
Fix echo selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Anurag committed Jan 31, 2018
1 parent d191519 commit 9fac4a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
24 changes: 13 additions & 11 deletions layouts/joomla/form/field/rules/tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
defined('JPATH_BASE') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Helper\UserGroupsHelper;
Expand All @@ -22,7 +24,7 @@
extract($displayData);

// Get some system objects.
$document = JFactory::getDocument();
$document = Factory::getDocument();

/**
* Layout variables
Expand Down Expand Up @@ -85,7 +87,7 @@
Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT');

// Ajax request data.
$ajaxUri = \JRoute::_('index.php?option=com_config&task=application.store&format=json&' . \JSession::getFormToken() . '=1');
$ajaxUri = Route::_('index.php?option=com_config&task=application.store&format=json&' . Session::getFormToken() . '=1');
?>

<?php // Description ?>
Expand Down Expand Up @@ -159,11 +161,11 @@ class="custom-select novalidate"

<?php // Build the dropdowns for the permissions sliders
// The parent group has "Not Set", all children can rightly "Inherit" from that.?>
<option value="" <?php ($assetRule === null ? ' selected="selected"' : ''); ?>>
<option value="" <?php echo ($assetRule === null ? ' selected="selected"' : ''); ?>>
<?php echo Text::_(empty($group->parent_id) && $isGlobalConfig ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED'); ?></option>
<option value="1" <?php ($assetRule === true ? ' selected="selected"' : ''); ?>>
<option value="1" <?php echo ($assetRule === true ? ' selected="selected"' : ''); ?>>
<?php echo Text::_('JLIB_RULES_ALLOWED'); ?></option>
<option value="0" <?php ($assetRule === false ? ' selected="selected"' : ''); ?>>
<option value="0" <?php echo ($assetRule === false ? ' selected="selected"' : ''); ?>>
<?php echo Text::_('JLIB_RULES_DENIED'); ?></option>

</select>&#160;
Expand All @@ -173,7 +175,7 @@ class="custom-select novalidate"
<td headers="aclactionth<?php echo $group->value; ?>">
<?php $result = array(); ?>
<?php // Get the group, group parent id, and group global config recursive calculated permission for the chosen action. ?>
<?php $inheritedGroupRule = Access::checkGroup((int) $group->value, $action->name, $assetId);
<?php $inheritedGroupRule = Access::checkGroup((int) $group->value, $action->name, $assetId);
$inheritedGroupParentAssetRule = !empty($parentAssetId) ? Access::checkGroup($group->value, $action->name, $parentAssetId) : null;
$inheritedParentGroupRule = !empty($group->parent_id) ? Access::checkGroup($group->parent_id, $action->name, $assetId) : null;

Expand All @@ -191,13 +193,13 @@ class="custom-select novalidate"
if ($inheritedGroupRule === null || $inheritedGroupRule === false)
{
$result['class'] = 'badge badge-danger';
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED_INHERITED');
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED_INHERITED');
}
// If recursive calculated setting is "Allowed". Calculated permission is "Allowed (Inherited)".
else
{
$result['class'] = 'badge badge-success';
$result['text'] = Text::_('JLIB_RULES_ALLOWED_INHERITED');
$result['text'] = Text::_('JLIB_RULES_ALLOWED_INHERITED');
}

// Second part: Overwrite the calculated permissions labels if there is an explicit permission in the current group.
Expand All @@ -212,13 +214,13 @@ class="custom-select novalidate"
if ($assetRule === false)
{
$result['class'] = 'badge badge-danger';
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED');
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED');
}
// If there is an explicit permission is "Allowed". Calculated permission is "Allowed".
else if ($assetRule === true)
{
$result['class'] = 'badge badge-success';
$result['text'] = Text::_('JLIB_RULES_ALLOWED');
$result['text'] = Text::_('JLIB_RULES_ALLOWED');
}

// Third part: Overwrite the calculated permissions labels for special cases.
Expand All @@ -227,7 +229,7 @@ class="custom-select novalidate"
if (empty($group->parent_id) && $isGlobalConfig === true && $assetRule === null)
{
$result['class'] = 'badge badge-danger';
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED_DEFAULT');
$result['text'] = Text::_('JLIB_RULES_NOT_ALLOWED_DEFAULT');
}

/**
Expand Down
37 changes: 20 additions & 17 deletions libraries/src/Form/Field/RulesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,28 @@ protected function getInput()
$component = empty($this->component) ? 'root.1' : $this->component;

// Current view is global config?
$isGlobalConfig = $component === 'root.1';
$this->isGlobalConfig = $component === 'root.1';

// Get the actions for the asset.
$actions = Access::getActions($component, $section);
$this->actions = Access::getActions($component, $section);

// Iterate over the children and add to the actions.
foreach ($this->element->children() as $el)
{
if ($el->getName() == 'action')
{
$actions[] = (object) array(
$this->actions[] = (object) array(
'name' => (string) $el['name'],
'title' => (string) $el['title'],
'description' => (string) $el['description'],
);
}
}

$this->actions=(array) $actions;


// Get the asset id.
// Note that for global configuration, com_config injects asset_id = 1 into the form.
$assetId = $this->form->getValue($assetField);
$newItem = empty($assetId) && $isGlobalConfig === false && $section !== 'component';
$this->assetId = $this->form->getValue($assetField);
$this->newItem = empty($assetId) && $this->isGlobalConfig === false && $section !== 'component';
$parentAssetId = null;

// If the asset id is empty (component or new item).
Expand All @@ -206,7 +204,7 @@ protected function getInput()
}

// If not in global config we need the parent_id asset to calculate permissions.
if (!$isGlobalConfig)
if (!$this->isGlobalConfig)
{
// In this case we need to get the component rules too.
$db = Factory::getDbo();
Expand All @@ -218,9 +216,15 @@ protected function getInput()

$db->setQuery($query);

$parentAssetId = (int) $db->loadResult();
$this->parentAssetId = (int) $db->loadResult();
}

// Get the rules for just this asset (non-recursive).
$this->assetRules = Access::getAssetRules($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()));
}
Expand All @@ -237,14 +241,13 @@ protected function getLayoutData()
$data = parent::getLayoutData();

$extraData = array(
'groups' => $this->getUserGroups(),
'section' => $this->section,
'actions' => $this->actions,
'component' => $this->component,
'assetRules' => Access::getAssetRules($this->assetId, false, false),
'assetId' => $this->assetId,
'groups' => $this->groups,
'section' => $this->section,
'actions' => $this->actions,
'assetId' => $this->assetId,
'newItem' => $this->newItem,
'assetRules' => $this->assetRules,
'isGlobalConfig' => $this->isGlobalConfig,
'newItem' => $this->newItem,
'parentAssetId' => $this->parentAssetId,

);
Expand Down

0 comments on commit 9fac4a3

Please sign in to comment.