function Node::baseFieldDefinitions

Same name in other branches
  1. 9 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::baseFieldDefinitions()
  2. 8.9.x core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::baseFieldDefinitions()
  3. 10 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::baseFieldDefinitions()

Overrides EditorialContentEntityBase::baseFieldDefinitions

File

core/modules/node/src/Entity/Node.php, line 272

Class

Node
Defines the node entity class.

Namespace

Drupal\node\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields['title'] = BaseFieldDefinition::create('string')->setLabel(t('Title'))
        ->setRequired(TRUE)
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE)
        ->setSetting('max_length', 255)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
        'weight' => -5,
    ])
        ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['uid']->setLabel(t('Authored by'))
        ->setDescription(t('The username of the content author.'))
        ->setRevisionable(TRUE)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'author',
        'weight' => 0,
    ])
        ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'weight' => 5,
        'settings' => [
            'match_operator' => 'CONTAINS',
            'size' => '60',
            'placeholder' => '',
        ],
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['status']->setDisplayOptions('form', [
        'type' => 'boolean_checkbox',
        'settings' => [
            'display_label' => TRUE,
        ],
        'weight' => 120,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Authored on'))
        ->setDescription(t('The date and time that the content was created.'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'timestamp',
        'weight' => 0,
    ])
        ->setDisplayOptions('form', [
        'type' => 'datetime_timestamp',
        'weight' => 10,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))
        ->setDescription(t('The time that the node was last edited.'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    $fields['promote'] = BaseFieldDefinition::create('boolean')->setLabel(t('Promoted to front page'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDefaultValue(TRUE)
        ->setDisplayOptions('form', [
        'type' => 'boolean_checkbox',
        'settings' => [
            'display_label' => TRUE,
        ],
        'weight' => 15,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['sticky'] = BaseFieldDefinition::create('boolean')->setLabel(t('Sticky at top of lists'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDefaultValue(FALSE)
        ->setDisplayOptions('form', [
        'type' => 'boolean_checkbox',
        'settings' => [
            'display_label' => TRUE,
        ],
        'weight' => 16,
    ])
        ->setDisplayConfigurable('form', TRUE);
    return $fields;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.