You are here

function auto_nodetitle_node_settings_form in Automatic Nodetitles 6

Same name and namespace in other branches
  1. 5 auto_nodetitle.module \auto_nodetitle_node_settings_form()

Helper function for hook_form_alter() renders the settings per node-type.

1 call to auto_nodetitle_node_settings_form()
auto_nodetitle_form_alter in ./auto_nodetitle.module
Implementation of hook_form_alter().

File

./auto_nodetitle.module, line 149
Allows hiding of the node title field and automatic title creation

Code

function auto_nodetitle_node_settings_form(&$form) {
  $default_value = auto_nodetitle_get_setting($form['#node_type']->type);
  $form['auto_nodetitle'] = array(
    '#type' => 'fieldset',
    '#title' => t('Automatic title generation'),
    '#weight' => 0,
    '#collapsible' => TRUE,
    '#collapsed' => !$default_value,
  );
  $form['auto_nodetitle']['ant'] = array(
    '#type' => 'radios',
    '#default_value' => $default_value,
    '#options' => array(
      t('Disabled'),
      t('Automatically generate the title and hide the title field'),
      t('Automatically generate the title if the title field is left empty'),
    ),
  );
  if (module_exists('token') || user_access('use PHP for title patterns')) {
    $description = t('Leave blank for using the per default generated title. Otherwise this string will be used as title.');
    if (module_exists('token')) {
      $description .= ' ' . t('Use the syntax [token] if you want to insert a replacement pattern.');
    }
    $form['auto_nodetitle']['ant_pattern'] = array(
      '#type' => 'textarea',
      '#title' => t('Pattern for the title'),
      '#description' => $description,
      '#default_value' => variable_get('ant_pattern_' . $form['#node_type']->type, ''),
    );

    // Don't allow editing of the pattern if PHP is used, but the users lacks
    // permission for PHP.
    if (variable_get('ant_php_' . $form['#node_type']->type, '') && !user_access('use PHP for title patterns')) {
      $form['auto_nodetitle']['ant_pattern']['#value'] = $form['auto_nodetitle']['ant_pattern']['#default_value'];
      $form['auto_nodetitle']['ant_pattern']['#disabled'] = TRUE;
      $form['auto_nodetitle']['ant_pattern']['#description'] = t('You are not allow the configure the pattern for the title, as you lack the %permission permission.', array(
        '%permission' => t('Use PHP for title patterns'),
      ));
    }
  }
  if (module_exists('token')) {
    $form['auto_nodetitle']['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
    );
    $form['auto_nodetitle']['token_help']['help'] = array(
      '#value' => theme('token_help', 'node'),
    );
  }
  if (user_access('use PHP for title patterns')) {
    $form['auto_nodetitle']['ant_php'] = array(
      '#type' => 'checkbox',
      '#title' => t('Evaluate PHP in pattern.'),
      '#description' => t('Put PHP code above that returns your string, but make sure you surround code in <?php and ?>. Note that $node is available and can be used by your code.'),
      '#default_value' => variable_get('ant_php_' . $form['#node_type']->type, ''),
    );
  }
  else {
    $form['auto_nodetitle']['auto_nodetitle_php'] = array(
      '#type' => 'value',
      '#value' => variable_get('ant_php_' . $form['#node_type']->type, ''),
    );
  }
}