1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
c304a780
|
Assos Assos
|
* Plugin to provide access control/visibility based on existence of a specified context.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'title' => t("Context exists"),
|
10 |
|
|
'description' => t('Control access by whether or not a context exists and contains data.'),
|
11 |
|
|
'callback' => 'ctools_context_exists_ctools_access_check',
|
12 |
|
|
'settings form' => 'ctools_context_exists_ctools_access_settings',
|
13 |
|
|
'summary' => 'ctools_context_exists_ctools_access_summary',
|
14 |
|
|
'required context' => new ctools_context_required(t('Context'), 'any', TRUE),
|
15 |
|
|
'defaults' => array('exists' => TRUE),
|
16 |
|
|
);
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
c304a780
|
Assos Assos
|
* Settings form.
|
20 |
85ad3d82
|
Assos Assos
|
*/
|
21 |
|
|
function ctools_context_exists_ctools_access_settings($form, &$form_state, $conf) {
|
22 |
|
|
$form['settings']['exists'] = array(
|
23 |
|
|
'#type' => 'radios',
|
24 |
|
|
'#description' => t("Check to see if the context exists (contains data) or does not exist (contains no data). For example, if a context is optional and the path does not contain an argument for that context, it will not exist."),
|
25 |
|
|
'#options' => array(TRUE => t('Exists'), FALSE => t("Doesn't exist")),
|
26 |
|
|
'#default_value' => $conf['exists'],
|
27 |
|
|
);
|
28 |
|
|
return $form;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
c304a780
|
Assos Assos
|
* Check for access.
|
33 |
85ad3d82
|
Assos Assos
|
*/
|
34 |
|
|
function ctools_context_exists_ctools_access_check($conf, $context) {
|
35 |
c304a780
|
Assos Assos
|
// Xor returns false if the two bools are the same, and true if they are not.
|
36 |
85ad3d82
|
Assos Assos
|
// i.e, if we asked for context_exists and it does, return true.
|
37 |
|
|
// If we asked for context does not exist and it does, return false.
|
38 |
|
|
return (empty($context->data) xor !empty($conf['exists']));
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
c304a780
|
Assos Assos
|
* Provide a summary description based upon the specified context.
|
43 |
85ad3d82
|
Assos Assos
|
*/
|
44 |
|
|
function ctools_context_exists_ctools_access_summary($conf, $context) {
|
45 |
|
|
if (!empty($conf['exists'])) {
|
46 |
|
|
return t('@identifier exists', array('@identifier' => $context->identifier));
|
47 |
|
|
}
|
48 |
|
|
else {
|
49 |
|
|
return t('@identifier does not exist', array('@identifier' => $context->identifier));
|
50 |
|
|
}
|
51 |
|
|
} |