0

Is it possible to add permissions to a Ctools content type plugin, similar to a node entity? I want to be able to check if a user has permission to add a certain content pane to a panels page through the IPE.

1

It should be possible using a ctools access plugin. From the linked site:

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',
);

It goes on to explain how to create the various callbacks but that's beyond the scope of this question I think.

  • So a ctools access plugin controls the access to a ctools content type plugin? – pi_ron Jan 13 '15 at 4:34
  • They appear to control access to just about every aspect of page manager/panels. – Darvanen Jan 13 '15 at 6:01
  • Ctools Access plugins provide options for selection rules in variants. They don't govern whether or not a single content type plugin is available to a user. I'm also looking for a solution to this issue, however, so if I come up with something I will post an answer. – KeyboardCowboy Nov 3 '16 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.