You are here

function classified_install in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 classified.install \classified_install()

Implements hook_install().

File

./classified.install, line 32
Install file for the Classified Ads module.

Code

function classified_install() {
  $t = get_t();

  // Define default values.
  foreach (_classified_get_vars() as $name => $default) {
    variable_set($name, $default);
  }

  // Create module vocabulary.
  $vocabulary = (object) array(
    'module' => 'classified',
    'machine_name' => 'classified_categories',
    'name' => $t('Classified Ads categories'),
    'description' => $t('This vocabulary is the one used by the Classified Ads module to classify ads. Do not remove it: it is managed by the Classified Ads module, not by the taxonomy module.'),
    'help' => $t('This term will appear on Classified Ads pages'),
    'multiple' => 0,
    'required' => 1,
    'hierarchy' => 1,
    'relations' => 0,
    'weight' => -10,
    'nodes' => array(
      'classified' => 1,
    ),
  );
  taxonomy_vocabulary_save($vocabulary);
  $vid = $vocabulary->vid;
  variable_set('classified-vid', $vid);
  drupal_set_message($t('New vocabulary @vid created for Classified Ads', array(
    '@vid' => $vid,
  )));

  // Create terms in module vocabulary.
  $terms = array(
    $t('For sale'),
    $t('Wanted'),
  );
  foreach ($terms as $name) {
    $term = (object) array(
      'name' => $name,
      'vid' => $vid,
      'description' => '',
      'format' => filter_default_format(),
    );
    taxonomy_term_save($term);
  }
  drupal_set_message($t('@count default ad classifications inserted', array(
    '@count' => count($terms),
  )));

  // Create fields: a body and a category.
  // Start by getting up-to-date content type information.
  node_types_rebuild();
  $types = node_type_get_types();
  node_add_body_field($types['classified'], $t('Ad Body'));
  $field_name = _classified_get('field-category');
  $field = array(
    'field_name' => $field_name,
    'type' => 'taxonomy_term_reference',
    'cardinality' => 1,
    'translatable' => FALSE,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => '0',
        ),
      ),
    ),
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'node',
    'field_name' => $field_name,
    'bundle' => 'classified',
    'label' => 'Ad Category',
    'description' => 'The category of your Classified Ad',
    'required' => TRUE,
    'widget' => array(
      'type' => 'options_select',
      'weight' => 0,
    ),
  );
  field_create_instance($instance);

  // Adding the flush below causes Simpletest to fail outside the tests.
  // drupal_flush_all_caches();
}