sharemessage.install in Share Message 7
Same filename and directory in other branches
Install hooks for sharemessage module.
File
sharemessage.installView source
<?php
/**
* @file
* Install hooks for sharemessage module.
*/
/**
* Implements hook_schema().
*/
function sharemessage_schema() {
$schema['sharemessage'] = array(
'description' => 'Contains share messages.',
'fields' => array(
'smid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Message ID.',
),
'label' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
'default' => '',
'description' => 'Message Label.',
),
'bundle' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
'default' => '',
'description' => 'Message Bundle.',
),
'name' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
'default' => '',
'description' => 'Message Name (machine name).',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x1,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'changed' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Date of change.',
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Creation date.',
),
'override_default_settings' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Override default settings.',
),
'settings' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional settings.',
),
'block' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Expose selected share messages as block.',
),
),
'primary key' => array(
'smid',
),
'unique keys' => array(
'name' => array(
'name',
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
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);
}
}
/**
* Implements hook_uninstall().
*/
function sharemessage_uninstall() {
field_delete_field('sharemessage_title');
field_delete_field('sharemessage_long');
field_delete_field('sharemessage_short');
field_delete_field('sharemessage_image');
field_delete_field('sharemessage_image_url');
field_delete_field('sharemessage_url');
field_delete_field('sharemessage_video_url');
}
/**
* Change the tweet service to twitter.
*/
function sharemessage_update_7000() {
// Removed as behavior seems to have changed again.
}
/**
* Add the video url field.
*/
function sharemessage_update_7001() {
$url_field_instance = field_info_instance('sharemessage', 'sharemessage_url', 'sharemessage');
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',
'weight' => $url_field_instance['widget']['weight'],
),
'display' => array(
'default' => array(
'type' => 'hidden',
),
),
);
field_create_instance($instance);
}
// Move the url field below the video field.
$url_field_instance['widget']['weight']++;
field_update_instance($url_field_instance);
}
Functions
Name | Description |
---|---|
sharemessage_install | Implements hook_install(). |
sharemessage_schema | Implements hook_schema(). |
sharemessage_uninstall | Implements hook_uninstall(). |
sharemessage_update_7000 | Change the tweet service to twitter. |
sharemessage_update_7001 | Add the video url field. |