Since I work in a k12 environment, I needed to make a plugin that removed “Public” as an option when users post content. I didn’t take me long to locate the file engine/lib/access.php as the file that controls these functions.
I hacked the core code and indeed it functioned as I wanted it to. Hacks to the core are undesireable because it complicates upgrading, so I wanted to create an override. I worked many hours trying to create a hack of the core access.php, but I was unsuccessful. I just couldn’t figure out how to write a start.php that would function. Finally, I had a break through, but it had nothing to do with overriding engine/lib/access.php.
Diego Andrés Ramírez Aragón and Jens von der Heydt suggested that the key to this may reside in the views directory. I knew how to write an override of elgg views. First I created the initial directories for the plugin:
nopublic/
nopublic/views
To find the rest of the pathway, I had to find where the access file was in the views directory and mirror it. Since it was in
views/default/input/access.php
I created
nopublic/views/default/input/
Next I opened created a copy of the original access.php, made my hacks and inserted it plugins’s input folder.
$class = $vars['class'];
if (!$class) $class = “input-access”;
if (!is_array($vars['options']))
{
$vars['options'] = array();
$vars['options'] = get_write_access_array();
}
if (is_array($vars['options']) && sizeof($vars['options']) > 0) {
?>
was changed to:
$class = $vars['class'];
if (!$class) $class = “input-access”;
if (!is_array($vars['options']))
{
$vars['options'] = array();
$vars['options'] = get_write_access_array();
unset($vars['options'][2]);
}
if (is_array($vars['options']) && sizeof($vars['options']) > 0) {
?>
The start.php requires no hooks. Simply initialize and register the plugin:
<?php
function nopublic_init() {
}
register_elgg_event_handler(‘init’,'system’,’nopublic_init’);
?>
I put that in my plugin directory, along with an manifest.xml file so now I had:
nopublic/start.php
nopublic/manifest.xml
nopublic/views/default/input/access.php
That disables the public access option–the basic nopublic plugin. There are many directories in the views folder that can be overridden this easily.

Clearly, there is much to explore with views overrides. I look forward to learning more about the manifestations of each file. They provide important customization options beyond themes.
I’d like to hear how others are using views overrides!
2 comments