edit_test.module 1014 Bytes
Newer Older
1 2 3 4 5 6
<?php

/**
 * @file
 * Helper module for the Edit tests.
 */
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

use Drupal\Core\Language\Language;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity\Entity\EntityDisplay;

/**
 * Implements hook_entity_view_alter().
 */
function edit_test_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) {
  if ($entity->entityType() == 'node' && $entity->bundle() == 'article') {
    $build['pseudo'] = array(
      '#theme' => 'field',
      '#title' => 'My pseudo field',
      '#field_name' => 'edit_test_pseudo_field',
      '#label_display' => 'Label',
      '#entity_type' => $entity->entityType(),
      '#bundle' => $entity->bundle(),
      '#language' => Language::LANGCODE_NOT_SPECIFIED,
      '#field_type' => 'pseudo',
      '#view_mode' => 'default',
      '#object' => $entity,
      '#access' => TRUE,
      '#items' => array(
        0 => array(
          'value' => 'pseudo field',
        ),
      ),
      0 => array(
        '#markup' => 'pseudo field',
      ),
    );
  }
}