sector_events-3.0.x-dev/sector_events.module

sector_events.module
<?php

/**
 * @file
 * Contains sector_events.module.
 */

/**
 * Implements hook_preproccess_field.
 *
 * We want to remove the field if the location is empty.
 *
 * Needs to be done in code since it's a display suite field using tokens.
 *
 * If the field is empty the tokens still try to be rendered to it displays
 * strangly and empty.
 *
 * TODO - I would love to make this a bit more flexible. I don't like how
 * inflexible this is - Using the field_event_address machine name for example.
 *
 * @param $variables
 */
function sector_events_preprocess_field(&$variables) {
  if($variables['element']['#field_name'] == 'dynamic_token_field:node-custom_location_with_map_link' && !empty($variables['element']['#field_name'])) {
    $node = $variables['element']['#object'];
    if($node) {
      $location = $node->get('field_event_address')->getValue();
      if (empty($location)) {
        unset($variables['items']);
        $variables['label_hidden'] = true;
      }
    }
  }
}


Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc