You are here

function mass_contact_install in Mass Contact 7

Same name and namespace in other branches
  1. 8 mass_contact.install \mass_contact_install()
  2. 5.2 mass_contact.install \mass_contact_install()
  3. 5 mass_contact.install \mass_contact_install()
  4. 6 mass_contact.install \mass_contact_install()

Implements hook_install().

File

./mass_contact.install, line 72
Install, update and uninstall functions for the Mass Contact module.

Code

function mass_contact_install() {

  // Use get_t() to get the name of the localization function for translation
  // during install. For use when t() is not available.
  $t = get_t();

  // Define the node type.
  $node_type_definition = array(
    'type' => 'mass_contact',
    'name' => $t('Mass Contact message'),
    'base' => 'node_content',
    'description' => $t('Archived copies of mass email messages sent from this site.'),
    'custom' => 1,
    'modified' => 1,
    'title_label' => $t('Subject'),
    'status' => 0,
    'promote' => 0,
    'sticky' => 0,
    'comment' => 0,
  );

  // Complete the node type definition by setting any defaults not explicitly
  // declared above.
  $mass_contact_node_type = node_type_set_defaults($node_type_definition);

  // Add the body field to the node type.
  node_add_body_field($mass_contact_node_type, $t('Message body'));

  // Save the node type.
  node_type_save($mass_contact_node_type);

  // Load the instance definition for the node type's body.
  $body_instance = field_info_instance('node', 'body', 'mass_contact');

  // Save the changes to the body field instance.
  field_update_instance($body_instance);

  // Create all the fields that are being adding to the node type.
  foreach (_mass_contact_fields() as $field) {
    field_create_field($field);
  }

  // Create all the instances for the fields.
  foreach (_mass_contact_field_instances() as $instance) {
    $instance['entity_type'] = 'node';
    $instance['bundle'] = $node_type_definition['type'];
    field_create_instance($instance);
  }
}