View source
<?php
$plugin = array(
'schema' => 'analytics_service',
'menu' => array(
'menu prefix' => 'admin/config/services',
'menu item' => 'analytics',
'menu title' => 'Analytics services',
'menu description' => 'Add, edit, and remove analytics services.',
),
'title singular' => t('analytics service'),
'title singular proper' => t('Analytics service'),
'title plural' => t('analytics services'),
'title plural proper' => t('Analytics services'),
'form' => array(
'settings' => 'analytics_service_edit_form',
),
'export' => array(
'admin_title' => 'label',
),
'handler' => array(
'class' => 'AnalyticsServiceExportUI',
'parent' => 'ctools_export_ui',
),
);
function analytics_service_edit_form(&$form, &$form_state) {
$service =& $form_state['item'];
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $service->description,
'#rows' => 2,
'#access' => FALSE,
);
if (!$service->service) {
$options = analytics_service_add_service_options();
natsort($options);
$form['service'] = array(
'#type' => 'select',
'#title' => t('Service'),
'#options' => $options,
'#required' => TRUE,
'#ajax' => array(
'callback' => 'analytics_service_edit_form_options_ajax',
'wrapper' => 'analytics-service-options',
'method' => 'replace',
'effect' => 'fade',
),
);
}
else {
$info = analytics_get_service_info($service->service);
$form['service'] = array(
'#type' => 'item',
'#title' => t('Service'),
'#markup' => $info ? check_plain($info['label']) : check_plain($service->service),
);
}
$new_service = drupal_array_get_nested_value($form_state, array(
'values',
'service',
));
if ($new_service && $new_service != $service->service) {
$service->service = $new_service;
$service->options = array();
form_clear_error();
}
$form['options'] = array(
'#type' => 'container',
'#tree' => TRUE,
'#prefix' => '<div id="analytics-service-options">',
'#suffix' => '</div>',
);
if ($service->service && ($instance = analytics_get_service_instance($service))) {
$form['options'] += $instance
->buildConfigurationForm($form, $form_state);
}
}
function analytics_service_edit_form_options_ajax($form, $form_state) {
return $form['options'];
}