function easychart_field_widget_form in Easychart 7.3
Same name and namespace in other branches
- 7 easychart.module \easychart_field_widget_form()
- 7.2 easychart.module \easychart_field_widget_form()
Implements hook_field_widget_form().
File
- ./
easychart.module, line 146 - Easychart module file.
Code
function easychart_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
switch ($instance['widget']['type']) {
case 'easychart':
$required = $element['#required'];
// Send Easychart configuration to the Easychart admin interface.
$options = '';
if (file_exists('public://easychart-options.json')) {
$options = file_get_contents('public://easychart-options.json');
}
$settings = array(
'easychartOptions' => $options,
'easychartTemplates' => variable_get('easychart_templates', ''),
'easychartPresets' => variable_get('easychart_presets', ''),
'easychartCustomize' => FALSE,
);
if (user_access('access full easychart configuration')) {
$settings['easychartCustomize'] = TRUE;
}
drupal_add_js(array(
'easychart' => $settings,
), 'setting');
// Wrapper to add the required javascript and css.
$element = array(
'#prefix' => '<div class="easychart-wrapper clearfix">',
'#suffix' => '</div>',
'#attached' => array(
// Add highcharts plugin.
'libraries_load' => array(
array(
'highcharts',
),
array(
'easychart',
),
),
'js' => array(
drupal_get_path('module', 'easychart') . '/js/easychart.widget.js',
drupal_get_path('module', 'easychart') . '/js/screenfull.min.js',
drupal_get_path('module', 'easychart') . '/js/handsontable.full.min.js',
),
'css' => array(
drupal_get_path('module', 'easychart') . '/css/easychart.widget.css',
drupal_get_path('module', 'easychart') . '/css/handsontable.full.min.css',
),
),
);
// Hidden fields with the chart data.
$element['config'] = array(
'#description' => t('The configuration options as described at http://api.highcharts.com/highcharts'),
'#type' => 'hidden',
'#default_value' => isset($items[$delta]['config']) ? $items[$delta]['config'] : NULL,
'#attributes' => array(
'class' => array(
'easychart-config',
),
),
);
$element['csv'] = array(
'#description' => t('Your chart data in CSV format'),
'#type' => 'hidden',
'#default_value' => isset($items[$delta]['csv']) ? $items[$delta]['csv'] : NULL,
'#attributes' => array(
'class' => array(
'easychart-csv',
),
),
'#element_validate' => array(
'easychart_field_csv_validate',
),
'#csv_required' => $required,
);
$element['csv_url'] = array(
'#description' => t('The URL to a CSV file'),
'#type' => 'hidden',
'#default_value' => isset($items[$delta]['csv_url']) ? $items[$delta]['csv_url'] : NULL,
'#attributes' => array(
'class' => array(
'easychart-csv-url',
),
),
);
// Placeholder to embed the Easychart plugin.
$element['preview'] = array(
'#title' => t('Easychart'),
'#markup' => '',
'#prefix' => '<div class="easychart-embed"><div class="easychart-header"><span class="toggle">' . t('Toggle Fullscreen') . '</span></div>',
'#suffix' => '</div>',
);
break;
}
return $element;
}