You are here

function title_entity_info_alter in Title 7

Implements hook_entity_info_alter().

File

./title.module, line 59

Code

function title_entity_info_alter(&$info) {
  foreach ($info as $entity_type => $entity_info) {
    if (!empty($entity_info['fieldable']) && !empty($info[$entity_type]['field replacement'])) {
      foreach ($info[$entity_type]['field replacement'] as $legacy_field => $data) {

        // Provide defaults for the replacing field name.
        $fr_info =& $info[$entity_type]['field replacement'][$legacy_field];
        if (empty($fr_info['field']['field_name'])) {
          $fr_info['field']['field_name'] = $legacy_field . '_field';
        }
        $fr_info['instance']['field_name'] = $fr_info['field']['field_name'];

        // Provide defaults for the sync callbacks.
        $type = $fr_info['field']['type'];
        if (empty($fr_info['callbacks'])) {
          $fr_info['callbacks'] = array();
        }
        $fr_info['callbacks'] += array(
          'sync_get' => "title_field_{$type}_sync_get",
          'sync_set' => "title_field_{$type}_sync_set",
        );

        // Support add explicit support for entity_label().
        if (isset($entity_info['entity keys']['label']) && $entity_info['entity keys']['label'] == $legacy_field) {

          // Store the original label callback for compatibility reasons.
          if (isset($info[$entity_type]['label callback'])) {
            $info[$entity_type]['label fallback']['title'] = $info[$entity_type]['label callback'];
          }
          $info[$entity_type]['label callback'] = 'title_entity_label';
          $fr_info += array(
            'preprocess_key' => $info[$entity_type]['entity keys']['label'],
          );
        }
      }
    }
  }
}