function tablefield_field_formatter_settings_form in TableField 7.3
Same name and namespace in other branches
- 7.2 tablefield.module \tablefield_field_formatter_settings_form()
Implements hook_field_formatter_settings_form().
File
- ./
tablefield.module, line 696 - Provides a set of fields that can be used to store tabular data with a node.
Code
function tablefield_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
switch ($display['type']) {
case 'format_raw':
// Get a machine name from the field name (without 'field_' prefix).
$prefix = 'field_';
$machine = $instance['field_name'];
$select = 'select';
$select_or_other_module = l(t('Select (or other) module'), 'https://drupal.org/project/select_or_other', array(
'attributes' => array(
'title' => t('Select (or other) | Drupal.org'),
'target' => '_blank',
),
));
$description = t('To provide a custom value install and enable the !select_or_other_module.', array(
'!select_or_other_module' => $select_or_other_module,
));
if (module_exists('select_or_other')) {
$select = 'select_or_other';
$description = NULL;
}
if (substr($machine, 0, strlen($prefix)) == $prefix) {
$machine = substr($machine, strlen($prefix));
}
$element['tabledatakey'] = array(
'#type' => $select,
'#title' => t('Wrapper for table data (if applicable)'),
'#description' => $description,
'#options' => array(
'tabledata' => t('tabledata (fixed string)'),
$instance['label'] => t('Label: @label', array(
'@label' => $instance['label'],
)),
$machine => t('Machine name: @machine', array(
'@machine' => $machine,
)),
),
'#default_value' => $settings['tabledatakey'],
'#other_unknown_defaults' => 'other',
'#other_delimiter' => FALSE,
);
$element['usearraykeys'] = array(
'#type' => 'select',
'#title' => t('Use first row/column values as keys (if not empty)'),
'#options' => array(
'No' => t('No'),
'Header' => t('Header only'),
'Both' => t('Both first row and first column (two headers, horizontal and vertical)'),
),
'#default_value' => $settings['usearraykeys'],
);
$element['rowkey'] = array(
'#title' => t('Row identifier key'),
'#type' => 'checkbox',
'#default_value' => $settings['rowkey'],
);
if ($settings['usearraykeys'] === 'Both') {
$element['rowkey']['#disabled'] = TRUE;
$element['rowkey']['#title'] = '<span class="grayed-out">' . t('Row identifier key') . '</span> | ' . t("Disabled because above the first column values are set to be used as row identifiers.");
}
$element['vertheader'] = array(
'#title' => t('Vertical header (first column instead of first row)'),
'#type' => 'checkbox',
'#default_value' => $settings['vertheader'],
);
$element['tabledataonly'] = array(
'#title' => t('Table data only (no caption)'),
'#type' => 'checkbox',
'#default_value' => $settings['tabledataonly'],
);
$element['numeric_check'] = array(
'#title' => t('Encode numeric strings as numbers'),
'#type' => 'checkbox',
'#default_value' => $settings['numeric_check'],
);
if ($settings['xml']) {
$element['numeric_check']['#disabled'] = TRUE;
$element['numeric_check']['#title'] = '<span class="grayed-out">' . t('Encode numeric strings as numbers') . '</span> | ' . t("Disabled because below XML is selected that does not use quotes around any values.");
}
$element['xml'] = array(
'#title' => t('XML instead of JSON'),
'#type' => 'checkbox',
'#default_value' => $settings['xml'],
);
$element['xml_safe'] = array(
'#type' => 'select',
'#title' => t('How to make field values XML safe?'),
'#options' => array(
'htmlspecialchars' => t('Convert special characters to HTML entities (htmlspecialchars)'),
'cdata' => t('Represent field values that contain special characters as a CDATA section'),
'cdata_all' => t('Represent all field values as a CDATA section'),
),
'#default_value' => $settings['xml_safe'],
);
if (!$settings['xml']) {
$element['xml_safe']['#disabled'] = TRUE;
$element['xml_safe']['#title'] = '<span class="grayed-out">' . t('How to make field values XML safe?') . '</span> | ' . t("Disabled because above XML is not selected.");
}
break;
default:
$element['sticky_header'] = array(
'#title' => t('Sticky header'),
'#type' => 'checkbox',
'#default_value' => $settings['sticky_header'],
);
$element['striping'] = array(
'#title' => t('Striping (odd/even class)'),
'#type' => 'checkbox',
'#default_value' => $settings['striping'],
);
$element['sortable'] = array(
'#title' => t('Sortable'),
'#type' => 'checkbox',
'#default_value' => $settings['sortable'],
);
$tablesorter_module = l(t('Tablesorter module'), 'https://drupal.org/project/tablesorter', array(
'attributes' => array(
'title' => t('Tablesorter | Drupal.org'),
'target' => '_blank',
),
));
$element['hide_header'] = array(
'#title' => t('Hide first row'),
'#type' => 'checkbox',
'#default_value' => $settings['hide_header'],
);
$element['hide_cols_skip_head'] = array(
'#title' => t('Hide empty columns ignoring column header'),
'#description' => t('This will remove the table field completely if all columns are empty including the field label.'),
'#type' => 'checkbox',
'#default_value' => $settings['hide_cols_skip_head'],
);
$element['trim_trailing_cols'] = array(
'#title' => t('Trim empty trailing columns'),
'#type' => 'checkbox',
'#default_value' => $settings['trim_trailing_cols'],
);
$element['trim_trailing_rows'] = array(
'#title' => t('Trim empty trailing rows'),
'#type' => 'checkbox',
'#default_value' => $settings['trim_trailing_rows'],
);
$element['hide_empty_rows'] = array(
'#title' => t('Hide empty rows'),
'#type' => 'checkbox',
'#default_value' => $settings['hide_empty_rows'],
);
$element['hide_empty_cols'] = array(
'#title' => t('Hide empty columns'),
'#type' => 'checkbox',
'#default_value' => $settings['hide_empty_cols'],
);
$permission = l(t('permission'), 'admin/people/permissions', array(
'fragment' => 'module-tablefield',
'attributes' => array(
'title' => t('Manage user permissions'),
),
));
$element['table_custom_class_attributes'] = array(
'#title' => t('Add custom class attribute classes to the table html element'),
'#type' => 'textfield',
'#size' => 40,
'#default_value' => $settings['table_custom_class_attributes'],
);
$element['export_csv'] = array(
'#title' => t('Show link to export table data as CSV depending on !permission', array(
'!permission' => $permission,
)),
'#type' => 'checkbox',
'#default_value' => $settings['export_csv'],
);
}
return $element;
}