You are here

function opigno_add_image_fields in Opigno 7

1 call to opigno_add_image_fields()
opigno_install in ./opigno.install
Implements hook_install().

File

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

Code

function opigno_add_image_fields() {
  $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' => '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,
        ),
      ));
    }

    // Set default image
    $source_dir = drupal_get_path('module', 'opigno') . '/img';
    $filename = 'opigno_course_default.jpg';
    $source = $source_dir . '/' . $filename;
    $field = field_info_field('opigno_course_image');
    opigno_content_set_default_image($field, $filename, $source);
  }
}