farm-2.x-dev/modules/core/entity/tests/modules/farm_entity_test/farm_entity_test.module

modules/core/entity/tests/modules/farm_entity_test/farm_entity_test.module
<?php

/**
 * @file
 * Contains farm_entity_test.module.
 */

use Drupal\Core\Entity\EntityTypeInterface;

/**
 * Implements hook_entity_base_field_info().
 */
function farm_entity_test_entity_base_field_info(EntityTypeInterface $entity_type) {
  $fields = [];

  // Add a new base field to all logs.
  if ($entity_type->id() == 'log') {
    $options = [
      'type' => 'string',
      'label' => t('Test hook base field'),
    ];
    $fields['test_hook_base_field'] = \Drupal::service('farm_field.factory')->baseFieldDefinition($options);
  }

  return $fields;
}

/**
 * Implements hook_farm_entity_bundle_field_info().
 */
function farm_entity_test_farm_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle) {
  $fields = [];

  // Add a new bundle field to test logs.
  if ($entity_type->id() == 'log' && in_array($bundle, ['test', 'test_override'])) {
    $options = [
      'type' => 'string',
      'label' => t('Test hook bundle field'),
    ];
    $fields['test_hook_bundle_field'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
  }

  // Add bundle specific fields to all log types.
  if ($entity_type->id() == 'log') {
    $options = [
      'type' => 'string',
      'label' => t('Test bundle specific field for: @bundle', ['@bundle' => $bundle]),
    ];
    $field_name = 'test_hook_bundle_' . $bundle . '_specific_field';
    $fields[$field_name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
  }

  return $fields;
}

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

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