You are here

function ds_extras_entity_view_alter in Display Suite 8.3

Same name and namespace in other branches
  1. 8.2 modules/ds_extras/ds_extras.module \ds_extras_entity_view_alter()
  2. 7.2 modules/ds_extras/ds_extras.module \ds_extras_entity_view_alter()
  3. 7 modules/ds_extras/ds_extras.module \ds_extras_entity_view_alter()

Implements hook_entity_view_alter().

File

modules/ds_extras/ds_extras.module, line 346
Display Suite extras main functions.

Code

function ds_extras_entity_view_alter(&$build, EntityInterface $entity, EntityDisplayInterface $display) {
  $entity_type = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  $view_mode = $display
    ->getMode();
  $block_data =& drupal_static('ds_block_region');
  $region_blocks = \Drupal::config('ds_extras.settings')
    ->get('region_blocks');
  if (empty($region_blocks) || empty($build)) {
    return;
  }
  $properties = [];
  foreach (Element::properties($build) as $property) {
    $properties[$property] = $build[$property];
  }
  $properties['#view_mode'] = $view_mode;
  if ($ds_settings = $display
    ->getThirdPartySettings('ds')) {
    foreach ($region_blocks as $block_key => $block) {
      if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}" && isset($ds_settings['regions'][$block_key]) && !empty($ds_settings['regions'][$block_key])) {
        foreach ($ds_settings['regions'][$block_key] as $field) {
          if (isset($build[$field])) {
            $block_data[$block_key][$field] = $build[$field];
            unset($build[$field]);
          }
        }
        if (isset($block_data[$block_key]) && is_array($block_data[$block_key])) {
          $block_data[$block_key] += $properties;
        }
      }
    }
  }
}