edit_test.module 1.34 KB
Newer Older
1
2
3
4
5
6
<?php

/**
 * @file
 * Helper module for the Edit tests.
 */
7
8
9

use Drupal\Core\Language\Language;
use Drupal\Core\Entity\EntityInterface;
10
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
11
12
13
14

/**
 * Implements hook_entity_view_alter().
 */
15
function edit_test_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  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',
      ),
    );
  }
}
40
41
42
43
44
45
46
47
48
49
50
51

/**
 * Implements hook_edit_render_field().
 */
function edit_test_edit_render_field(Drupal\Core\Entity\EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
  return array(
    '#prefix' => '<div class="edit-test-wrapper">',
    'field' => field_view_field($entity, $field_name),
    '#suffix' => '</div>',
  );
}