function theme_ds_field_expert in Display Suite 7.2
Same name and namespace in other branches
- 7 modules/ds_extras/ds_extras.module \theme_ds_field_expert()
Custom output all HTML for the field.
2 string references to 'theme_ds_field_expert'
- dsNodeTests::testDSFieldTemplate in tests/
ds.entities.test - Tests on field templates.
- ds_extras_ds_field_settings_alter in modules/
ds_extras/ ds_extras.module - Implements hook_ds_field_settings_alter().
File
- modules/
ds_extras/ ds_extras.module, line 782 - Display Suite extras main functions.
Code
function theme_ds_field_expert($variables) {
$output = '';
$config = $variables['ds-config'];
// Set prefix
if (!empty($config['prefix'])) {
$output .= $config['prefix'];
}
// Render the label if it's not hidden.
if (!$variables['label_hidden']) {
$styled_label = $variables['label'];
if (!isset($config['lb-col'])) {
$styled_label .= ': ';
}
// Style the label it self
$label_wrapper = isset($config['lb-el']) ? $config['lb-el'] : 'div';
$class = array(
'label-' . $variables['element']['#label_display'],
);
if (!empty($config['lb-cl'])) {
$class[] = $config['lb-cl'];
}
$class = !empty($class) ? ' class="' . implode(' ', $class) . '"' : '';
$attributes = array();
if (!empty($config['lb-at'])) {
$attributes[] = $config['lb-at'];
}
if (!empty($config['lb-def-at'])) {
$attributes[] = $variables['title_attributes'];
}
$attributes = !empty($attributes) ? ' ' . implode(' ', $attributes) : '';
$styled_label = '<' . $label_wrapper . $class . $attributes . '>' . $styled_label . '</' . $label_wrapper . '>';
// Place it inside a wrapper
if (isset($config['lbw'])) {
$class = !empty($config['lbw-cl']) ? ' class="' . $config['lbw-cl'] . '"' : '';
$attributes = !empty($config['lbw-at']) ? ' ' . $config['lbw-at'] : '';
$styled_label = '<' . $config['lbw-el'] . $class . $attributes . '>' . $styled_label . '</' . $config['lbw-el'] . '>';
}
$output .= $styled_label;
}
// Field items wrapper
if (isset($config['fis'])) {
$class = !empty($config['fis-cl']) ? ' class="' . token_replace($config['fis-cl'], array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
)) . '"' : '';
$attributes = array();
if (!empty($config['fis-at'])) {
$attributes[] = token_replace($config['fis-at'], array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
));
}
if (!empty($config['fis-def-at'])) {
$attributes[] = $variables['content_attributes'];
}
$attributes = !empty($attributes) ? ' ' . implode(' ', $attributes) : '';
$output .= '<' . $config['fis-el'] . $class . $attributes . '>';
}
// Render items.
$item_count = count($variables['items']);
$item_index = 0;
foreach ($variables['items'] as $delta => $item) {
// Field item wrapper.
if (isset($config['fi'])) {
$class = array();
if (!empty($config['fi-odd-even'])) {
$class[] = $delta % 2 ? 'even' : 'odd';
}
if (!empty($config['fi-cl'])) {
$class[] = $config['fi-cl'];
}
if (!empty($config['fi-first-last']) && $item_index == 0) {
$class[] = "first";
}
if (!empty($config['fi-first-last']) && $item_index == $item_count - 1) {
$class[] = "last";
}
$class = !empty($class) ? ' class="' . token_replace(implode(' ', $class), array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
)) . '"' : '';
$attributes = array();
if (!empty($config['fi-at'])) {
$attributes[] = token_replace($config['fi-at'], array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
));
}
if (!empty($config['fi-def-at'])) {
$attributes[] = $variables['item_attributes'][$delta];
}
$attributes = !empty($attributes) ? ' ' . implode(' ', $attributes) : '';
$output .= '<' . $config['fi-el'] . $class . $attributes . '>';
}
// Render field content.
$output .= drupal_render($item);
// Closing field item wrapper.
if (isset($config['fi'])) {
$output .= '</' . $config['fi-el'] . '>';
}
++$item_index;
}
// Closing field items wrapper.
if (isset($config['fis'])) {
$output .= '</' . $config['fis-el'] . '>';
}
// Outer wrapper.
if (isset($config['ow'])) {
$class = array();
if (!empty($config['ow-cl'])) {
$class[] = token_replace($config['ow-cl'], array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
));
}
if (!empty($config['ow-def-cl'])) {
$class[] = $variables['classes'];
}
$class = !empty($class) ? ' class="' . implode(' ', $class) . '"' : '';
$attributes = array();
if (!empty($config['ow-at'])) {
$attributes[] = token_replace($config['ow-at'], array(
$variables['element']['#entity_type'] => $variables['element']['#object'],
), array(
'clear' => TRUE,
));
}
if (!empty($config['ow-def-at'])) {
$attributes[] = $variables['attributes'];
}
$attributes = !empty($attributes) ? ' ' . implode(' ', $attributes) : '';
$output = '<' . $config['ow-el'] . $class . $attributes . '>' . $output . '</' . $config['ow-el'] . '>';
}
// Set suffix
if (!empty($config['suffix'])) {
$output .= $config['suffix'];
}
return $output;
}