Commit f402e251 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix warnings when rendering access type after error (bug #894592)



When the view access page is submitted with an error, php warnings
are emitted when the rendering the access rows.

First because the pieform element assumes that an 'accesstype' index
exists in the accesslist value, but this is only true when the
accesslist still contains database records rather than the list
submitted by the form.

Second,  disabled public access record causes a warning because
'public' isn't in the list of 'presets' allowed to be added to the
view, so we need to keep track of the allowed presets and the full
list of presets that may have been allowed in the past.

Change-Id: Ic4db20738d53a52caeb3ebef0b44660dcb7c9ee6
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 49d71e1d
......@@ -51,25 +51,26 @@ function pieform_element_viewacl(Pieform $form, $element) {
else if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') {
$public = true;
}
$presets = array();
$allpresets = array('public', 'loggedin', 'friends');
$allowedpresets = array();
$loggedinindex = 0;
if ($public) {
$presets[] = 'public';
$allowedpresets[] = 'public';
$loggedinindex = 1;
}
$presets[] = 'loggedin';
$allowedpresets[] = 'loggedin';
if ($form->get_property('userview')) {
$presets[] = 'friends';
$allowedpresets[] = 'friends';
}
$accesslist = array();
if ($value) {
foreach ($value as $item) {
if (is_array($item)) {
if ($item['accesstype'] == 'public') {
if ($item['type'] == 'public') {
$item['publicallowed'] = (int)$public;
}
if (in_array($item['type'], $presets)) {
if (in_array($item['type'], $allpresets)) {
$item['name'] = get_string($item['type'], 'view');
$item['preset'] = true;
}
......@@ -99,8 +100,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
);
}
$potentialpresets = $presets;
foreach ($potentialpresets as &$preset) {
foreach ($allowedpresets as &$preset) {
$preset = array(
'type' => $preset,
'id' => $preset,
......@@ -152,7 +152,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
}
$smarty->assign('viewtype', $element['viewtype']);
$smarty->assign('potentialpresets', json_encode($potentialpresets));
$smarty->assign('potentialpresets', json_encode($allowedpresets));
$smarty->assign('loggedinindex', $loggedinindex);
$smarty->assign('accesslist', json_encode($accesslist));
$smarty->assign('viewid', $form->get_property('viewid'));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment