You are here

public static function DomainPath::baseFieldDefinitions in Domain Path 8

Define the field properties here.

Field name, type and size determine the table structure.

In addition, we can define how the field and its content can be manipulated in the GUI. The behaviour of the widgets used can be determined here.

Overrides ContentEntityBase::baseFieldDefinitions

File

src/Entity/DomainPath.php, line 65
Contains \Drupal\domain_path\Entity\DomainPath.

Class

DomainPath
Defines the DomainPath entity.

Namespace

Drupal\domain_path\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

  // Standard field, used as unique if primary index.
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Term entity.'))
    ->setReadOnly(TRUE);

  // Standard field, unique outside of the scope of the current project.
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Domain path entity.'))
    ->setReadOnly(TRUE);

  // Owner field of the Domain path.
  // Entity reference field, holds the reference to the domain object.
  // The view shows the title field of the domain.
  // The form presents a auto complete field for the domain title.
  $fields['domain_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Domain Id'))
    ->setDescription(t('The Title of the associated domain.'))
    ->setSetting('target_type', 'domain')
    ->setSetting('handler', 'default')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'entity_reference_label',
    'weight' => -7,
  ])
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => 60,
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
    'weight' => -7,
  ])
    ->setRequired(TRUE);
  $fields['language'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language'))
    ->setDescription(t('The language of Domain path entity.'))
    ->setRequired(TRUE);

  // Name field for the domain path.
  // We set display options for the view as well as the form.
  // Users with correct privileges can change the view and edit configuration.
  $fields['source'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Source'))
    ->setDescription(t('The source patch of the Domain path alias.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -5,
  ])
    ->setRequired(TRUE);

  // Name field for the domain path.
  // We set display options for the view as well as the form.
  // Users with correct privileges can change the view and edit configuration.
  $fields['alias'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Alias'))
    ->setDescription(t('The alias of the Domain path entity.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -5,
  ])
    ->setRequired(TRUE);
  return $fields;
}