Example #1
0
/**
 * Implements hook_preprocess_field().
 */
function eigefoundationtheme_preprocess_field(&$variables, $hook)
{
    if ($variables['element']['#field_name'] == 'field_mt_ongoing') {
        if (!isset($variables['element']['#items']) || !count($variables['element']['#items']) || !isset($variables['element']['#items'][0]) || isset($variables['element']['#items'][0]) && $variables['element']['#items'][0]['value'] == 0) {
            $variables['items'][0]['#markup'] = '';
            $variables['label_hidden'] = TRUE;
        }
    }
    if (in_array($variables['element']['#field_name'], array('field_primary_topic_category', 'field_other_topic_categories'))) {
        foreach ($variables['items'] as $delta => $item) {
            if (isset($variables['items'][$delta]['#markup'])) {
                $term_name = $variables['items'][$delta]['#markup'];
                $css_class = _title_to_css_class($term_name, 'gender_story_topic_');
                array_push($variables['item_attributes_array'][$delta]['class'], $css_class);
                $variables['items'][$delta]['#markup'] = '<a href="/more-areas/gender-stereotypes/search-for-gender-stories?pt[]=' . $variables['element']['#items'][$delta]['tid'] . '" title="' . t("See all stories for topic ") . $term_name . '">' . $term_name . '</a>';
            }
        }
    }
    // this is required for certain fields only (EIGEDR-400), but since it's unobtrusive, will apply to all
    if ($variables['element']['#field_type'] == 'list_integer') {
        if (isset($variables['items'][0]['#markup'])) {
            $css_class = _title_to_css_class($variables['items'][0]['#markup'], 'list_value_');
            $variables['classes_array'][] = $css_class;
        }
    }
    // this is required for certain CTs only (EIGEDR-413), but since it's unobtrusive, will apply to all
    if ($variables['element']['#field_name'] == 'content_type' && $variables['element']['#view_mode'] == 'teaser') {
        $variables['classes_array'][] = 'type_' . $variables['element']['#bundle'];
    }
}
$primaryTopicClass = _title_to_css_class($primaryTopicCategoryName, ' _ gender_story_topic_');
$avatar_classes = '"group-avatar-wrapper field-group-div' . $primaryTopicClass . $ageClass . $sexClass . '"';
//Key Actors field
$keyActors = null;
if (isset($node->field_key_actors['en'][0])) {
    $keyActors = $node->field_key_actors['en'][0]['value'];
}
//Primary Topic Category markup
$primaryTopicCategory = '<div class="taxonomy-term-reference ' . $primaryTopicClass . '"">' . $primaryTopicCategoryName . '</div>';
//Other Topic Categories markup
$otherTopicCategoriesMarkup = '';
foreach ($node->field_other_topic_categories[LANGUAGE_NONE] as $index => $term) {
    $tid = $term['tid'];
    $topicCategoryTerm = taxonomy_term_load($tid);
    $topicCategoryName = $topicCategoryTerm->name;
    $topicCategoryClass = _title_to_css_class($topicCategoryName, ' _ gender_story_topic_');
    $otherTopicCategoriesMarkup .= '<div class="taxonomy-term-reference ' . $topicCategoryClass . '">' . $topicCategoryName . '</div>';
}
//Other Topics markup
$otherTopicsMarkup = '';
foreach ($node->field_other_topics[LANGUAGE_NONE] as $index => $term) {
    $tid = $term['tid'];
    $topicTerm = taxonomy_term_load($tid);
    $topicName = $topicTerm->name;
    $otherTopicsMarkup .= '<div class="taxonomy-term-reference">' . $topicName . '</div>';
}
//Year markup
$yearMarkup = null;
foreach ($node->field_year[LANGUAGE_NONE] as $index => $yearItem) {
    $yearMarkup .= '<span class="date-display-single" property="dc:date" datatype="xsd:dateTime" content="' . $yearItem['value'] . '">' . substr($yearItem['value'], 0, 4) . '</span>';
}