$title) { $columns[$key] = array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ); } return array( 'columns' => $columns, 'indexes' => array( 'given' => array('given'), 'family' => array('family'), ), ); } /** * Implements hook_schema(). */ function name_schema() { $schema = array(); $schema['name_custom_format'] = array( 'fields' => array( 'ncfid' => array( 'description' => 'The primary identifier for a custom format.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'name' => array( 'description' => 'The name to identify the custom format to a user.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'machine_name' => array( 'description' => 'The machine name to identify the custom format to the system.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'format' => array( 'description' => 'The format string to apply to names.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), ), 'primary key' => array('ncfid'), ); return $schema; } /** * Implements hook_install(). * * Inserts some common name formats into the database. */ function name_install() { name_install_default_formats(); } /** * Implements hook_uninstall(). */ function name_uninstall() { variable_del('name_settings'); variable_del('name_user_preferred'); // There is no UI for this setting. variable_del('name_example_names'); } /** * This adds the formats that would otherwise be inserted during installation. */ function name_update_6000() { $ret = array(); // Create the table. $schema = array( 'fields' => array( 'ncfid' => array( 'description' => t('The primary identifier for a custom format.'), 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'name' => array( 'description' => t('The name to identify the custom format to a user.'), 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'machine_name' => array( 'description' => t('The machine name to identify the custom format to the system.'), 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'format' => array( 'description' => t('The format string to apply to names.'), 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), ), 'primary key' => array('ncfid'), ); db_create_table('name_custom_format', $schema); // Install some default values. $t = get_t(); name_install_default_formats(); // Clear the caches. cache_clear_all('*', 'cache', TRUE); cache_clear_all('*', 'cache_content', TRUE); if (module_exists('views')) { // Needed because this can be called from .install files module_load_include('module', 'views'); views_invalidate_cache(); } return t('Created name formats table {name_custom_format}.') . '
' . $t('The default set of custom name format strings was generated and saved. These are listed !here.', array('!here' => l($t('here', 'admin/config/regional/name')))); } /** * Move the user field selected realname into a variable to avoid doing lookups * on all user fields / instances during hook_user_load(). */ function name_update_7000() { foreach (field_info_instances('user', 'user') as $instance) { $field = field_info_field($instance['field_name']); if ($field['type'] == 'name' && !empty($instance['settings']['override_username'])) { variable_set('name_user_preferred', $instance['field_name']); break; } } } /** * Updates the field formatters to the new singular formatter type. */ function name_update_7002() { foreach (field_info_fields() as $field_name => $field) { if ($field['type'] == 'name' && !empty($field['bundles'])) { foreach ($field['bundles'] as $entity_type => $bundles) { foreach ($bundles as $bundle) { $changed = FALSE; $instance = field_info_instance($entity_type, $field_name, $bundle); if (!empty($instance['display'])) { foreach ($instance['display'] as $view_mode => &$display) { list($name, $output, $format) = explode('_', $display['type'] . '__'); if ($name == 'name') { switch ($output) { case 'default': case 'plain': case 'raw': $display['type'] = 'name_formatter'; $display['settings']['output'] = $output; if (empty($format)) { $format = 'default'; } $display['settings']['format'] = $format; // Ensure that the display settings for the two new fields // are set while we are updating the other display settings. $defaults = array( 'markup' => 0, 'multiple' => 'default', 'multiple_delimiter' => ', ', 'multiple_and' => 'text', // and or symbol 'multiple_delimiter_precedes_last' => 'never', // contextual, always, never 'multiple_el_al_min' => 3, 'multiple_el_al_first' => 1, ); foreach ($defaults as $key => $value) { if (!isset($display['settings'][$key])) { $display['settings'][$key] = $value; } } $changed = TRUE; break; default: // Assuming a third party formatter here. } } } } if ($changed) { field_update_instance($instance); } } } } } // The new formatter settings will not save unless we clear the caches. field_cache_clear(); cache_clear_all(); } /** * Inserts some common formats. */ function name_install_default_formats() { $t = get_t(); $formats = array( array( 'format' => '((((t+ig)+im)+if)+is)+jc', 'name' => $t('Full'), 'machine_name' => 'full', ), array( 'format' => 'g', 'name' => $t('Given'), 'machine_name' => 'given', ), array( 'format' => 'f', 'name' => $t('Family'), 'machine_name' => 'family', ), array( 'format' => 't+if', 'name' => $t('Title Family'), 'machine_name' => 'formal', ), array( 'format' => 'g+if', 'name' => $t('Given Family'), 'machine_name' => 'short_full', ), ); foreach ($formats as $format) { db_insert('name_custom_format') ->fields(array( 'name' => $format['name'], 'machine_name' => $format['machine_name'], 'format' => $format['format'], )) ->execute(); } }