function advpoll_install in Advanced Poll 7.3
Same name and namespace in other branches
- 8 advpoll.install \advpoll_install()
- 5 advpoll.install \advpoll_install()
- 6.3 advpoll.install \advpoll_install()
- 6 advpoll.install \advpoll_install()
- 6.2 advpoll.install \advpoll_install()
- 7 advpoll.install \advpoll_install()
- 7.2 advpoll.install \advpoll_install()
Implements hook_install().
File
- ./
advpoll.install, line 37 - Install file for Advanced Poll.
Code
function advpoll_install() {
// Fetch the t function for use in install.
$t = get_t();
// We define the node type as an associative array.
$node_adv = array(
'type' => 'advpoll',
'name' => $t('Advanced poll'),
'base' => 'node_content',
'has_title' => 1,
'description' => $t('Advanced poll adds additional poll functionality, cookie voting, write-ins and voting modes.'),
'title_label' => $t('Question'),
'custom' => TRUE,
);
/* Complete the node type definition by setting any defaults not explicitly
* declared above.
* http://api.drupal.org/api/function/node_type_set_defaults/7
*/
$content_type = node_type_set_defaults($node_adv);
// We add a body field and set the body label immediately.
node_add_body_field($content_type, $t('Description'));
// Save the content type.
node_type_save($content_type);
/* Load the instance definition for our content type's body.
* http://api.drupal.org/api/function/field_info_instance/7
*/
$body_instance = field_info_instance('node', 'body', 'advpoll');
/* Add our example_node_list view mode to the body instance display by
* instructing the body to display as a summary.
*/
$body_instance['display']['advpoll_list'] = array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
);
// http://api.drupal.org/api/function/field_update_instance/7
field_update_instance($body_instance);
// http://api.drupal.org/api/function/field_create_field/7
foreach (_advpoll_installed_fields() as $field) {
if (!field_info_field($field['field_name'])) {
field_create_field($field);
}
}
/* Create all the instances for our fields.
* http://api.drupal.org/api/function/field_create_instance/7
*/
foreach (_advpoll_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = $node_adv['type'];
if (!field_info_instance('node', $instance['field_name'], $node_adv['type'])) {
field_create_instance($instance);
}
}
}