View source
<?php
function views_deploy_menu() {
$items = array();
$plans = deploy_get_plans();
if (!empty($plans)) {
$items[] = array(
'path' => 'admin/build/views/deploy',
'title' => t('Deploy'),
'description' => t('Add a view to a deployment plan.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'views_deploy_add_form',
$plans,
),
'access' => user_access('add items to deployment plan'),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
function views_deploy_add_form($plans) {
$views = array();
$result = db_query("SELECT name FROM {view_view} ORDER BY name");
while ($view = db_fetch_array($result)) {
$views[$view['name']] = $view['name'];
}
$form['pid'] = array(
'#title' => t('Deployment Plan'),
'#type' => 'select',
'#options' => $plans,
'#description' => t('The deployment plan to add this view to'),
);
if (module_exists('hs_flatlist')) {
$form['view_name'] = array(
'#title' => t('View'),
'#type' => 'hierarchical_select',
'#required' => TRUE,
'#config' => array(
'module' => 'hs_flatlist',
'params' => array(
'options' => $views,
),
'dropbox' => array(
'status' => 1,
'title' => t('Selected views'),
),
),
'#description' => t('The views to deploy.'),
);
}
else {
$form['view_name'] = array(
'#title' => t('View'),
'#type' => 'select',
'#multiple' => TRUE,
'#required' => TRUE,
'#options' => $views,
'#description' => t('The views to deploy.'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function views_deploy_add_form_submit($form_id, $form_values) {
$pid = $form_values['pid'];
$module = 'views';
foreach ($form_values['view_name'] as $view_name) {
$description = "View: {$view_name}";
deploy_add_to_plan($pid, $module, $description, $view_name);
}
return "admin/build/deploy/list/{$pid}";
}
function views_deploy_add_form_validate($form_id, $form_values) {
foreach ($form_values['view_name'] as $view_name) {
$result = db_query("select * from {deploy_plan_items} where module = 'views' and pid = %d and data = '%s'", $form_values['pid'], $view_name);
if (db_num_rows($result)) {
form_set_error('view_name', t("View {$view_name} already exists in the deployment plan."));
}
}
}
function views_deploy($url, $api_key, $view_name) {
$view = views_get_view($view_name);
if (is_null($view)) {
drupal_set_message(t("View {$view_name} does not exist."));
}
$export = views_create_view_code($view_name);
return xmlrpc($url, 'views.importView', $api_key, $export);
}