function theme_jeditable_formatter_jeditable_select in jEditable inline content editing 7
Theme a list field as a jeditable select.
File
- ./
jeditable.module, line 388 - jeditable.module TODO: Provides integration between Drupal and the jEditable jquery plugin @todo: Datepicker support @todo: Ajax upload support @todo: Radioboxes/checkboxes support @todo: add required handler for date @todo: add compatibility for…
Code
function theme_jeditable_formatter_jeditable_select($variables) {
$element = $variables['element'];
$field = $variables['field'];
$field_name = $field['field_name'];
$entity = $variables['entity'];
$entity_type = $variables['entity_type'];
$widget_type = $variables['widget_type'];
$delta = $variables['delta'];
$field_info = field_info_field($field_name);
//key value instead of key as value
$key_val = isset($field_info['settings']['allowed_values'][$element['value']]) ? $field_info['settings']['allowed_values'][$element['value']] : t('- None -');
switch ($entity_type) {
case 'node':
// Check user's access to editing this node.
if (!node_access('update', $entity)) {
return $element['value'];
}
$id = $entity->nid;
break;
case 'field_collection_item':
// user's access inherited from node.
$field_name = $entity->field_name;
$hostEntity = entity_load_single('field_collection_item', $entity->item_id)
->hostEntity();
$id = $hostEntity->nid;
// override delta with field_collection's delta
foreach ($hostEntity->{$field_name}[$hostEntity->language] as $key => $val) {
if ($val['value'] == $entity->item_id) {
$delta = $key;
}
}
break;
case 'user':
// Check user's access to editing this user.
if (!user_edit_access($entity)) {
return $element['value'];
}
$id = $entity->uid;
break;
}
if (strpos($field['field_name'], 'field_') === 0) {
$entity_type = 'field';
}
return '<span id="' . $entity_type . '-' . $id . '-' . $field['field_name'] . '-' . $widget_type . '-' . $delta . '" class="jeditable jeditable-' . $widget_type . '">' . $key_val . '</span>';
}