You are here

function sharemessage_install in Share Message 7

Same name and namespace in other branches
  1. 8 sharemessage.install \sharemessage_install()

Implements hook_install().

File

./sharemessage.install, line 104
Install hooks for sharemessage module.

Code

function sharemessage_install() {

  // This module should show only the addThis buttons,
  // so that all fields will be hidden.
  $display_hidden = array(
    'display' => array(
      'default' => array(
        'type' => 'hidden',
      ),
    ),
  );

  // Check if sharemessage_title field is not already created.
  if (!field_info_field('sharemessage_title')) {
    $field = array(
      'field_name' => 'sharemessage_title',
      'type' => 'text',
      'locked' => TRUE,
      'translatable' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_title',
      'entity_type' => 'sharemessage',
      'label' => 'Share Title',
      'description' => 'Used as title in the share message, where applicable: Facebook, E-Mail subject, ...',
      'bundle' => 'sharemessage',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_long field is not already created.
  if (!field_info_field('sharemessage_long')) {
    $field = array(
      'field_name' => 'sharemessage_long',
      'type' => 'text_long',
      'locked' => TRUE,
      'translatable' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_long',
      'entity_type' => 'sharemessage',
      'label' => 'Long Description',
      'description' => 'Used as long description for the share message, where applicable: Facebook, E-mail body, ...',
      'bundle' => 'sharemessage',
      'settings' => array(
        'max_length' => 400,
      ),
      'widget' => array(
        'type' => 'text_textarea',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_short field is not already created.
  if (!field_info_field('sharemessage_short')) {
    $field = array(
      'field_name' => 'sharemessage_short',
      'type' => 'text',
      'locked' => TRUE,
      'translatable' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_short',
      'entity_type' => 'sharemessage',
      'label' => 'Short Description',
      'description' => 'Used as short description for twitter messages.',
      'bundle' => 'sharemessage',
      'settings' => array(
        'max_length' => 140,
      ),
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_image field is not already created.
  if (!field_info_field('sharemessage_image')) {
    $field = array(
      'field_name' => 'sharemessage_image',
      'type' => 'image',
      'locked' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_image',
      'entity_type' => 'sharemessage',
      'label' => 'Image',
      'description' => 'Upload the image you want to use as image for the share message, where applicable: Facebook, E-mail body, ...',
      'bundle' => 'sharemessage',
      'widget' => array(
        'type' => 'image_image',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_image_url field is not already created.
  if (!field_info_field('sharemessage_image_url')) {
    $field = array(
      'field_name' => 'sharemessage_image_url',
      'type' => 'text',
      'locked' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_image_url',
      'entity_type' => 'sharemessage',
      'label' => 'Image URL',
      'description' => 'Or enter the image URL that will be used in case the image is not uploaded.',
      'bundle' => 'sharemessage',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_video_url field is not already created.
  if (!field_info_field('sharemessage_video_url')) {
    $field = array(
      'field_name' => 'sharemessage_video_url',
      'type' => 'text',
      'locked' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_video_url',
      'entity_type' => 'sharemessage',
      'label' => 'Video URL',
      'description' => 'The image URL that will be used for sharing. If a video URL is set, the image will be used as a thumbnail for the video.',
      'bundle' => 'sharemessage',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }

  // Check if sharemessage_url field is not already created.
  if (!field_info_field('sharemessage_url')) {
    $field = array(
      'field_name' => 'sharemessage_url',
      'type' => 'text',
      'locked' => TRUE,
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
      'field_name' => 'sharemessage_url',
      'entity_type' => 'sharemessage',
      'label' => 'Message URL',
      'description' => 'Specific sharemessage URL that should be shared, defaults to the current page.',
      'bundle' => 'sharemessage',
      'widget' => array(
        'type' => 'text_textfield',
      ),
    ) + $display_hidden;
    field_create_instance($instance);
  }
}