You are here

function birthdays_defaults_install in Birthdays 7

Implements hook_install().

File

defaults/birthdays_defaults.install, line 11
Create a default field and action.

Code

function birthdays_defaults_install() {

  // Clear the field cache to be sure the new field type is available.
  field_cache_clear();

  // Create the default field.
  if (!field_info_field('birthdays')) {
    field_create_field(array(
      'field_name' => 'birthdays',
      'type' => 'birthdays_date',
      'cardinality' => 1,
      'translatable' => FALSE,
      'entity_types' => array(
        'user',
      ),
    ));
  }

  // Create the deault field instance.
  if (!field_info_instance('user', 'birthdays', 'user')) {
    field_create_instance(array(
      'field_name' => 'birthdays',
      'entity_type' => 'user',
      'bundle' => 'user',
      'label' => st('Birthday'),
    ));
  }

  // Explain that.
  if (module_exists('field_ui')) {
    $field_ui = st('You can adjust the birthday !field_settings, !manage_account_fields or !manage_the_display under Administration » Configuration » People.', array(
      '!field_settings' => l(st('field settings'), 'admin/config/people/accounts/fields/birthdays'),
      '!manage_account_fields' => l(st('manage account fields'), 'admin/config/people/accounts/fields'),
      '!manage_the_display' => l(st('manage the display'), 'admin/config/people/accounts/display'),
    ));
  }
  else {
    $field_ui = st('Enable the Field UI module to adjust the birthday field settings, manage account fields or manage the display under Administration » Configuration » People.');
  }
  drupal_set_message(st('A default field has been attached to the user profiles.') . ' ' . $field_ui);

  // Create a default birthday mail action.
  if (!variable_get('birthdays_defaults_action')) {
    $aid = actions_save('system_send_email_action', 'system', _birthdays_defaults_action_parameters(), st('Happy birthday mail'));
    variable_set('birthdays_defaults_action', $aid);

    // Explain that.
    if (module_exists('trigger')) {
      drupal_set_message(st('A <em>Happy birthday mail</em> action has been created. You can !assign that action so that users recieve an email on their birthday.', array(
        '!assign' => l(st('assign'), 'admin/structure/trigger/birthdays'),
      )));
    }
    else {
      drupal_set_message(st('Enable the Trigger module and assign the newly created <em>Happy birthday mail</em> action to send users emails on their birthdays.'));
    }
  }

  // Explain views support.
  if (module_exists('views_ui')) {
    drupal_set_message(st('Birthdays defaults provides a default page and block with birthdays. You can !use_the_views_module to enable or customize them.', array(
      '!use_the_views_module' => l(st('use the views module'), 'admin/structure/views'),
    )));
  }
  else {
    drupal_set_message(st('You can use the the Views module to lists of birthdays as blocks or pages.'));
  }
}