node.variable.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @file
  4. * Variable API module. Definition for Drupal core variables
  5. */
  6. /**
  7. * Implements hook_variable_info().
  8. */
  9. function node_variable_info($options) {
  10. // Per content type options. Group 'node_type_settings'.
  11. $variables['teaser_length_[node_type]'] = array(
  12. 'type' => 'multiple',
  13. 'title' => t('Length of trimmed posts'),
  14. 'repeat' => array(
  15. 'type' => 'select',
  16. 'default' => 600,
  17. 'options' => 'text_length',
  18. ),
  19. '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),
  20. 'group' => 'node_type_settings',
  21. );
  22. $variables['node_preview_[node_type]'] = array(
  23. 'type' => 'multiple',
  24. 'title' => t('Preview before submitting'),
  25. 'repeat' => array(
  26. 'type' => 'select',
  27. 'default' => DRUPAL_OPTIONAL,
  28. 'options callback' => 'node_variable_option_list',
  29. ),
  30. 'description' => t('Must users preview posts before submitting?', array(), $options),
  31. 'group' => 'node_type_settings',
  32. );
  33. $variables['node_options_[node_type]'] = array(
  34. 'type' => 'multiple',
  35. 'title' => t('Default options', array(), $options),
  36. 'repeat' => array(
  37. 'type' => 'options',
  38. 'default' => array('status', 'promote'),
  39. 'options callback' => 'node_variable_option_list',
  40. ),
  41. 'description' => t('Users with the <em>administer nodes</em> permission will be able to override these options.', array(), $options),
  42. 'group' => 'node_type_settings',
  43. );
  44. $variables['node_submitted_[node_type]'] = array(
  45. 'type' => 'multiple',
  46. 'title' => t('Display author and date information.', array(), $options),
  47. 'repeat' => array(
  48. 'default' => TRUE,
  49. 'type' => 'boolean',
  50. ),
  51. 'description' => t('Author username and publish date will be displayed.', array(), $options),
  52. 'group' => 'node_type_settings',
  53. );
  54. return $variables;
  55. }
  56. /**
  57. * Implements hook_variable_group_info().
  58. */
  59. function node_variable_group_info() {
  60. $groups['node_type_settings'] = array(
  61. 'title' => t('Node type settings'),
  62. 'description' => t('Settings for each node type.'),
  63. 'access' => 'administer nodes',
  64. 'path' => 'admin/structure/types',
  65. );
  66. return $groups;
  67. }
  68. /**
  69. * Implements hook_variable_type_info()
  70. */
  71. function node_variable_type_info() {
  72. $type['node_type'] = array(
  73. 'title' => t('Node type'),
  74. 'options callback' => 'node_type_get_names',
  75. 'type' => 'select',
  76. );
  77. $type['text_length'] = array(
  78. 'title' => t('Text length'),
  79. 'options callback' => 'node_variable_option_text_length',
  80. 'type' => 'select',
  81. );
  82. return $type;
  83. }
  84. /**
  85. * Callback for node variable options
  86. */
  87. function node_variable_option_text_length($variable, $options = array()) {
  88. return array(
  89. 0 => t('Unlimited', array(), $options),
  90. 200 => t('@count characters', array('@count' => 200), $options),
  91. 400 => t('@count characters', array('@count' => 400), $options),
  92. 600 => t('@count characters', array('@count' => 600), $options),
  93. 800 => t('@count characters', array('@count' => 800), $options),
  94. 1000 => t('@count characters', array('@count' => 1000), $options),
  95. 1200 => t('@count characters', array('@count' => 1200), $options),
  96. 1400 => t('@count characters', array('@count' => 1400), $options),
  97. 1600 => t('@count characters', array('@count' => 1600), $options),
  98. 1800 => t('@count characters', array('@count' => 1800), $options),
  99. 2000 => t('@count characters', array('@count' => 2000), $options),
  100. );
  101. }
  102. /**
  103. * Callback for variable options
  104. */
  105. function node_variable_option_list($variable, $options = array()) {
  106. switch ($variable['parent']) {
  107. case 'node_preview_[node_type]':
  108. return array(
  109. DRUPAL_DISABLED => t('Disabled', array(), $options),
  110. DRUPAL_OPTIONAL => t('Optional', array(), $options),
  111. DRUPAL_REQUIRED => t('Required', array(), $options),
  112. );
  113. case 'node_options_[node_type]':
  114. return array(
  115. 'status' => t('Published', array(), $options),
  116. 'promote' => t('Promoted to front page', array(), $options),
  117. 'sticky' => t('Sticky at top of lists', array(), $options),
  118. 'revision' => t('Create new revision', array(), $options),
  119. );
  120. }
  121. }
  122. /**
  123. * Build subform for variables for node type
  124. *
  125. * @param $type
  126. * Node type name
  127. * @param $list
  128. * List of variables to include
  129. */
  130. function node_variable_type_subform($type, $list) {
  131. module_load_include('form.inc', 'variable');
  132. foreach ($list as $name) {
  133. $variable = variable_get_child($name . '_[node_type]', $type);
  134. $form[$name] = variable_form_element($variable);
  135. }
  136. return $form;
  137. }