I've created a custom widget for a textarea (to display the contents in a table as well). So the textarea should appear and work just like a normal textarea widget, but with an additional HTML table of its contents.
I can make it appear correctly, but when I save the form the values do not get saved.
In fact, my "data_source_field_is_empty()" function is never called (the dpm() text never appears).
function data_source_field_widget_form(&$form,
&$form_state,
$field,
$instance,
$langcode,
$items,
$delta,
$element) {
switch ($instance['widget']['type']) {
case 'data_source_data_widget':
$thisItem = isset($items[$delta]) ? $items[$delta]['value'] : '';
$widget['#type'] = 'textarea';
$widget['#default_value'] = $thisItem;
// Only do this if there is already content in the field
if (isset($items[$delta])) {
$rows = _data_source_parse_csv($thisItem);
$widget['#prefix'] = '<button type="button" id="show-hide-raw-table-data">Show raw data</button>';
$widget['#suffix'] = _data_source_dataTable($rows, 0);
$form['#attached']['js'][] = array(
'data' => drupal_get_path('module', 'data_source') . '/js/data_source.js',
'type' => 'file',
);
$form['#attached']['css'][] = array(
'data' => drupal_get_path('module', 'data_source') . '/css/data_source.css',
'type' => 'file',
);
}
$element[$field['field_name']] = $widget;
break;
}
return ($element);
}
function data_source_field_is_empty($item, $field) {
dpm("Got here");
return empty($item[$field['field_name']]);
}
Any ideas? I'm looking at the $element[$field['field_name']] = $widget;
part, but none of the variations I've tried have worked.