Projet

Général

Profil

Paste
Télécharger (2,22 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / plugins / access / forum_container.inc @ 74f6bef0

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide access control based upon term vocabulary
6
 */
7
/**
8
 * Plugins are described by creating a $plugin array which will be used
9
 * by the system that includes this file.
10
 */
11
$plugin = array(
12
  'title' => t("Forum: container"),
13
  'description' => t('Control access by whether or not the forum is a container.'),
14
  'callback' => 'advanced_forum_forum_container_ctools_access_check',
15
  'default' => array('container' => 0),
16
  'settings form' => 'advanced_forum_forum_container_ctools_access_settings',
17
  'settings form submit' => 'advanced_forum_forum_container_ctools_access_settings_submit',
18
  'summary' => 'advanced_forum_forum_container_ctools_acesss_summary',
19
  'required context' => new ctools_context_required(t('Forum'), array('forum')),
20
);
21

    
22
/**
23
 * Settings form for the 'by term_vocabulary' access plugin
24
 */
25
function advanced_forum_forum_container_ctools_access_settings($form, &$form_state, $conf) {
26
  $form['settings']['container'] = array(
27
    '#type' => 'select',
28
    '#title' => t('Container'),
29
    '#options' => array(
30
      0 => t('Pass if forum is a container'),
31
      1 => t('Pass if forum is not a container')
32
    ),
33
    '#default_value' => $conf['container'],
34
  );
35

    
36
  return $form;
37
}
38

    
39
/**
40
 * Compress the term_vocabularys allowed to the minimum.
41
 */
42
function advanced_forum_forum_container_ctools_access_settings_submit($form, &$form_state) {
43
  $form_state['values']['settings']['rids'] = array_keys(array_filter($form_state['values']['settings']['rids']));
44
}
45

    
46
/**
47
 * Check for access.
48
 */
49
function advanced_forum_forum_container_ctools_access_check($conf, $context) {
50
  // As far as I know there should always be a context at this point, but this
51
  // is safe.
52
  if (empty($context) || empty($context->data)) {
53
    return FALSE;
54
  }
55

    
56
  // xor returns false if the two bools are the same, and true if they are not.
57
  return $context->data->container xor !empty($conf['container']);
58
}
59

    
60
/**
61
 * Provide a summary description based upon the checked term_vocabularys.
62
 */
63
function advanced_forum_forum_container_ctools_acesss_summary($conf, $context) {
64
  $comparison = empty($conf['container']) ? "is" : 'is not';
65

    
66
  return t('@id1 @comp a forum container', array('@comp' => $comparison, '@id1' => $context->identifier));
67
}