improvements-2.x-dev/tests/modules/improvements_test/improvements_test.module

tests/modules/improvements_test/improvements_test.module
<?php

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\improvements\Plugin\Field\ComputedMapFieldItemList;

/**
 * Implements hook_entity_base_field_info().
 */
function improvements_test_entity_base_field_info(EntityTypeInterface $entity_type): ?array {
  if ($entity_type->id() == 'node') {
    $fields = [];

    $fields['test_map_field'] = BaseFieldDefinition::create('map')
      ->setLabel('Test map field');

    $fields['test_computed_map_field_single'] = BaseFieldDefinition::create('string')
      ->setLabel('Test computed map field single')
      ->setComputed(TRUE)
      ->setClass(ComputedMapFieldItemList::class)
      ->setSettings([
        'source_field_name' => 'test_map_field',
        'array_path' => 'second.foo',
     ]);

    $fields['test_computed_map_field_multiple'] = BaseFieldDefinition::create('string')
      ->setLabel('Test computed map field multiple')
      ->setComputed(TRUE)
      ->setClass(ComputedMapFieldItemList::class)
      ->setSettings([
        'source_field_name' => 'test_map_field',
        'array_path' => [
          0 => 'second.foo',
          1 => 'second.bar',
        ],
        'value_template' => '@0-@1',
     ]);

    $fields['test_third_party_data'] = BaseFieldDefinition::create('third_party_data')
      ->setLabel('Test third party data');

    return $fields;
  }

  return NULL;
}

/**
 * Implements hook_page_ROUTE_NAME_result_alter().
 */
function improvements_test_page_improvements_test_altered_page_result_result_alter(array &$page): void {
  $page['#markup'] = 'Altered result';
}

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

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