You are here

function quiz_drag_drop_install in Quiz Drag Drop 7

Implements hook_install().

File

./quiz_drag_drop.install, line 11
drag drop Install (a quiz question type)

Code

function quiz_drag_drop_install() {

  // Add body field to multichoice node.
  quiz_question_add_body_field('quiz_drag_drop');
  cache_clear_all('autoload:', 'cache');

  // At this point quiz core has created the drag drop node type.
  // Now it's time to add the image field to the node:
  if (!field_info_field('field_dragdrop_image')) {
    $field = array(
      'field_name' => 'field_dragdrop_image',
      'type' => 'image',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }
  $instance = field_info_instance('node', 'field_dragdrop_image', 'quiz_drag_drop');
  if (empty($instance)) {
    $t = get_t();
    $help_text = $t("<p>Upload images for drag drop question. Give each image a title.</p>\n                       <p><em>This image title will appear in placeholder box. So make sure title is not more than 18 characters.\n                       Otherwise it will be trimmed to 18 characters.</em></p>");
    $instance = array(
      'field_name' => 'field_dragdrop_image',
      'entity_type' => 'node',
      'bundle' => 'quiz_drag_drop',
      'label' => 'Quiz image',
      'description' => $help_text,
      'required' => TRUE,
      'settings' => array(
        'no_ui' => FALSE,
        'title_field' => TRUE,
      ),
      'widget' => array(
        'settings' => array(
          'no_ui' => FALSE,
          'max_filesize' => '1M',
          'preview_image_style' => 'thumbnail',
        ),
      ),
    );
    field_create_instance($instance);
  }
}