From 849f4344d13b0060829b61b0ee2ad4660fff45b0 Mon Sep 17 00:00:00 2001 From: Carlo Landmeter Date: Fri, 4 Mar 2011 14:05:45 +0100 Subject: added support for views and added fields views default include file maintainer and contributor fields --- apk_browser.install | 394 +++++++++++++++++++++++++--------------------------- 1 file changed, 189 insertions(+), 205 deletions(-) (limited to 'apk_browser.install') diff --git a/apk_browser.install b/apk_browser.install index 6fd47f9..345f10f 100644 --- a/apk_browser.install +++ b/apk_browser.install @@ -1,205 +1,189 @@ - 'apk', //machine name - 'name' => 'Alpine package', // human name - 'base' => 'node_content', //api callback - 'description' => $t('Content type to store Alpine Linux packages'), - 'title_label' => $t('Package'), - //'has_title' => FALSE - ); - //set missing defaults and save the node type - $content_type = node_type_set_defaults($node_fields); - node_type_save($content_type); - - /* - * Create all the fields and instances we are adding to our content type. - */ - foreach (_apk_browser_field_vars() as $name => $fvars) { - $cardinality = ($name == 'apk_depends') ? '-1' : '1'; - if (!field_info_field($name)) { - $field = array( - 'field_name' => $name, - 'cardinality' => $cardinality, - 'type' => 'text', - 'settings' => array( - 'max_length' => $fvars['length'], - ), - - ); - field_create_field($field); - } - // now all instances - if (!field_info_instance('node', $name, 'apk')) { - $instance = array( - 'field_name' => $name, - 'label' => $fvars['label'], - 'type' => 'text', - 'entity_type' => 'node', - 'bundle' => 'apk', - 'widget' => array( - 'type' => 'text_textfield', - ), - 'display' => array( - 'default' => array( - 'label' => 'inline' - ) - ) - ); - field_create_instance($instance); - } - } - - /* - * Create taxonamy vocab - * create table and asign it - */ - $vnames = array( - 'repo' => $t('Repository') , - 'arch' => $t('Architecture') - ); - foreach ($vnames as $vname => $desc) { - $fieldname = 'taxonomy_apk_' . $vname; - $machinename = 'apk_' . $vname; - $vedit = array( - 'name' => $desc, - 'description' => $t('@desc taxonomy', array('@desc' => $desc)), - 'machine_name' => $machinename - ); - if (taxonomy_vocabulary_save((object) $vedit)) { - if (!field_info_field($fieldname)) { - $field = array( - 'field_name' => $fieldname, - 'type' => 'taxonomy_term_reference', - //sets the number of terms which can be selected - 'cardinality' => '1', - 'settings' => array( - 'allowed_values' => array( - array( - 'vocabulary' => $machinename, - 'parent' => 0, - ), - ), - ), - ); - field_create_field($field); - } - if (!field_info_instance('node', $fieldname, 'taxonomy_term_reference')) { - $instance = array( - 'field_name' => $fieldname, - 'entity_type' => 'node', - 'label' => $desc, - 'bundle' => 'apk', - 'required' => TRUE, - 'widget' => array( - 'type' => 'options_select', - ) - ); - field_create_instance($instance); - } - } - } -} - -//cleanup database, removing all apk entries -function apk_browser_uninstall() { - $nfields = array_keys(_apk_browser_field_vars()); - /* delete all apk nodes. - * disabled because too slow - * $nodes = db_select('node') - * ->fields('node', array('nid')) - * ->condition('type', 'apk') - * ->execute() - * ->fetchAll(); - * foreach ($nodes as $node) { - * node_delete($node->nid); - * } - */ - //delete the content type - node_type_delete('apk'); - //delete the apk node fields - foreach ($nfields as $nfield) { - field_delete_field($nfield); - } - //delete all apk related instaces - $instances = field_info_instances('node', 'apk'); - foreach ($instances as $instance) { - field_delete_instance($instance, TRUE); - } - field_delete_field('taxonomy_apk_repo'); - field_delete_field('taxonomy_apk_arch'); - //delete taxonomy - $vocabulary = taxonomy_vocabulary_machine_name_load('apk_arch'); - if ($vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); - } - $vocabulary = taxonomy_vocabulary_machine_name_load('apk_repo'); - if ($vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); - } - db_delete('variable')->condition('name', 'apk_%%', 'LIKE')->execute(); -} - -/* - * functions which return apk browser - * structure and variables will be used - * for install and uninstall - */ - -function _apk_browser_field_vars() { - $t = get_t(); - //return array of fields variables - return array( -/* - * use node title as package name - 'apk_name' => array( - 'label' => $t('Package'), - 'length' => '255' - ), - */ - 'apk_checksum' => array( - 'label' => $t('Checksum'), - 'length' => '255' - ), - 'apk_version' => array( - 'label' => $t('Version'), - 'length' => '255' - ), - 'apk_size' => array( - 'label' => $t('Size'), - 'length' => '255' - ), - 'apk_isize' => array( - 'label' => $t('Installed size'), - 'length' => '255' - ), - 'apk_description' => array( - 'label' => $t('Description'), - 'length' => '1000' - ), - 'apk_url' => array( - 'label' => $t('URL'), - 'length' => '255' - ), - 'apk_license' => array( - 'label' => $t('License'), - 'length' => '255' - ), - 'apk_depends' => array( - 'label' => $t('Dependencies'), - 'length' => '255' - ) - ); -} + 'apk', //machine name + 'name' => 'Alpine package', // human name + 'base' => 'node_content', //api callback + 'description' => $t('Content type to store Alpine Linux packages'), + 'title_label' => $t('Package'), + ); + //set missing defaults and save the node type + $content_type = node_type_set_defaults($node_fields); + node_type_save($content_type); + + /* + * Create all the fields and instances we are adding to our content type. + */ + foreach (_apk_browser_field_vars() as $name => $fvars) { + if (!field_info_field($name)) { + $field = array( + 'field_name' => $name, + 'cardinality' => (isset($fvars['cdl'])) ? $fvars['cdl'] : '1', + 'type' => (isset($fvars['type'])) ? $fvars['type'] : 'text', + 'settings' => array( + 'max_length' => (isset($fvars['length'])) ? $fvars['length'] : '255', + ), + ); + field_create_field($field); + } + // now all instances + if (!field_info_instance('node', $name, 'apk')) { + $instance = array( + 'field_name' => $name, + 'label' => $fvars['label'], + 'type' => 'text', + 'entity_type' => 'node', + 'bundle' => 'apk', + 'widget' => array( + 'type' => (isset($fvars['widget'])) ? $fvars['widget'] : 'text_textfield', + ), + 'display' => array( + 'default' => array( + 'label' => 'inline' + ) + ) + ); + field_create_instance($instance); + } + } + + /* + * Create taxonamy vocab + * create table and asign it + */ + $vnames = array( + 'repo' => $t('Repository'), + 'arch' => $t('Architecture') + ); + foreach ($vnames as $vname => $desc) { + $fieldname = 'taxonomy_apk_' . $vname; + $machinename = 'apk_' . $vname; + $vedit = array( + 'name' => $desc, + 'description' => $t('@desc taxonomy', array('@desc' => $desc)), + 'machine_name' => $machinename + ); + if (taxonomy_vocabulary_save((object) $vedit)) { + if (!field_info_field($fieldname)) { + $field = array( + 'field_name' => $fieldname, + 'type' => 'taxonomy_term_reference', + //sets the number of terms which can be selected + 'cardinality' => '1', + 'settings' => array( + 'allowed_values' => array( + array( + 'vocabulary' => $machinename, + 'parent' => 0, + ), + ), + ), + ); + field_create_field($field); + } + if (!field_info_instance('node', $fieldname, 'taxonomy_term_reference')) { + $instance = array( + 'field_name' => $fieldname, + 'entity_type' => 'node', + 'label' => $desc, + 'bundle' => 'apk', + 'required' => TRUE, + 'widget' => array( + 'type' => 'options_select', + ) + ); + field_create_instance($instance); + } + } + } +} + +//cleanup database, removing all apk entries +function apk_browser_uninstall() { + $nfields = array_keys(_apk_browser_field_vars()); + //delete the content type + node_type_delete('apk'); + //delete the apk node fields + foreach ($nfields as $nfield) { + field_delete_field($nfield); + } + //delete all apk related instaces + $instances = field_info_instances('node', 'apk'); + foreach ($instances as $instance) { + field_delete_instance($instance, TRUE); + } + field_delete_field('taxonomy_apk_repo'); + field_delete_field('taxonomy_apk_arch'); + //delete taxonomy + $vocabulary = taxonomy_vocabulary_machine_name_load('apk_arch'); + if ($vocabulary) { + taxonomy_vocabulary_delete($vocabulary->vid); + } + $vocabulary = taxonomy_vocabulary_machine_name_load('apk_repo'); + if ($vocabulary) { + taxonomy_vocabulary_delete($vocabulary->vid); + } + db_delete('variable')->condition('name', 'apk_%%', 'LIKE')->execute(); +} + +/* + * functions which return apk browser + * structure and variables will be used + * for install and uninstall + */ + +function _apk_browser_field_vars() { + $t = get_t(); + //return array of fields variables + return array( + 'apk_checksum' => array( + 'label' => $t('Checksum') + ), + 'apk_version' => array( + 'label' => $t('Version') + ), + 'apk_size' => array( + 'label' => $t('Size') + ), + 'apk_isize' => array( + 'label' => $t('Installed size') + ), + 'apk_description' => array( + 'label' => $t('Description'), + 'length' => '1000' + ), + 'apk_url' => array( + 'label' => $t('URL'), + ), + 'apk_license' => array( + 'label' => $t('License') + ), + 'apk_depends' => array( + 'label' => $t('Dependencies'), + 'cdl' => '-1' + ), + 'apk_maintainer' => array( + 'label' => $t('Maintainer'), + 'type' => 'user_reference', + 'widget' => 'options_select' + ), + 'apk_contributor' => array( + 'label' => $t('Contributor'), + 'type' => 'user_reference', + 'widget' => 'user_reference_autocomplete', + 'cdl' => '-1' + ) + ); +} -- cgit v1.2.3