mediamosa_development_rest_form()The form to execute a REST call.
sites/all/modules/mediamosa_development/mediamosa_development.admin.inc, line 269
<?php
function mediamosa_development_rest_form() {
// Get session.
$session = isset($_SESSION['mediamosa_development_params']) ? $_SESSION['mediamosa_development_params'] : array();
drupal_add_css(drupal_get_path('module', 'mediamosa_development') . '/mediamosa_development.css');
// Get all the REST calls.
$rest_calls = module_invoke_all('mediamosa_register_rest_call');
$rest_call_options = array('' => 'Select Rest call');
foreach ($rest_calls as $uri => $rest_call) {
foreach ($rest_call as $method => $rest_call_data) {
$rest_call_options[$uri . '|' . $method] = $uri . ' [' . $method . ']';
}
}
ksort($rest_call_options);
$form = array();
$form['rest'] = array(
'#type' => 'fieldset',
'#title' => t('REST call'),
'#weight' => -10,
);
$apps = array();
if (module_exists('mediamosa_connector')) {
$apps[0] = t('Use MediaMosa Connector to connect');
}
$apps_2 = mediamosa_app::get_all_apps(array(mediamosa_app_db::APP_ID, mediamosa_app_db::APP_NAME), mediamosa_app_db::APP_ID, 'ASC')->fetchAllKeyed();
foreach ($apps_2 as $app_id => $app_name) {
$apps[$app_id] = strtr('@name (App ID @app_id)', array('@name' => $app_name, '@app_id' => $app_id));
}
if (empty($apps)) {
$form['rest']['client_application'] = array(
'#markup' => t('No client applications found or MediaMosa connector setup.'),
);
}
$form['rest']['client_application'] = array(
'#type' => 'select',
'#title' => 'REST call URI',
'#options' => $apps,
'#default_value' => '',
);
$mediamosa_development_mediamosa_17_rest_url = variable_get('mediamosa_development_mediamosa_17_rest_url', '');
if (!empty($mediamosa_development_mediamosa_17_rest_url)) {
$form['rest']['run_on_mm_17'] = array(
'#type' => 'checkbox',
'#title' => t('Run REST call on MediaMosa 1.7.x to compare output.'),
'#default_value' => 0,
);
}
if (empty($session['uri'])) {
$form['rest']['uri'] = array(
'#type' => 'select',
'#title' => 'REST call URI',
'#options' => $rest_call_options,
'#default_value' => '',
);
$form['rest']['submit'] = array(
'#type' => 'submit',
'#value' => t('Select'),
);
}
else {
list($uri, $method) = explode('|', $session['uri']);
// Get all the REST calls docs.
$rest_call_docs = module_invoke_all('mediamosa_register_rest_call_doc');
// Get the doc.
$rest_call_doc = isset($rest_call_docs[$uri][$method]) ? $rest_call_docs[$uri][$method] : array();
$descriptions = array(
!empty($rest_call_doc[mediamosa_rest_call::TITLE]) ? '<b>' . $rest_call_doc[mediamosa_rest_call::TITLE] . '</b>' : t('No title found'),
!empty($rest_call_doc[mediamosa_rest_call::DESCRIPTION]) ? $rest_call_doc[mediamosa_rest_call::DESCRIPTION] : t('No description found'),
'',
l(t('@uri [@method]', array('@uri' => $uri, '@method' => $method)), strtr('admin/mediamosa/browse/restcall/@uri/@method', array('@uri' => str_replace('/', '-', $uri), '@method' => $method))),
);
$form['rest']['description'] = array(
'#markup' => '<p>' . implode('<br />', $descriptions) . '</p>',
);
$form['rest']['clear'] = array(
'#type' => 'submit',
'#value' => t('Clear URI selection'),
);
$form['rest']['submit'] = array(
'#type' => 'submit',
'#value' => t('Execute @uri [@method]', array('@uri' => $uri, '@method' => $method)),
'#ajax' => array(
'event' => 'click',
'wrapper' => 'rest_call_output',
'path' => 'admin/mediamosa/config/development/js/restcall',
),
'#weight' => 10,
);
$form['rest_result'] = array(
'#type' => 'fieldset',
'#title' => t('REST Call output'),
'#weight' => 10,
'#prefix' => '<div id="rest_call_output">',
'#suffix' => '</div>',
);
$form['rest_result']['output'] = array(
'#type' => 'textarea',
'#title' => t('Output'),
'#default_value' => '',
);
$form['rest_result']['output_mm17'] = array(
'#type' => 'hidden',
'#title' => t('Output MediaMosa 1.7.x'),
'#default_value' => '',
);
$form['rest_result']['output_compare'] = array(
'#type' => 'hidden',
'#title' => t('Compare results'),
'#default_value' => '',
);
$form = _mediamosa_build_form($form);
}
return $form;
}
?>