I wanted to add an edit button to the details view on the front-end to make view\editing records a bit more intuitive. As it stands (from what I can tell anyways) if a user needs to view the details of a record and wants to edit that record they have to go back to list view, find the record and then click edit. Since I didn't see any option anywhere to add such a thing I used the PHP plugin on the edit form page to add one. Now when a user goes from list view, and clicks on details they have a button at the top that links them back to the form to edit that record.
To do this edit your form, click on plugins, add using these options:
If you want to display the button based on a logged in users group (You will have to edit the $allowgroups array with the joomla group ids you wish to allow) use the following code:
I am no coding expert, but everything seems to work ok for me. Hopefully it helps someone else as well .
To do this edit your form, click on plugins, add using these options:
- DO: php
- In: Both
- On: Edit
- Process Script: At top of Form (getTopContent)
- PHP File: - None Selected -
PHP:
$fullUrl = JURI::getInstance()->toString();
$modUrl = str_replace('details', 'form', $fullUrl, $count);
if ($count > 0) {
$baseUrl = JURI::base();
$linkUrl = str_replace($baseUrl, '', $modUrl);
$link = '<div style="padding:5px 0 5px 30px">Edit this record<a style="padding-left:10px;" title="Edit this record" href="' . $linkUrl . '"><img src="/media/com_fabrik/images/edit.png" alt="Edit"></a></div>';
return $link;
}else {return;}
PHP:
function array_multineedle_search($arrayNeedles, $haystack){
foreach($arrayNeedles as $needle){
if(in_array($needle, $haystack)) return true;
}
return false;
}
$user =& JFactory::getUser();
$usergroups = $user->get('groups');
$allowgroups = array(2,8);
$result = array_multineedle_search($allowgroups, $usergroups);
if($user->guest){
return;
}elseif($result){
$fullUrl = JURI::getInstance()->toString();
$modUrl = str_replace('details', 'form', $fullUrl, $count);
if ($count > 0) {
$baseUrl = JURI::base();
$linkUrl = str_replace($baseUrl, '', $modUrl);
$link = '<div style="padding:5px 0 5px 30px">Edit this record<a style="padding-left:10px;" title="Edit this record" href="' . $linkUrl . '"><img src="/media/com_fabrik/images/edit.png" alt="Edit"></a></div>';
return $link;
}else {return;}
}
I am no coding expert, but everything seems to work ok for me. Hopefully it helps someone else as well .