You are here

asset_gallery.install in Asset 7

Install, update, and uninstall functions for the Asset gallery module.

File

modules/asset_gallery/asset_gallery.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Asset gallery module.
 */

/**
 * Implements hook_install().
 */
function asset_gallery_install() {
  field_info_cache_clear();
  $fields = array();

  // Exported field: 'asset-gallery-field_asset_gallery_desc'.
  $fields['asset-gallery-field_asset_gallery_desc'] = array(
    'field_config' => array(
      'active' => '1',
      'cardinality' => '1',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_asset_gallery_desc',
      'foreign keys' => array(
        'format' => array(
          'columns' => array(
            'format' => 'format',
          ),
          'table' => 'filter_format',
        ),
      ),
      'indexes' => array(
        'format' => array(
          0 => 'format',
        ),
      ),
      'locked' => '0',
      'module' => 'text',
      'settings' => array(),
      'translatable' => '0',
      'type' => 'text_long',
    ),
    'field_instance' => array(
      'bundle' => 'gallery',
      'default_value' => NULL,
      'deleted' => '0',
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'module' => 'text',
          'settings' => array(),
          'type' => 'text_default',
          'weight' => '1',
        ),
        'full' => array(
          'label' => 'hidden',
          'module' => 'text',
          'settings' => array(),
          'type' => 'text_default',
          'weight' => '1',
        ),
        'tooltip' => array(
          'label' => 'hidden',
          'module' => 'text',
          'settings' => array(),
          'type' => 'text_default',
          'weight' => '0',
        ),
      ),
      'entity_type' => 'asset',
      'field_name' => 'field_asset_gallery_desc',
      'label' => 'Description',
      'required' => 0,
      'settings' => array(
        'text_processing' => '0',
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'active' => 1,
        'module' => 'text',
        'settings' => array(
          'rows' => '4',
        ),
        'type' => 'text_textarea',
        'weight' => '2',
      ),
    ),
  );

  // Exported field: 'asset-gallery-field_asset_gallery_images'.
  $fields['asset-gallery-field_asset_gallery_images'] = array(
    'field_config' => array(
      'active' => '1',
      'cardinality' => '5',
      'deleted' => '0',
      'entity_types' => array(),
      'field_name' => 'field_asset_gallery_images',
      'foreign keys' => array(
        'asset' => array(
          'columns' => array(
            'target_id' => 'aid',
          ),
          'table' => 'asset',
        ),
      ),
      '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(
            'direction' => 'ASC',
            'field' => 'field_asset_image:fid',
            'property' => 'aid',
            'type' => 'none',
          ),
          'target_bundles' => array(
            'image' => 'image',
          ),
        ),
        'handler_submit' => 'Change handler',
        'target_type' => 'asset',
      ),
      'translatable' => '0',
      'type' => 'entityreference',
    ),
    'field_instance' => array(
      'bundle' => 'gallery',
      'default_value' => NULL,
      'deleted' => '0',
      'description' => '',
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'module' => 'entityreference',
          'settings' => array(
            'view_mode' => 'gallery',
          ),
          'type' => 'entityreference_entity_view',
          'weight' => '0',
        ),
        'full' => array(
          'label' => 'hidden',
          'module' => 'entityreference',
          'settings' => array(
            'view_mode' => 'gallery',
          ),
          'type' => 'entityreference_entity_view',
          'weight' => '0',
        ),
        'tooltip' => array(
          'label' => 'hidden',
          'module' => 'entityreference',
          'settings' => array(
            'view_mode' => 'small',
          ),
          'type' => 'entityreference_entity_view',
          'weight' => '1',
        ),
      ),
      'entity_type' => 'asset',
      'field_name' => 'field_asset_gallery_images',
      'label' => 'Images',
      'required' => 1,
      'settings' => array(
        'user_register_form' => FALSE,
      ),
      'widget' => array(
        'active' => 1,
        'module' => 'entityreference',
        'settings' => array(
          'match_operator' => 'CONTAINS',
          'path' => '',
          'references_dialog_add' => 1,
          'references_dialog_edit' => 1,
          'references_dialog_search' => 1,
          'references_dialog_search_view' => '',
          'size' => '80',
        ),
        'type' => 'entityreference_autocomplete',
        'weight' => '1',
      ),
    ),
  );

  // Translatables
  // Included for use with string extractors like potx.
  $t = get_t();
  $t('Description');
  $t('Images');
  foreach ($fields as $field) {

    // Create or update field.
    $field_config = $field['field_config'];
    if ($existing_field = field_info_field($field_config['field_name'])) {
      field_update_field($field_config);
    }
    else {
      field_create_field($field_config);
    }

    // Create or update field instance.
    $field_instance = $field['field_instance'];
    $existing_instance = field_info_instance($field_instance['entity_type'], $field_instance['field_name'], $field_instance['bundle']);
    if ($existing_instance) {
      field_update_instance($field_instance);
    }
    else {
      field_create_instance($field_instance);
    }
    variable_set('menu_rebuild_needed', TRUE);
  }
  $bundle_settings = array(
    'view_modes' => array(
      'full' => array(
        'custom_settings' => TRUE,
      ),
      'small' => array(
        'custom_settings' => FALSE,
      ),
      'tooltip' => array(
        'custom_settings' => TRUE,
      ),
    ),
    'extra_fields' => array(
      'form' => array(
        'title' => array(
          'weight' => '0',
        ),
      ),
      'display' => array(),
    ),
  );
  field_bundle_settings('asset', 'gallery', $bundle_settings);
  assets_set_wysiwyg_modes('gallery', array(
    'full' => 'full',
  ));
  $bundle_settings = field_bundle_settings('asset', 'image');
  $bundle_settings['view_modes']['gallery'] = array(
    'custom_settings' => TRUE,
  );
  field_bundle_settings('asset', 'image', $bundle_settings);
  $instance = field_read_instance('asset', 'field_asset_image', 'image');
  $instance['display']['gallery'] = array(
    'label' => 'hidden',
    'type' => 'image',
    'weight' => 0,
    'settings' => array(
      'image_style' => 'asset_image_full',
      'image_link' => '',
    ),
    'module' => 'image',
  );
  field_update_instance($instance);
  $instance = field_read_instance('asset', 'field_asset_image_description', 'image');
  $instance['display']['gallery'] = array(
    'label' => 'hidden',
    'type' => 'text_default',
    'weight' => 1,
    'settings' => array(),
    'module' => 'text',
  );
  field_update_instance($instance);
  $instance = field_read_instance('asset', 'field_asset_image_copyright', 'image');
  $instance['display']['gallery'] = array(
    'label' => 'hidden',
    'type' => 'text_default',
    'weight' => 1,
    'settings' => array(),
    'module' => 'text',
  );
  field_update_instance($instance);
}

/**
 * Implements hook_uninstall().
 */
function asset_gallery_uninstall() {
  field_delete_field('field_asset_gallery_desc');
  field_delete_field('field_asset_gallery_images');
}

Functions