Projet

Général

Profil

Paste
Télécharger (4,91 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / variable / includes / node.variable.inc @ ba09eb79

1
<?php
2
/**
3
 * @file
4
 * Variable API module. Definition for Drupal core variables
5
 */
6

    
7
/**
8
 * Implements hook_variable_info().
9
 */
10
function node_variable_info($options) {
11
  // Per content type options. Group 'node_type_settings'.
12
  $variables['teaser_length_[node_type]'] = array(
13
    'type' => 'multiple',
14
    'title' => t('Length of trimmed posts'),
15
    'repeat' => array(
16
      'type' => 'select',
17
      'default' => 600,
18
      'options' => 'text_length',
19
    ),
20
    'description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.", array(), $options),
21
    'group' => 'node_type_settings',
22
  );
23
  $variables['node_preview_[node_type]'] = array(
24
    'type' => 'multiple',
25
    'title' => t('Preview before submitting'),
26
    'repeat' => array(
27
      'type' => 'select',
28
      'default' => DRUPAL_OPTIONAL,
29
      'options callback' => 'node_variable_option_list',
30
    ),
31
    'description' => t('Must users preview posts before submitting?', array(), $options),
32
    'group' => 'node_type_settings',
33
  );
34
  $variables['node_options_[node_type]'] = array(
35
    'type' => 'multiple',
36
    'title' => t('Default options', array(), $options),
37
    'repeat' => array(
38
      'type' => 'options',
39
      'default' => array('status', 'promote'),
40
      'options callback' => 'node_variable_option_list',
41
    ),
42
    'description' => t('Users with the <em>administer nodes</em> permission will be able to override these options.', array(), $options),
43
    'group' => 'node_type_settings',
44
  );
45
  $variables['node_submitted_[node_type]'] = array(
46
    'type' => 'multiple',
47
    'title' => t('Display author and date information.', array(), $options),
48
    'repeat' => array(
49
      'default' => TRUE,
50
      'type' => 'boolean',
51
    ),
52
    'description' => t('Author username and publish date will be displayed.', array(), $options),
53
    'group' => 'node_type_settings',
54
  );
55
  return $variables;
56
}
57

    
58

    
59
/**
60
 * Implements hook_variable_group_info().
61
 */
62
function node_variable_group_info() {
63
  $groups['node_type_settings'] = array(
64
    'title' => t('Node type settings'),
65
    'description' => t('Settings for each node type.'),
66
    'access' => 'administer nodes',
67
    'path' => 'admin/structure/types', 
68
  );
69
  return $groups;
70
}
71

    
72
/**
73
 * Implements hook_variable_type_info()
74
 */
75
function node_variable_type_info() {
76
  $type['node_type'] = array(
77
    'title' => t('Node type'),
78
    'options callback' => 'node_type_get_names',
79
    'type' => 'select',
80
  );
81
  $type['text_length'] = array(
82
    'title' => t('Text length'),
83
    'options callback' => 'node_variable_option_text_length',
84
    'type' => 'select',
85
  );
86
  return $type;
87
}
88

    
89
/**
90
 * Callback for node variable options
91
 */
92
function node_variable_option_text_length($variable, $options = array()) {
93
  return array(
94
       0 => t('Unlimited', array(), $options),
95
     200 => t('@count characters', array('@count' =>  200), $options),
96
     400 => t('@count characters', array('@count' =>  400), $options),
97
     600 => t('@count characters', array('@count' =>  600), $options),
98
     800 => t('@count characters', array('@count' =>  800), $options),
99
    1000 => t('@count characters', array('@count' => 1000), $options),
100
    1200 => t('@count characters', array('@count' => 1200), $options),
101
    1400 => t('@count characters', array('@count' => 1400), $options),
102
    1600 => t('@count characters', array('@count' => 1600), $options),
103
    1800 => t('@count characters', array('@count' => 1800), $options),
104
    2000 => t('@count characters', array('@count' => 2000), $options),
105
  );  
106
}
107

    
108
/**
109
 * Callback for variable options
110
 */
111
function node_variable_option_list($variable, $options = array()) {
112
  switch ($variable['parent']) {
113
    case 'node_preview_[node_type]':
114
      return array(
115
        DRUPAL_DISABLED => t('Disabled', array(), $options),
116
        DRUPAL_OPTIONAL => t('Optional', array(), $options),
117
        DRUPAL_REQUIRED => t('Required', array(), $options),
118
      );
119
    case 'node_options_[node_type]':
120
      return array(
121
        'status' => t('Published', array(), $options),
122
        'promote' => t('Promoted to front page', array(), $options),
123
        'sticky' => t('Sticky at top of lists', array(), $options),
124
        'revision' => t('Create new revision', array(), $options),     
125
      );
126
  }
127
}
128

    
129
/**
130
 * Build subform for variables for node type
131
 * 
132
 * @param $type
133
 *   Node type name
134
 * @param $list
135
 *   List of variables to include
136
 */
137
function node_variable_type_subform($type, $list) {
138
  module_load_include('form.inc', 'variable');
139
  foreach ($list as $name) {
140
    $variable = variable_get_child($name . '_[node_type]', $type);
141
    $form[$name] = variable_form_element($variable);  
142
  }
143
  return $form;
144
}