function auto_nodetitle_form_node_type_form_alter in Automatic Nodetitles 8
Same name and namespace in other branches
- 7 auto_nodetitle.module \auto_nodetitle_form_node_type_form_alter()
Implements hook_form_FORM_ID_alter() for the node type form.
File
- ./
auto_nodetitle.module, line 153 - Allows hiding of the node title field and automatic title creation.
Code
function auto_nodetitle_form_node_type_form_alter(&$form, &$form_state) {
$type = $form_state['controller']
->getEntity()->type;
$default_value = auto_nodetitle_get_setting($type);
$form['auto_nodetitle'] = array(
'#type' => 'details',
'#title' => t('Automatic title generation'),
'#weight' => 0,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#attached' => array(
'js' => array(
'auto-nodetitle' => drupal_get_path('module', 'auto_nodetitle') . '/auto_nodetitle.js',
),
),
);
$form['auto_nodetitle']['status'] = 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'),
),
);
$form['auto_nodetitle']['pattern'] = array(
'#type' => 'textarea',
'#title' => t('Pattern for the title'),
'#description' => t('Leave blank for using the per default generated title. Otherwise this string will be used as title. Use the syntax [token] if you want to insert a replacement pattern.'),
'#default_value' => \Drupal::config('auto_nodetitle.node.' . $type)
->get('pattern') ?: '',
);
// Don't allow editing of the pattern if PHP is used, but the users lacks
// permission for PHP.
if (\Drupal::config('auto_nodetitle.node.' . $type)
->get('php') && !user_access('use PHP for title patterns')) {
$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'),
));
}
// Display the list of available placeholders if token module is installed.
if (Drupal::moduleHandler()
->moduleExists('token')) {
$form['auto_nodetitle']['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array(
'node',
),
);
}
$form['auto_nodetitle']['php'] = array(
'#access' => user_access('use PHP for title patterns'),
'#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' => \Drupal::config('auto_nodetitle.node.' . $type)
->get('php') ?: '',
);
$form['actions']['submit']['#submit'][] = 'auto_nodetitle_form_node_type_form_submit';
}