pathauto-8.x-1.8/tests/modules/pathauto_string_id_test/src/Entity/PathautoStringId.php

tests/modules/pathauto_string_id_test/src/Entity/PathautoStringId.php
<?php

namespace Drupal\pathauto_string_id_test\Entity;

use Drupal\Core\Entity\Attribute\ContentEntityType;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines a test entity with a string ID.
 *
 * @ContentEntityType(
 *   id = "pathauto_string_id_test",
 *   label = @Translation("Test entity with string ID"),
 *   handlers = {
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
 *     },
 *   },
 *   base_table = "pathauto_string_id_test",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "name",
 *   },
 *   links = {
 *     "canonical" = "/pathauto_string_id_test/{pathauto_string_id_test}",
 *   },
 * )
 */
#[ContentEntityType(
  id: 'pathauto_string_id_test',
  label: new TranslatableMarkup('Test entity with string ID'),
  entity_keys: [
    'id' => 'id',
    'label' => 'name',
  ],
  handlers: [
    'route_provider' => [
      'html' => DefaultHtmlRouteProvider::class,
    ],
  ],
  links: [
    'canonical' => '/pathauto_string_id_test/{pathauto_string_id_test}',
  ],
  base_table: 'pathauto_string_id'
)]
class PathautoStringId extends ContentEntityBase {

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields['id'] = BaseFieldDefinition::create('string')
      ->setLabel('ID')
      ->setReadOnly(TRUE)
      // A bigger value will not be allowed to build the index.
      ->setSetting('max_length', 191);
    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel('Name');
    $fields['path'] = BaseFieldDefinition::create('path')
      ->setLabel('Path')
      ->setComputed(TRUE);

    return $fields;
  }

}

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

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