You are here

public static function Host::baseFieldDefinitions in http:BL 8

Determines the schema for the base_table property defined above.

Overrides ContentEntityBase::baseFieldDefinitions

File

src/Entity/Host.php, line 198
Contains \Drupal\httpbl\Entity\Host.

Class

Host
Defines the host entity class.

Namespace

Drupal\httpbl\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

  // Standard field, used as unique if primary index.
  $fields['hid'] = BaseFieldDefinition::create('integer')
    ->setLabel(new TranslatableMarkup('ID'))
    ->setDescription(new TranslatableMarkup('The Unique ID of the Host entity.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);

  // Host Ip (Name) field for the host.
  $fields['host_ip'] = BaseFieldDefinition::create('string')
    ->setLabel(new TranslatableMarkup('Http:BL Evaluated Host'))
    ->setDescription(new TranslatableMarkup('Evaluated Host IP address.'))
    ->setSettings(array(
    'default_value' => '',
    'max_length' => 15,
    'text_processing' => 0,
  ))
    ->setDisplayOptions('view', array(
    'label' => 'above',
    'type' => 'string',
    'weight' => -6,
  ))
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', FALSE);

  // Status the host; whether or not it is safe, grey-listed or blacklisted.
  $fields['host_status'] = BaseFieldDefinition::create('integer')
    ->setLabel(new TranslatableMarkup('Host Status'))
    ->setDescription(new TranslatableMarkup('Evaluated status (HTTPBL_LIST_* constants)'))
    ->setRequired(TRUE)
    ->setSetting('size', 'tiny')
    ->setConstraints(array(
    'Range' => array(
      'min' => 0,
      'max' => 2,
    ),
  ))
    ->setDisplayOptions('view', array(
    'label' => 'inline',
    'type' => 'integer',
    'weight' => 0,
  ))
    ->setDisplayConfigurable('view', TRUE);

  // Evaluation source for the host.
  $fields['source'] = BaseFieldDefinition::create('string')
    ->setLabel(new TranslatableMarkup('Evaluation Source'))
    ->setDescription(new TranslatableMarkup('Who evaluated this host?'))
    ->setSettings(array(
    'default_value' => '',
    'max_length' => 32,
    'text_processing' => 0,
  ))
    ->setDisplayOptions('view', array(
    'label' => 'inline',
    'type' => 'string',
    'weight' => 1,
  ))
    ->setDisplayConfigurable('view', TRUE);

  // Expiration timestamp for this host.
  $fields['expire'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(new TranslatableMarkup('Expires'))
    ->setDescription(t('Time this host should be purged (via cron).'))
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE)
    ->setDisplayOptions('view', array(
    'label' => 'inline',
    'type' => 'timestamp',
    'weight' => 2,
  ))
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);

  // Created timestamp for this host.
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(new TranslatableMarkup('Created'))
    ->setDescription(t('Time this host was created.'))
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE);

  // Changed timestamp for this host.
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(new TranslatableMarkup('Changed'))
    ->setDescription(t('The time that the host was last edited.'))
    ->setTranslatable(TRUE)
    ->setRevisionable(TRUE);

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