Professional Documents
Culture Documents
BiblioTita Install
BiblioTita Install
php
//todo: campi: immagine (verificare se si pu caricare da link), categories
/**
* Implements hook_install().
*/
function bibliotita_install() {
//Create content type for the book
if (!in_array('bibliotita_book', node_type_get_names())){
$type = array(
'type' => 'bibliotita_book',
'name' => t('Book'),
'description' => t('A book'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'has_title' => false,
);
$type = node_type_set_defaults($type);
node_type_save($type);
}
//Create field isbn
if(!field_info_field('field_isbn')){
$field_isbn = array(
'field_name' => 'field_isbn',
'type' => 'text',
);
field_create_field($field_isbn);
}
//Create field title
if(!field_info_field('field_title')){
$field_title = array(
'field_name' => 'field_title',
'type' => 'text'
);
field_create_field($field_title);
}
//Create field author
if(!field_info_field('field_author')){
$field_author = array(
'field_name' => 'field_author',
'cardinality' => -1,
'type' => 'text'
);
field_create_field($field_author);
}
//Create field description
if(!field_info_field('field_description')){
$field_description = array(
'field_name' => 'field_description',
'type' => 'text'
);
field_create_field($field_description);
}
//Create field publisher
if(!field_info_field('field_publisher')){
$field_publisher = array(
'field_name' => 'field_publisher',
'type' => 'text'
);
field_create_field($field_publisher);
}
//Create field published date
if(!field_info_field('field_published_date')){
$field_published_date = array(
'field_name' => 'field_published_date',
'type' => 'text'
);
field_create_field($field_published_date);
}
$vocabularies = taxonomy_vocabulary_get_names();
//dpm($vocabularies);
$pos = FALSE;
foreach($vocabularies as $vocab){
//dpm('entro foreach:' . $vocab->name);
if ($vocab->machine_name == 'book_status'){
$pos = $vocab->vid;
}
}
/*
$pos = array_search('book_status', $vocabularies);
*/
//dpm($pos);
if ($pos !== FALSE) {
$vid = $pos;
//dpm('vocabolario gi esistente');
}else{
//Create Vocabulary status
$myVocabulary = array(
'name' => t('Status'),
'machine_name' => 'book_status',
'description' => t('The possible status of a book'),
'hierarchy' => 1,
'module' => 'bibliotita',
'weight' => 1
);
// argument must be an object
$myVocabulary = (object) $myVocabulary;
taxonomy_vocabulary_save($myVocabulary);
// horray, we have a vid now
$vid = $myVocabulary->vid;
$term = new stdClass();
$term->vid = $vid;
$term->name = t('Disponibile');
taxonomy_term_save($term);
field_create_instance($instance_author);
//Instance field description
$instance_description = array(
'field_name' => 'field_description',
'entity_type' => 'node',
'label' => t('Description'),
'bundle' => 'bibliotita_book',
'required' => FALSE,
'widget' => array('type' => 'textfield',),
);
field_create_instance($instance_description);
//Instance field publisher
$instance_publisher = array(
'field_name' => 'field_publisher',
'entity_type' => 'node',
'label' => t('Publisher'),
'bundle' => 'bibliotita_book',
'required' => FALSE,
'widget' => array('type' => 'textfield',),
);
field_create_instance($instance_publisher);
//Instance field published date
$instance_published_date = array(
'field_name' => 'field_published_date',
'entity_type' => 'node',
'label' => t('Published Date'),
'bundle' => 'bibliotita_book',
'required' => FALSE,
'widget' => array('type' => 'textfield',),
);
field_create_instance($instance_published_date);
//Instance field status
$instance_status = array(
'field_name' => 'field_status',
'entity_type' => 'node',
'label' => t('Status'),
'bundle' => 'bibliotita_book',
'required' => FALSE,
'widget' => array('type' => 'options_select',),
);
field_create_instance($instance_status);
//Create content type for book loan
if (!in_array('bibliotita_book_loan', node_type_get_names())){
$type = array(
'type' => 'bibliotita_book_loan',
'name' => t('Book Loan'),
'description' => t('A book loan'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'has_title' => false,
);
$type = node_type_set_defaults($type);
node_type_save($type);
}
/**
* Implements hook_uninstall().
*/
function bibliotita_uninstall() {
db_delete('node')
-> condition('type', 'bibliotita_book', '=')
-> execute();
node_type_delete('bibliotita_book');
db_delete('node')
-> condition('type', 'bibliotita_book_loan', '=')
-> execute();
node_type_delete('bibliotita_book_loan');
}