You are here

party_starterkit_b2b.install in Party 8.2

Same filename and directory in other branches
  1. 7 starterkits/party_starterkit_b2b/party_starterkit_b2b.install

Party Starterkit B2B install file

File

starterkits/party_starterkit_b2b/party_starterkit_b2b.install
View source
<?php

/**
 * @file
 * Party Starterkit B2B install file
 */

/**
 * Implements hook_install().
 */
function party_starterkit_b2b_install() {

  // Create the taxonomy vocabulary
  $vocab = array(
    'name' => 'Organization Types',
    'machine_name' => 'party_org_types',
    'hierarchy' => 'single',
    'module' => 'party_starterkit_b2b',
  );
  $vocab = taxonomy_vocabulary_save((object) $vocab);
  party_starterkit_b2b_install_terms();

  // Create the relation types
  $employee_relation = relation_type_create(array(
    'relation_type' => 'employee',
    'label' => 'Employee of',
    'reverse_label' => 'Employs',
    'directional' => TRUE,
    'source_bundles' => array(
      'party:party',
    ),
    'target_bundles' => array(
      'party:party',
    ),
  ));
  relation_type_save($employee_relation);
  field_helper_install_all('party_starterkit_b2b');
}

/**
 * Implements hook_uninstall().
 */
function party_starterkit_b2b_uninstall() {
  field_helper_uninstall_all('party_starterkit_b2b');
  party_starterkit_b2b_uninstall_terms();
  $vocabulary = taxonomy_vocabulary_machine_name_load('party_org_types');
  taxonomy_vocabulary_delete($vocabulary->vid);
  relation_type_delete('employee');
}

/**
 * Implements hook_install_fields().
 *
 * @see field_helper module
 */
function party_starterkit_b2b_install_fields() {
  $fields = array();

  // Organization name field
  $fields['party_org_name'] = array(
    'field_name' => 'party_org_name',
    'type' => 'text',
    'cardinality' => 1,
  );

  // Organization link field
  $fields['party_org_web'] = array(
    'field_name' => 'party_org_web',
    'type' => 'link_field',
    'cardinality' => 1,
  );

  // Organization email field
  $fields['party_org_email'] = array(
    'field_name' => 'party_org_email',
    'type' => 'email',
    'cardinality' => 1,
  );

  // Organization address
  $fields['party_org_address'] = array(
    'field_name' => 'party_org_address',
    'type' => 'addressfield',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  );

  // Organization phone
  $fields['party_org_phone'] = array(
    'field_name' => 'party_org_phone',
    'type' => 'phone',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'country' => 'ca',
    ),
  );

  // Organization type
  $fields['party_org_type'] = array(
    'field_name' => 'party_org_type',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        0 => array(
          'vocabulary' => 'party_org_types',
          'parent' => '0',
        ),
      ),
    ),
  );

  // Contact name field
  $fields['party_contact_name'] = array(
    'field_name' => 'party_contact_name',
    'type' => 'name',
    'cardinality' => 1,
    'settings' => array(
      'components' => array(
        'title' => 'title',
        'given' => 'given',
        'middle' => 'middle',
        'family' => 'family',
        'generational' => FALSE,
        'credentials' => 'credentials',
      ),
      'labels' => array(
        'title' => 'Title',
        'given' => 'First Name',
        'middle' => 'Middle Name(s)',
        'family' => 'Last Name',
        'generational' => 'Generational',
        'credentials' => 'Credentials',
      ),
    ),
  );

  // Contact email field
  $fields['party_contact_email'] = array(
    'field_name' => 'party_contact_email',
    'type' => 'email',
    'cardinality' => 1,
  );

  // Contact address
  $fields['party_contact_address'] = array(
    'field_name' => 'party_contact_address',
    'type' => 'addressfield',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  );

  // Contact phone
  $fields['party_contact_phone'] = array(
    'field_name' => 'party_contact_phone',
    'type' => 'phone',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'country' => 'ca',
    ),
  );

  // Notes notes
  $fields['party_notes_notes'] = array(
    'field_name' => 'party_notes_notes',
    'type' => 'text_long',
    'cardinality' => 1,
  );
  return $fields;
}

/**
 * Implements hook_install_instances().
 */
