You are here

function ds_test_entity_view in Display Suite 8.3

Same name and namespace in other branches
  1. 8.4 tests/modules/ds_test/ds_test.module \ds_test_entity_view()
  2. 8.2 tests/modules/ds_test/ds_test.module \ds_test_entity_view()

Implements hook_entity_view().

File

tests/modules/ds_test/ds_test.module, line 59
Display Suite test module.

Code

function ds_test_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  $build['ds_extras_extra_test_field'] = [
    '#markup' => 'This is an extra field made available through "Extra fields" functionality.',
    '#weight' => 10,
  ];

  // Check whether the heavy extra field is rendered or not.
  if ($entity
    ->getEntityTypeId() == 'node' && $entity
    ->bundle() == 'article') {
    $heavy_field = $display
      ->getComponent('heavy_field');
    if ($heavy_field) {
      $build['heavy_field'] = [
        '#markup' => 'Heavy field',
        '#weight' => $heavy_field['weight'],
      ];
    }
  }
}