function google_authorship_enable in Google Authorship 7.2
Same name and namespace in other branches
- 7 google_authorship.install \google_authorship_enable()
Implements hook_enable().
This will check to see if the field has been created and if not will create it. * It will then add an instance of that field to the user entity and set various defaults and other settings.
File
- ./
google_authorship.install, line 16 - Adds field to user entity on enable and removes fields on uninstall. Will not delete fields upon disable.
Code
function google_authorship_enable() {
// Check if our field is not already created.
if (!field_info_field('field_google_plus_id')) {
// Creates an array to pass to Drupal's field_create_field function.
$field = array(
'field_name' => 'field_google_plus_id',
'type' => 'text',
// The maximum number of values this field can store is 1
'cardinality' => '1',
);
// Takes the previous array and creates a new Drupal 7 field.
field_create_field($field);
// Create the array to pass to field_create_instance()
$instance = array(
'field_name' => 'field_google_plus_id',
'entity_type' => 'user',
'label' => 'Google+ ID',
'description' => t('This is the 21 digit number found in the URL of
this user\'s Google+ profile.'),
'bundle' => 'user',
// If you don't set the "required" property then the field wont be
// required by default.
'settings' => array(
// Here you inform either or not you want this field showing up on
// the registration form.
'user_register_form' => 1,
),
// Sets the input widget type.
'widget' => array(
'type' => 'textfield',
'weight' => '1',
'settings' => array(
// Sets the max size of the input to 21, the size of Google+ IDs.
'size' => '21',
),
),
'display' => array(
'default' => array(
// Hide the Google+ ID on the user page.
'label' => 'hidden',
// Attempts to set the weight to 2, but Drupal's weight system has
// a bug.
'weight' => '2',
),
),
);
// Takes the previous array and creates a new Drupal 7 instance on the
// user bundle.
field_create_instance($instance);
}
}