getOwnerId()) { // If no owner has been set explicitly, make the anonymous user the owner. $this->setOwnerId(0); } } {% endif %} {% if has_base_fields %} /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); {% if label_base_field %} $fields['label'] = BaseFieldDefinition::create('string') {% if revisionable %} ->setRevisionable(TRUE) {% endif %} {% if translatable %} ->setTranslatable(TRUE) {% endif %} ->setLabel(t('Label')) ->setRequired(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', [ 'type' => 'string_textfield', 'weight' => -5, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('view', [ 'label' => 'hidden', 'type' => 'string', 'weight' => -5, ]) ->setDisplayConfigurable('view', TRUE); {% endif %} {% if status_base_field %} $fields['status'] = BaseFieldDefinition::create('boolean') {% if revisionable %} ->setRevisionable(TRUE) {% endif %} ->setLabel(t('Status')) ->setDefaultValue(TRUE) ->setSetting('on_label', 'Enabled') ->setDisplayOptions('form', [ 'type' => 'boolean_checkbox', 'settings' => [ 'display_label' => FALSE, ], 'weight' => 0, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('view', [ 'type' => 'boolean', 'label' => 'above', 'weight' => 0, 'settings' => [ 'format' => 'enabled-disabled', ], ]) ->setDisplayConfigurable('view', TRUE); {% endif %} {% if description_base_field %} $fields['description'] = BaseFieldDefinition::create('text_long') {% if revisionable %} ->setRevisionable(TRUE) {% endif %} {% if translatable %} ->setTranslatable(TRUE) {% endif %} ->setLabel(t('Description')) ->setDisplayOptions('form', [ 'type' => 'text_textarea', 'weight' => 10, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('view', [ 'type' => 'text_default', 'label' => 'above', 'weight' => 10, ]) ->setDisplayConfigurable('view', TRUE); {% endif %} {% if author_base_field %} $fields['uid'] = BaseFieldDefinition::create('entity_reference') {% if revisionable %} ->setRevisionable(TRUE) {% endif %} {% if translatable %} ->setTranslatable(TRUE) {% endif %} ->setLabel(t('Author')) ->setSetting('target_type', 'user') ->setDefaultValueCallback(static::class . '::getDefaultEntityOwner') ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete', 'settings' => [ 'match_operator' => 'CONTAINS', 'size' => 60, 'placeholder' => '', ], 'weight' => 15, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('view', [ 'label' => 'above', 'type' => 'author', 'weight' => 15, ]) ->setDisplayConfigurable('view', TRUE); {% endif %} {% if created_base_field %} $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Authored on')) {% if translatable %} ->setTranslatable(TRUE) {% endif %} ->setDescription(t('The time that the {{ entity_type_label|lower }} was created.')) ->setDisplayOptions('view', [ 'label' => 'above', 'type' => 'timestamp', 'weight' => 20, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayOptions('form', [ 'type' => 'datetime_timestamp', 'weight' => 20, ]) ->setDisplayConfigurable('view', TRUE); {% endif %} {% if changed_base_field %} $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) {% if translatable %} ->setTranslatable(TRUE) {% endif %} ->setDescription(t('The time that the {{ entity_type_label|lower }} was last edited.')); {% endif %} return $fields; } {% endif %} }