Created
March 4, 2015 21:02
-
-
Save hannesl/a415957b1136c1885446 to your computer and use it in GitHub Desktop.
Drupal: bring some sanity to the field markup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!empty($items) && !empty($items[0]) && !empty($items[0]['#markup'])): ?> | |
<div class="<?php print $classes; ?>"<?php print $attributes; ?>> | |
<?php if ($multiple): ?> | |
<?php if (!$label_hidden && $label) : ?> | |
<h3 class="field-label"<?php print $title_attributes; ?>><?php print $label ?></h3> | |
<?php endif; ?> | |
<ul class="field-items"> | |
<?php foreach ($items as $item) : ?> | |
<li class="field-item"><?php print render($item); ?></li> | |
<?php endforeach; ?> | |
</ul> | |
<?php else: ?> | |
<?php if (!$label_hidden && $label) : ?> | |
<?php if ($element['#label_display'] == 'inline'): ?> | |
<span class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:</span> | |
<?php else: ?> | |
<h3 class="field-label"<?php print $title_attributes; ?>><?php print $label ?></h3> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php foreach ($items as $item) : ?> | |
<?php print render($item); ?> | |
<?php endforeach; ?> | |
<?php endif; ?> | |
</div> | |
<?php endif ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function THEME_preprocess_field(&$vars) { | |
// Check if this is a single or multiple field. | |
$field_info = field_info_field($vars['element']['#field_name']); | |
$vars['multiple'] = $field_info['cardinality'] != 1; | |
$vars['single'] = !$vars['multiple']; | |
// Label inline or above? | |
$vars['label_inline'] = $vars['element']['#label_display'] == 'inline'; | |
$vars['label_above'] = !$vars['label_inline']; | |
// No .clearfix please. | |
$vars['classes_array'] = array_diff($vars['classes_array'], array('clearfix')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment