You are here

function field_token_value_field_instance_settings_form in Field Token Value 7

Implements hook_field_instance_settings_form().

File

./field_token_value.module, line 53
Provides a field type allowing the value to be set using tokens.

Code

function field_token_value_field_instance_settings_form($field, $instance) {
  $form['field_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Field value'),
    '#description' => t('Enter the value for this field. Tokens are automatically replaced upon saving of the node itself.'),
    '#default_value' => $instance['settings']['field_value'],
    '#element_validate' => array(
      'token_element_validate',
    ),
    '#token_types' => array(
      $instance['entity_type'],
    ),
    '#required' => TRUE,
    '#maxlength' => 1024,
  );

  // Determine the version of token being used. That way we can ensure the token
  // list is complete.
  $info = token_theme();

  // The theme_token_tree_link really only works if the token_types variable
  // is available. This allows us to add the entity tokens to the list. This
  // variable is only available with token version 1.6 or higher, or with the
  // path found in https://www.drupal.org/node/2289203.
  if (isset($info['token_tree_link']['variables']['token_types'])) {
    $theme = 'token_tree_link';
  }
  else {
    $theme = 'token_tree';
  }
  $form['token_help'] = array(
    '#theme' => $theme,
    '#token_types' => array(
      $instance['entity_type'],
    ),
  );
  $form['remove_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remove empty tokens'),
    '#description' => t('Select this option to remove tokens from the final text if no replacement value can be generated.'),
    '#default_value' => $instance['settings']['remove_empty'],
  );
  return $form;
}