function media_library_modal_add in Media Library 6
Second step in the modal dialog, for generating the multi-step form.
Parameters
type - media type name: update - TRUE if updating an object
2 calls to media_library_modal_add()
- media_library_modal in ./
media_library.modal.inc - Main modal frame
- media_library_types_choice in ./
media_library.modal.inc - Renders the list of Types to be selected prior to inserting media.
1 string reference to 'media_library_modal_add'
- media_library_menu in ./
media_library.module - Implementation of hook_menu()
File
- ./
media_library.modal.inc, line 79 - Modal frame functions
Code
function media_library_modal_add($type) {
ctools_include('modal');
ctools_include('ajax');
ctools_include('wizard');
ctools_include('object-cache');
// Let's get our step
$step = arg(4);
// Loads our object from cache.
$object = media_library_get_cache('media_obj');
$object->type = $type;
ctools_object_cache_set('media_library', 'media_obj', $object);
// Get our type info
$types = media_library_get_types();
if (!isset($types[$type])) {
ctools_modal_render(t('Error'), t('Specified type does not exist: ' . $type));
}
$module = $types[$type]['module'];
// Call the hook to get the steps list.
$steps = module_invoke($module, 'media_forms', $type);
if (empty($step)) {
$step = key($steps);
}
$order = array();
foreach ($steps as $step_name => &$info) {
$order[$step_name] = $info['label'];
$info['title'] = $info['label'];
unset($steps[$step_name]['label']);
}
$forms = $steps;
/**
* This is the CTools Wizard form setting
* Check CTools Advanced Help on topic Wizard for documentation
*/
$form_info = array(
'id' => 'media-library',
'path' => "media-library/main/add/{$type}/%step",
'title' => t('Insert !media', array(
'!media' => $types[$type]['title'],
)),
'show trail' => FALSE,
'show back' => FALSE,
'show cancel' => TRUE,
'show return' => FALSE,
'next text' => t('Next'),
'next callback' => 'media_library_modal_next',
'finish callback' => 'media_library_modal_finish',
'return callback' => 'media_library_modal_cancel',
'cancel callback' => 'media_library_modal_cancel',
'order' => $order,
'forms' => $forms,
);
$form_state = array(
'cache name' => 'media_obj',
'ajax' => TRUE,
'modal' => TRUE,
);
// Our object is to be saved here...
$form_state['media_obj'] = $object;
// Set default values when editing
foreach ($form_state['media_obj'] as $attr => $value) {
if ($attr == 'action') {
$form_state['action'] = $value;
}
else {
$form_state['update'][$attr] = $value;
}
}
ctools_wizard_multistep_form($form_info, $step, $form_state);
}