You are here

function opigno_update_7101 in Opigno 7

Enable the course image field

File

./opigno.install, line 87
Contains install instructions and logic

Code

function opigno_update_7101() {
  $type = node_type_load(OPIGNO_COURSE_BUNDLE);
  if (!empty($type)) {
    $field = field_info_field('opigno_course_image');
    if (empty($field)) {
      field_create_field(array(
        'active' => 1,
        'cardinality' => 1,
        'deleted' => 0,
        'entity_types' => array(),
        'field_name' => 'opigno_course_image',
        'foreign keys' => array(
          'fid' => array(
            'columns' => array(
              'fid' => 'fid',
            ),
            'table' => 'file_managed',
          ),
        ),
        'indexes' => array(
          'fid' => array(
            0 => 'fid',
          ),
        ),
        'locked' => 0,
        'module' => 'image',
        'settings' => array(
          'default_image' => 47,
          'uri_scheme' => 'public',
        ),
        'translatable' => 0,
        'type' => 'image',
      ));
    }
    $instance = field_info_instance('node', 'opigno_course_image', 'course');
    if (empty($instance)) {
      field_create_instance(array(
        'bundle' => 'course',
        'deleted' => 0,
        'description' => '',
        'display' => array(
          'default' => array(
            'label' => 'above',
            'module' => 'image',
            'settings' => array(
              'image_link' => '',
              'image_style' => 'thumbnail',
            ),
            'type' => 'image',
            'weight' => 19,
          ),
          'teaser' => array(
            'label' => 'above',
            'settings' => array(),
            'type' => 'hidden',
            'weight' => 0,
          ),
        ),
        'entity_type' => 'node',
        'field_name' => 'opigno_course_image',
        'label' => 'course_image',
        'required' => 0,
        'settings' => array(
          'alt_field' => 0,
          'default_image' => 0,
          'file_directory' => '',
          'file_extensions' => 'png gif jpg jpeg',
          'max_filesize' => '',
          'max_resolution' => '',
          'min_resolution' => '',
          'title_field' => 0,
          'user_register_form' => FALSE,
        ),
        'widget' => array(
          'active' => 1,
          'module' => 'image',
          'settings' => array(
            'preview_image_style' => 'apps_logo_small',
            'progress_indicator' => 'throbber',
          ),
          'type' => 'image_image',
          'weight' => 42,
        ),
      ));
    }
    $source_dir = drupal_get_path('profile', 'opigno_lms') . "/img";
    $filename = "opigno_lms.png";
    $source = $source_dir . '/' . $filename;
    $destination = $filename;
    $field = field_info_field('opigno_course_image');
    opigno_content_set_default_image($field, $filename, $source, $destination);
  }
}