View source
<?php
define('CAROUSEL_NODE_TYPE', 'bootstrap_carousel');
function bootstrap_carousel_install() {
node_types_rebuild();
_bootstrap_carousel_add_default_content_type_fields();
}
function bootstrap_carousel_uninstall() {
_bootstrap_carousel_delete_nodes();
_bootstrap_carousel_delete_default_content_type_fields();
_bootstrap_carousel_delete_content_type();
variable_del('bootstrap_carousel_youtube_player_api');
cache_clear_all();
}
function bootstrap_carousel_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
if (($library = libraries_detect('bootstrap')) && !empty($library['installed'])) {
$requirements['bootstrap_library'] = array(
'title' => $t('Bootstrap library'),
'value' => $t('Installed'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['bootstrap_library'] = array(
'title' => $t('Bootstrap library'),
'value' => $t('Not installed'),
'description' => $library['error message'],
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
function bootstrap_carousel_field_schema($field) {
$varchar = array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
);
$text = array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
);
$int = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
);
$columns = array(
'carousel_image' => $int,
'image_alt_text' => $varchar,
'carousel_caption' => $text,
'carousel_video' => $varchar,
'format' => $varchar,
);
return array(
'columns' => $columns,
'indexes' => array(),
'foreign keys' => array(
'format' => array(
'table' => 'filter_format',
'columns' => array(
'format' => 'format',
),
),
'file_managed' => array(
'table' => 'file_managed',
'columns' => array(
'fid' => 'carousel_image',
),
),
),
);
}
function _bootstrap_carousel_add_default_content_type_fields() {
$fields = _bootstrap_carousel_get_content_type_fields_definition();
foreach ($fields as $field) {
field_create_field($field);
field_create_instance($field);
}
}
function _bootstrap_carousel_delete_default_content_type_fields() {
$fields = _bootstrap_carousel_get_content_type_fields_definition();
foreach ($fields as $field) {
field_delete_instance($field);
field_delete_field($field['field_name']);
}
}
function _bootstrap_carousel_delete_nodes() {
$query = <<<QUERY
SELECT n.nid
FROM {node} n
WHERE n.type = :type
QUERY;
$args = array(
':type' => CAROUSEL_NODE_TYPE,
);
$carousel_nodes = db_query($query, $args);
foreach ($carousel_nodes as $node) {
node_delete($node->nid);
}
}
function _bootstrap_carousel_delete_content_type() {
node_type_delete(CAROUSEL_NODE_TYPE);
}
function _bootstrap_carousel_get_content_type_fields_definition() {
$weight = 0;
$fields = array(
array(
'field_name' => 'field_slides',
'type' => 'bootstrap_carousel',
'translatable' => TRUE,
'entity_type' => 'node',
'bundle' => CAROUSEL_NODE_TYPE,
'label' => t('Bootstrap Carousel Slides'),
'cardinality' => -1,
),
array(
'field_name' => 'field_control_options',
'type' => 'list_text',
'translatable' => TRUE,
'entity_type' => 'node',
'bundle' => CAROUSEL_NODE_TYPE,
'label' => t('Carousel Control Options'),
'cardinality' => -1,
'indexes' => array(
'value' => array(
0 => 'value',
),
),
'locked' => 0,
'module' => 'list',
'settings' => array(
'allowed_values' => array(
1 => t('Arrows control'),
2 => t('Bullets control'),
3 => t('Pause Cycling on Hover'),
),
'allowed_values_function' => '',
),
'widget' => array(
'active' => 1,
'module' => 'options',
'type' => 'options_buttons',
),
),
array(
'field_name' => 'field_carousel_interval',
'type' => 'number_integer',
'active' => 1,
'cardinality' => 1,
'entity_type' => 'node',
'module' => 'number',
'translatable' => TRUE,
'bundle' => CAROUSEL_NODE_TYPE,
'label' => t('Transition Interval'),
'description' => t('The amount of time to delay between automatically cycling an item (milliseconds). If it is empty the carousel will not automatically cycle.'),
),
);
return $fields;
}