t("String context length"), 'description' => t('Control access by length of string context.'), 'callback' => 'bryn_ctools_string_context_length_ctools_access_check', 'settings form' => 'bryn_ctools_string_context_length_ctools_access_settings', 'summary' => 'bryn_ctools_string_context_length_ctools_access_summary', 'required context' => new ctools_context_required(t('String'), 'string'), ); } /** * Settings form for the 'by role' access plugin. */ function bryn_ctools_string_context_length_ctools_access_settings(&$form, &$form_state, $conf) { $form['settings']['greater_than'] = array( '#type' => 'radios', '#title' => t('Grant access if string context length is'), '#options' => array(1 => t('Greater than'), 0 => t('Less than or equal to')), '#default_value' => $conf['greater_than'], ); $form['settings']['context_length'] = array( '#type' => 'textfield', '#title' => t('Length of context'), '#size' => 3, '#default_value' => $conf['context_length'], '#description' => t('Access/visibility will be granted based on string context length.'), ); } /** * Check for access. */ function bryn_ctools_string_context_length_ctools_access_check($conf, $context) { // As far as I know there should always be a context at this point, but this // is safe. if (empty($context) || empty($context->data)) { $context_length = 0; } else { $context_length = drupal_strlen($context->data); } $compare = ($context_length > $conf['context_length']); if (($compare && $conf['greater_than']) || (!$compare && !$conf['greater_than'])) { return TRUE; } return FALSE; } /** * Provide a summary description based upon the checked roles. */ function bryn_ctools_string_context_length_ctools_access_summary($conf, $context) { return t('String context must be !comp @length characters', array('!comp' => $conf['greater_than'] ? 'greater than' : 'less than or equal to', '@length' => $conf['context_length']) ); }