<?php

/**
 * @file
 * Module install logic.
 */

/**
 * Implements hook_install().
 */
function opigno_og_prereq_install() {
  $field = field_info_field('course_required_course_ref');
  if (empty($field)) {
    field_create_field(array(
      'active' => 1,
      'cardinality' => 1,
      'deleted' => 0,
      'entity_types' => array(),
      'field_name' => 'course_required_course_ref',
      'foreign keys' => array(
        'node' => array(
          'columns' => array(
            'target_id' => 'nid',
          ),
          'table' => 'node',
        ),
      ),
      'indexes' => array(
        'target_id' => array(
          0 => 'target_id',
        ),
      ),
      'locked' => 0,
      'module' => 'entityreference',
      'settings' => array(
        'handler' => 'base',
        'handler_settings' => array(
          'behaviors' => array(
            'views-select-list' => array(
              'status' => 0,
            ),
          ),
          'sort' => array(
            'type' => 'none',
          ),
          'target_bundles' => array(
            'course' => 'course',
          ),
        ),
        'target_type' => 'node',
      ),
      'translatable' => 1,
      'type' => 'entityreference',
    ));
  }

  $instance = field_info_instance('node', 'course_required_course_ref', OPIGNO_COURSE_BUNDLE);
  if (empty($instance)) {
    field_create_instance(array(
      'field_name' => 'course_required_course_ref',
      'entity_type' => 'node',
      'bundle' => OPIGNO_COURSE_BUNDLE,
      'label' => "Required course",
      'description' => "Makes this course dependent on another one.",
      'required' => FALSE,
    ));
  }
}