You are here

function publication_date_entity_base_field_info in Publication Date 8

Same name and namespace in other branches
  1. 8.2 publication_date.module \publication_date_entity_base_field_info()

Implements hook_entity_base_field_info().

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type:

Return value

array

File

./publication_date.module, line 25
Add a field to nodes containing the publication date.

Code

function publication_date_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  $fields = [];
  if ($entity_type
    ->id() == 'node') {
    $fields['published_at'] = \Drupal\Core\Field\BaseFieldDefinition::create('published_at')
      ->setLabel(t('Published on'))
      ->setDescription(t('Keep the publication timestamp for each node.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', array(
      'label' => 'hidden',
      'type' => 'timestamp',
      'weight' => 0,
    ))
      ->setDisplayOptions('form', array(
      'type' => 'datetime_timestamp',
      'weight' => 10,
    ))
      ->setDisplayConfigurable('form', TRUE);
  }
  return $fields;
}