og-8.x-1.x-dev/tests/modules/og_test/src/Plugin/OgFields/EntityRestrictedField.php

tests/modules/og_test/src/Plugin/OgFields/EntityRestrictedField.php
<?php

declare(strict_types=1);

namespace Drupal\og_test\Plugin\OgFields;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\og\Attribute\OgFields;
use Drupal\og\OgFieldBase;
use Drupal\og\OgFieldsInterface;

/**
 * A test field that can be attached only to the node entity.
 */
#[OgFields(
  id: 'entity_restricted',
  type: 'group',
  description: new TranslatableMarkup('A test field that can be attached only to the node entity.'),
)]
class EntityRestrictedField extends OgFieldBase implements OgFieldsInterface {

  /**
   * {@inheritdoc}
   */
  public function getFieldStorageBaseDefinition(array $values = []): array {
    $values = [
      // Restrict the allowed entities.
      'entity' => ['node'],
      'type' => 'list_integer',
    ];

    return parent::getFieldStorageBaseDefinition($values);
  }

  /**
   * {@inheritdoc}
   */
  public function getFormDisplayDefinition(array $values = []): array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getViewDisplayDefinition(array $values = []): array {
    return [];
  }

}

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

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