function image_legacy_field_convert_info in Image 7
Implement hook_field_convert_info().
Return an array describing field migration plans.
Assumptions this plan makes:
- core upgrade will have converted the {files} table and its entries to a {file_managed} table. In particular: the 'filename' column is now 'uri', and its value changed thus: s[sites/default][public://]
File
- ./
image_legacy.field_convert.inc, line 12
Code
function image_legacy_field_convert_info() {
/*
TODO:
- create a normal node type
- convert image derivatives to image styles.
- clean up original {file_managed} entries
- delete non-original files and {file_managed} entries
*/
// Get the maximum upload dimensions from image_legacy module to set on the new field.
$sizes = image_get_sizes();
$max_width = $sizes['_original']['width'];
$max_height = $sizes['_original']['height'];
if (is_numeric($max_width) && is_numeric($max_height)) {
$max_resolution = $max_width . 'x' . $max_height;
}
else {
$max_resolution = '';
}
return array(
'image_d6' => array(
// Basics about this field migration plan
'title' => t('Image'),
'description' => t('Image module conversion to image field.'),
// Required modules
'dependencies' => array(
'image',
),
'files' => array(
// array of files to include
__FILE__,
),
// The entity type that this plan operates on, eg 'node', 'user', 'comment'.
// Further information about this entity type will be retrieved from hook_entity_info().
'entity_type' => 'node',
// How to determine if this plan has run or not.
'has_run' => array(
// Simple form: give the name of a table which exists if the plan has not run yet
// (and therefore which the plan should rename as part of its work).
'table_exists' => 'image',
),
// We need to create a node type.
'bundles' => array(
'image' => array(
'status' => 'create',
// can be one of:
// - 'create' -- TODO
// - 'convert' -- for modules that used hook_node_info() on D6.
'type' => 'image',
'name' => 'Image',
'description' => 'An image (with thumbnail). This is ideal for publishing photographs or screenshots.',
),
),
// The fields we will need to create or use.
// An array of one or more fields and instances, keyed by whatever you like
// (field name is nice though).
'fields' => array(
'node_image' => array(
// Whether we need to create a new field and instances or not.
// one of:
// - create // create the field and instances
// - create instance // the field exists; create one or more instances of it
// - exists // the field and instance already exist. @TODO: add support for this!
'status' => 'create',
// Information about the field to create.
// This is a standard FieldAPI array suitable for passing to field_create_field().
// @see <http://drupal.org/node/474420>.
// Some useful information: $field_type_options = field_ui_field_type_options();
'field' => array(
'field_name' => 'node_image',
'type' => 'image',
'cardinality' => 1,
// single value
'settings' => array(
'required' => TRUE,
'file_directory' => variable_get('image_default_path', 'images'),
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => variable_get('image_max_upload_size', 800) . 'k',
// Image module stores an integer representing kilobytes.
'max_resolution' => $max_resolution,
'min_resolution' => '',
),
),
// FieldAPI instances arrays.
// An array of one or more instances of this field, keyed by whatever you like.
'instances' => array(
// This is a standard FieldAPI array suitable for passing to field_create_instance()
// although the 'object_type' and 'field_name' keys are filled in for you.
// Some useful information: include_once('modules/field_ui/field_ui.admin.inc'); $widget_type_options = field_ui_widget_type_options(NULL, TRUE); dsm($widget_type_options);
'all' => array(
'label' => t('Image'),
'description' => t('Select an image to upload.'),
'bundle' => 'image',
'widget' => array(
'type' => 'image_image',
'module' => 'image',
'weight' => -1,
'settings' => array(
'progress_indicator' => 'throbber',
'preview_image_style' => 'thumbnail',
),
),
),
),
),
),
// How to get all the objects we need to operate on
'list' => array(
'query_method' => 'dynamic',
// DBTNG baby! todo: support static queries too?
'query' => array(
// this is an array of stuff to build the query object with
// we'll use the standard abbreviation of the first letter of this!
'conditions' => array(
// arrays of parameters suitable for passing to the $query as conditions
// each array here is passed as $query->([the array])
array(
'n.type',
'image',
'=',
),
),
),
),
// How to load each object we manipulate.
// @todo: we can maybe omit this entire section and just assume the entity_load() function?
'load' => array(
'load_method' => 'entity',
),
// How to manipulate each object: take values from one property and put them in another.
'manipulate' => array(
// hook_field_convert_load() is called on each object.
'property_conversions' => array(
array(
'images_image_original' => 'node_image',
),
),
),
// How to save the entity once we are done.
'save' => 'node_save',
),
);
}