Some time ago we've learned how to develop ctools content type for Panels module. Now it’s time for the next plugin type for Ctools, namely - access plugin. Plugins of this type are some kind of rules depending on which Panels module decide whether to show or not show pane (the least structure unit of panel), to choose one or another version of panel to be displayed.
For example, lets make up the following task: we have a standard panel user_view, which overrides the standard user page display on Drupal.
We have the user A, who is watching the user B profile. If the user A has been registered on the site before the user B, he will see the certain set of fields, and if not - the other one. The task is somehow far from reality, but it is ok for the example.
Firstly, just like during work with Сtools content type, for the web developer it is necessary to call hook_ctools_plugin_directory() to indicate that we have ctools plugins of specific type in our module:
/* * Implements hook_ctools_plugin_directory(). */ function access_example_ctools_plugin_directory($owner, $plugin_type) { if ($owner == 'ctools' && !empty($plugin_type)) { return "plugins/{$plugin_type}"; } }
Then in module folder we need to create "plugins" folder and "access" folder inside of “plugins” folder. Create plugin file with the name "access_example_plugin.inc" inside of "access" folder. Write the access rule by array in this file:
/** * Plugins are described by creating a $plugin array which will be used * by the system that includes this file. */ $plugin = array( // Plugin user-friendly name. 'title' => t('Eldership rule'), // Plugin description. 'description' => t('Controls access depends on eldership'), // Without required context plugin will now be shown in Panels UI. 'required context' => array(new ctools_context_required(t('User'), 'user')), // Function which will allow or restrict access. 'callback' => 'access_example_who_elder_access', // Plugin settings form. 'settings form' => 'access_example_who_elder_access_settings_form', // Provides a summary descriptions depends on settings selected. 'summary' => 'access_example_who_elder_access_summary', );