0

I'm trying to define a Panels visibility rule (access plugin) programmatically but I'm running into a problem.

My code is below. This code works as a Selection Rule (on the Access tab), but when I try to add my access plugin as a Visibility Rule (on the Content tab), the plugin is added to the panel pane, but it doesn't show up in the UI under "Visibility rules." So there's no way to delete it, and the title isn't shown.

I assume I failed to declare something that makes it show up in the Visibility Rules, but I haven't been able to figure out what. I was following this guide, but my plugin is simpler than the one in the example (no configuration necessary).

<?php
/**
 * @file
 * Plugin to check whether the value matches the proximity query string
 * https://drupal.stackexchange.com/questions/33336/what-are-ctools-plugin-content-type-access-etc-and-how-does-one-create-them/33337#33337
 */

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'title' => t("Check proximity query string"),
  'description' => t('Returns FALSE if the proximity search query string is set'),
  'callback' => 'mymodule_checkproxquerystring_ctools_access_check',
  'settings form' => 'mymodule_checkproxquerystring_ctools_access_settings',
);

/**
 * Settings form for the 'term depth' access plugin.
 */
function mymodule_checkproxquerystring_ctools_access_settings($form, &$form_state, $conf) {
  return $form;
}

/**
 * Check for access.
 */
function mymodule_checkproxquerystring_ctools_access_check($conf, $context) {
  if (isset($_GET['d']) && (is_numeric($_GET['d']))) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}

1 Answer 1

2

I think probably that is due to the missing 'summary' key from your '$plugin'. A simple access plugin to check if the current page can be defined as :

$plugin = array(
  'title' => t('Front page'),
  'description' => t('Is this the front page.'),
  'callback' => 'ctools_front_ctools_access_check',
  'default' => array('negate' => 0),
  'settings form' => 'ctools_front_ctools_access_settings',
  'summary' => 'ctools_front_ctools_access_summary',
);

/**
 * Settings form for the 'by parent term' access plugin
 */
function ctools_front_ctools_access_settings($form, &$form_state, $conf) {
  // No additional configuration necessary.
  return $form;
}

/**
 * Check for access.
 */
function ctools_front_ctools_access_check($conf, $context) {
  if (drupal_is_front_page()) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}

/**
 * Provide a summary description based upon the checked terms.
 */
function ctools_front_ctools_access_summary($conf, $context) {
  return t('The front page');
}

The canonical reference of this could be found in the access plugins defined in the ctools module itself.

1
  • Yes, adding the summary key to the plugin array and then copying the function did the trick. May 25, 2015 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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