You are here

function title_field_attach_create_bundle in Title 7

Implements hook_field_attach_create_bundle().

Automatically attach the replacement field to the new bundle.

File

./title.module, line 949

Code

function title_field_attach_create_bundle($entity_type, $bundle) {
  $entity_info = entity_get_info($entity_type);
  if (empty($entity_info['field replacement'])) {
    return;
  }
  $options = variable_get('title_' . $entity_type, array());
  foreach (array_keys($entity_info['field replacement']) as $legacy_field) {
    if (empty($options['auto_attach'][$legacy_field])) {
      continue;
    }

    // Do not continue if the replacement field already exists.
    $field_name = $entity_info['field replacement'][$legacy_field]['field']['field_name'];
    if (field_info_instance($entity_type, $field_name, $bundle)) {
      continue;
    }
    title_field_replacement_toggle($entity_type, $bundle, $legacy_field);
    $instance = field_info_instance($entity_type, $field_name, $bundle);
    if ($instance) {
      $params = array(
        '@entity_label' => drupal_strtolower($entity_info['label']),
        '%field_name' => $instance['label'],
      );
      drupal_set_message(t('The @entity_label %field_name field was automatically replaced.', $params));
    }
  }
}