Modifying the Detail View With a Hook
Posted: 2013-10-10 18:41
Here's some code I want to share that gives an example of changing the display of the detail view form through a hook function.
In this case, I wanted to hide the "Print Preview" button.
This code goes in the TABLENAME_dv() function in the TABLENAME.php file in the hooks directory. This function is called after displaying the table view, and just before displaying the detail view (the comments should explain it):
This will always hide the button whenever anybody is looking at the detail view. If, however, you want to hide buttons based on specific users, you could surround this code with an if statement that tested for the class of users you don't want to see the button. For example:
You can use these examples to hide any buttons you want, based on user groups. You can also adapt this concept to hide certain fields in the editing form for certain groups of users.
Hope this helps someone,
Garry
In this case, I wanted to hide the "Print Preview" button.
This code goes in the TABLENAME_dv() function in the TABLENAME.php file in the hooks directory. This function is called after displaying the table view, and just before displaying the detail view (the comments should explain it):
Code: Select all
function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args){
// ****************************************************************
// Remove "PRINT PREVIEW" button from the detail view editing form
// ****************************************************************
// HTML for detail view PRINT PREVIEW button as generated by AppGini:
// <button tabindex="2" type="submit" id="dvprint" name="dvprint_x" value="1"
// onclick="$$('form')[0].writeAttribute('novalidate', 'novalidate'); document.myform.reset();
// return true;"><img src="print-preview.gif" /> __BUTTON LABEL TEXT__</button>
//
// Get the global variable for language text
global $Translation;
// Get the text of the button label
$buttLabel = $Translation['Print Preview'];
// Delete it!
$html = str_replace("<button tabindex=\"2\" type=\"submit\" id=\"dvprint\" name=\"dvprint_x\" value=\"1\" onclick=\"$$('form')[0].writeAttribute('novalidate', 'novalidate'); document.myform.reset(); return true;\"><img src=\"print-preview.gif\" /> $buttLabel</button>","",$html);
}
Code: Select all
if ($memberInfo['group'] == 'anonymous') {
// Disable detail view button
CODE FROM ABOVE GOES HERE
}
Hope this helps someone,
Garry