function party_starterkit_b2b_install_instances() {
  $t = get_t();
  $instances = array();
  $instances['party_org_name'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_name',
    'label' => $t('Name'),
    'description' => $t('The name of this organization.'),
    'widget' => array(
      'type' => 'text_textfield',
    ),
  );
  $instances['party_org_web'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_web',
    'label' => $t('Website'),
    'description' => $t("The organization's website."),
    'settings' => array(
      'title' => 'none',
    ),
    'widget' => array(
      'type' => 'link_field',
    ),
  );
  $instances['party_org_email'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_email',
    'label' => $t('Email'),
    'description' => $t("The organization's email address."),
    'widget' => array(
      'type' => 'email_textfield',
    ),
  );
  $instances['party_org_address'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_address',
    'label' => $t('Address'),
    'description' => $t("The organization's address."),
    'widget' => array(
      'type' => 'addressfield_standard',
      'settings' => array(
        'format_handlers' => array(
          'address_hide_country' => 'address_hide_country',
        ),
      ),
    ),
  );
  $instances['party_org_phone'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_phone',
    'label' => $t('Phone Number'),
    'settings' => array(
      'ca_phone_parentheses' => 0,
    ),
    'widget' => array(
      'type' => 'phone_textfield',
    ),
  );
  $instances['party_org_type'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_org',
    'field_name' => 'party_org_type',
    'label' => $t('Organization Type'),
    'widget' => array(
      'type' => 'options_select',
    ),
  );
  $instances['party_contact_name'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_contact',
    'field_name' => 'party_contact_name',
    'label' => $t('Name'),
    'description' => $t('The name of this contact.'),
    'widget' => array(
      'type' => 'name_widget',
    ),
  );
  $instances['party_contact_email'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_contact',
    'field_name' => 'party_contact_email',
    'label' => $t('Email'),
    'description' => $t("The contact's email address."),
    'widget' => array(
      'type' => 'email_textfield',
    ),
  );
  $instances['party_contact_address'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_contact',
    'field_name' => 'party_contact_address',
    'label' => $t('Address'),
    'description' => $t("The contact's address."),
    'widget' => array(
      'type' => 'addressfield_standard',
      'settings' => array(
        'format_handlers' => array(
          'address_hide_country' => 'address_hide_country',
        ),
      ),
    ),
  );
  $instances['party_contact_phone'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_contact',
    'field_name' => 'party_contact_phone',
    'label' => $t('Phone Number'),
    'settings' => array(
      'ca_phone_parentheses' => 0,
    ),
    'widget' => array(
      'type' => 'phone_textfield',
    ),
  );
  $instances['party_notes_notes'] = array(
    'entity_type' => 'profile2',
    'bundle' => 'party_notes',
    'field_name' => 'party_notes_notes',
    'label' => $t('Notes'),
    'settings' => array(
      'text_processing' => 0,
    ),
    'widget' => array(
      'type' => 'text_textarea',
      'settings' => array(
        'rows' => 5,
      ),
    ),
  );
  return $instances;
}

/**
 * Create some taxonomy terms for the org type vocabulary.
 */
function party_starterkit_b2b_install_terms() {
  $vocabulary = taxonomy_vocabulary_machine_name_load('party_org_types');
  $term = array(
    'vid' => $vocabulary->vid,
    'name' => 'Customer',
    'vocabulary_machine_name' => $vocabulary->machine_name,
  );
  taxonomy_term_save((object) $term);
  $term = array(
    'vid' => $vocabulary->vid,
    'name' => 'Prospect',
    'vocabulary_machine_name' => $vocabulary->machine_name,
  );
  taxonomy_term_save((object) $term);
  $term = array(
    'vid' => $vocabulary->vid,
    'name' => 'Vendor',
    'vocabulary_machine_name' => $vocabulary->machine_name,
  );
  taxonomy_term_save((object) $term);
}

/**
 * Uninstall the terms we made on install.
 */
function party_starterkit_b2b_uninstall_terms() {
  $vocabulary = taxonomy_vocabulary_machine_name_load('party_org_types');
  $terms = taxonomy_term_load_multiple(array(), array(
    'vid' => $vocabulary->vid,
  ));
  foreach ($terms as $term) {
    taxonomy_term_delete($term->tid);
  }
}

Functions

Namesort descending Description
party_starterkit_b2b_install Implements hook_install().
party_starterkit_b2b_install_fields Implements hook_install_fields().
party_starterkit_b2b_install_instances Implements hook_install_instances().
party_starterkit_b2b_install_terms Create some taxonomy terms for the org type vocabulary.
party_starterkit_b2b_uninstall Implements hook_uninstall().
party_starterkit_b2b_uninstall_terms Uninstall the terms we made on install.