You are here

function simpleads_update_7001 in SimpleAds 7

Add new fields to store Text and Flash ads. Make Image Ad field to not required.

File

./simpleads.updates.inc, line 12
SimpleAds Updates.

Code

function simpleads_update_7001(&$sandbox) {
  $t = get_t();
  $fields = array(
    array(
      'field_name' => 'field_ad_flash',
      'type' => 'file',
      'cardinality' => 1,
      'translatable' => TRUE,
      'locked' => FALSE,
      'indexes' => array(
        'fid' => array(
          'fid',
        ),
      ),
      'settings' => array(
        'uri_scheme' => 'public',
        'default_image' => FALSE,
      ),
      'storage' => array(
        'type' => 'field_sql_storage',
        'settings' => array(),
      ),
    ),
  );
  foreach ($fields as $field) {
    field_create_field($field);
  }
  $instance = array(
    'field_name' => 'field_ad_flash',
    'entity_type' => 'node',
    'label' => $t('Flash Ad'),
    'bundle' => 'simpleads',
    'description' => $t('Upload Flash file for this Ad.'),
    'required' => FALSE,
    'settings' => array(
      'file_directory' => 'field/flash',
      'file_extensions' => 'swf',
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'alt_field' => FALSE,
      'title_field' => '',
    ),
    'widget' => array(
      'type' => 'file_generic',
      'settings' => array(),
      'weight' => 0,
    ),
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'file_default',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'file_default',
        'weight' => -1,
      ),
    ),
  );
  field_create_instance($instance);
  $instance = array(
    'field_name' => 'field_ad_image',
    'entity_type' => 'node',
    'label' => $t('Ad Image'),
    'bundle' => 'simpleads',
    'description' => $t('Upload an image for this Ad.'),
    'required' => FALSE,
    'settings' => array(
      'file_directory' => 'field/image',
      'file_extensions' => 'png gif jpg jpeg',
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'alt_field' => TRUE,
      'title_field' => '',
    ),
    'widget' => array(
      'type' => 'image_image',
      'settings' => array(
        'progress_indicator' => 'throbber',
        'preview_image_style' => 'thumbnail',
      ),
      'weight' => -2,
    ),
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array(
          'image_style' => 'large',
          'image_link' => '',
        ),
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array(
          'image_style' => 'medium',
          'image_link' => 'content',
        ),
        'weight' => -1,
      ),
    ),
  );
  field_update_instance($instance);
  $instance = array(
    'field_name' => 'field_ad_category',
    'entity_type' => 'node',
    'label' => $t('Ad Group'),
    'bundle' => 'simpleads',
    'required' => TRUE,
    'widget' => array(
      'type' => 'options_select',
      'weight' => -4,
    ),
    'display' => array(
      'default' => array(
        'type' => 'hidden',
      ),
      'teaser' => array(
        'type' => 'hidden',
      ),
    ),
  );
  field_update_instance($instance);
  $fields = array(
    array(
      'field_name' => 'field_ad_text',
      'type' => 'text',
      'cardinality' => 1,
      'translatable' => TRUE,
      'locked' => FALSE,
      'settings' => array(),
      'storage' => array(
        'type' => 'field_sql_storage',
        'settings' => array(),
      ),
    ),
  );
  foreach ($fields as $field) {
    field_create_field($field);
  }
  $instance = array(
    'field_name' => 'field_ad_text',
    'entity_type' => 'node',
    'label' => $t('Text Ad'),
    'bundle' => 'simpleads',
    'description' => $t('Enter your text ad. If you would like to embed media, please configure WYSIWYG editor and input format settings.'),
    'required' => FALSE,
    'settings' => array(
      'rows' => 5,
      'text_processing' => 1,
    ),
    'widget' => array(
      'type' => 'text_textarea',
      'settings' => array(),
      'weight' => 1,
      'module' => 'text',
    ),
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'text_default',
        'weight' => -1,
        'module' => 'text',
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'text_default',
        'weight' => -1,
      ),
    ),
  );
  field_create_instance($instance);
  $fields = array(
    array(
      'field_name' => 'field_ad_type',
      'type' => 'list_text',
      'cardinality' => 1,
      'translatable' => TRUE,
      'locked' => FALSE,
      'module' => 'list',
      'settings' => array(
        'allowed_values' => array(
          'graphic' => $t('Image Ad'),
          'text' => $t('Text Ad'),
          'flash' => $t('Flash Ad'),
        ),
        'allowed_values_function' => '',
      ),
      'storage' => array(
        'type' => 'field_sql_storage',
        'settings' => array(),
      ),
    ),
  );
  foreach ($fields as $field) {
    field_create_field($field);
  }
  $instance = array(
    'field_name' => 'field_ad_type',
    'entity_type' => 'node',
    'label' => $t('Ad Type'),
    'bundle' => 'simpleads',
    'description' => $t('Please select Ad type.'),
    'required' => TRUE,
    'default_value' => array(
      0 => array(
        'value' => 'graphic',
      ),
    ),
    'settings' => array(
      'allowed_values' => array(
        'graphic' => $t('Image Ad'),
        'text' => $t('Text Ad'),
        'flash' => $t('Flash Ad'),
      ),
      'user_register_form' => FALSE,
    ),
    'user_register_form' => FALSE,
    'widget' => array(
      'active' => 1,
      'type' => 'options_select',
      'weight' => -3,
      'module' => 'list',
    ),
    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'list_default',
        'module' => 'list',
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'list_default',
        'module' => 'list',
        'weight' => -1,
      ),
    ),
  );
  field_create_instance($instance);
}