function newsletter_subscriber_install in Newsletter 7.2
Implements hook_install().
File
- modules/
subscriber/ newsletter_subscriber.install, line 14 - Sets up the base table for newsletter subscribers and a table to store information about the subscriber types, install, uninstall and update functions for Newsletter subscriber module.
Code
function newsletter_subscriber_install() {
// Create default subscriber type
$roles = user_roles(TRUE);
$type = newsletter_subscriber_type_create(array(
'type' => 'general',
'name' => t('General subscriber'),
'description' => '',
'weight' => 0,
'data' => array(
'allow_anonymous' => TRUE,
'roles' => array_keys($roles),
),
));
$type
->save();
// Add entity reference field of newsletter_lists
$field = array(
'field_name' => 'field_newsletter_list',
'type' => 'entityreference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'target_type' => 'newsletter_list',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(
'newsletter_list',
),
),
),
);
if (!field_info_field($field['field_name'])) {
field_create_field($field);
}
// Attach it to subscriber entity
$instance = array(
'field_name' => 'field_newsletter_list',
'entity_type' => 'newsletter_subscriber',
'bundle' => 'general',
'label' => 'Lists',
'required' => TRUE,
'widget' => array(
'weight' => 0,
'type' => 'options_buttons',
'active' => 1,
),
'settings' => array(
'target_type' => 'newsletter_list',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(
'newsletter_list',
),
),
),
);
if (!field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle'])) {
field_create_instance($instance);
}
}