array(
'name' => t('Pages'),
'description' => t('Validates on a selection of pages.'),
),
);
}
function condition_pages_requirement_form($context) {
$form['pages_operator'] = array(
'#type' => 'radios',
'#title' => t('Validate'),
'#options' => array(
'' => t("Always (skip requirement)"),
CONDITION_NONE => t('Except on the listed pages.'),
CONDITION_ANY => t('Only on the listed pages.'),
),
'#default_value' => $context['operator'],
);
$form['pages_pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#description' => t('Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog. <front> is the front page.'),
'#default_value' => $context['pages'],
);
return $form;
}
function condition_pages_requirement_form_submit($form, &$form_state) {
if ($form_state['values']['pages_operator'] || $form_state['values']['pages_pages']) {
return array(
'operator' => $form_state['values']['pages_operator'],
'pages' => $form_state['values']['pages_pages'],
);
}
}
function condition_pages_requirement(&$condition, $context = array()) {
if (!$context['operator'] || ($context['operator'] == CONDITION_NONE && !$context['pages'])) {
return TRUE;
}
if (!$context['pages'] && $context['operator'] == CONDITION_ANY) {
return FALSE;
}
$alias = drupal_get_path_alias($_GET['q']);
return ($context['operator'] == CONDITION_NONE xor (drupal_match_path($alias, $context['pages']) || ($_GET['q'] != $alias && drupal_match_path($_GET['q'], $context['pages']))));
}
?>