\Drupal::currentUser()->id(), ]; } /** * {@inheritdoc} */ public function getName() { return $this->get('name')->value; } /** * {@inheritdoc} */ public function setName($name) { $this->set('name', $name); return $this; } /** * {@inheritdoc} */ public function getCreatedTime() { return $this->get('created')->value; } /** * {@inheritdoc} */ public function setCreatedTime($timestamp) { $this->set('created', $timestamp); return $this; } /** * {@inheritdoc} */ public function getOwner() { return $this->get('user_id')->entity; } /** * {@inheritdoc} */ public function getOwnerId() { return $this->get('user_id')->target_id; } /** * {@inheritdoc} */ public function setOwnerId($uid) { $this->set('user_id', $uid); return $this; } /** * {@inheritdoc} */ public function setOwner(UserInterface $account) { $this->set('user_id', $account->id()); return $this; } /** * {@inheritdoc} */ public function isPublished() { return (bool) $this->getEntityKey('status'); } /** * {@inheritdoc} */ public function setPublished($published) { $this->set('status', $published ? TRUE : FALSE); return $this; } /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Authored by')) ->setDescription(t('The user ID of the author.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') ->setTranslatable(TRUE); # ->setDisplayOptions('form', [ # 'type' => 'entity_reference_autocomplete', # 'weight' => 5, # 'settings' => [ # 'match_operator' => 'CONTAINS', # 'size' => '60', # 'autocomplete_type' => 'tags', # 'placeholder' => '', # ], # ]); // This field is always implied from the context, // so has no form or view display. $fields['person'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Person')) ->setDescription(t('The person this hat is of.')) ->setSetting('target_type', 'person'); $fields['contact_details'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Contact Details to use for this Hat')) ->setDescription(t('The contact details to be used when communicating with this person in this capacity.')) ->setSetting('target_type', 'contact_details') ->setSetting('handler', 'views') ->setSetting('handler_settings', ['view' => [ 'view_name' => 'this_person_s_contact_details', 'display_name' => 'entity_reference_1' ]]) ->setDisplayOptions('view', [ 'label' => 'above', 'weight' => 100, 'settings' => ['link' => 'false'] ]) ->setDisplayOptions('form', [ 'type' => 'options_buttons', 'weight' => 0, ]) ->setRequired(TRUE) ->setTranslatable(TRUE); // This field is computed in a presave hook, and used for entity reference // options when selecting a person for involvement in a case etc. $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of this hat instance as it appears in entity reference fields.')); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Publishing status')) ->setDescription(t('A boolean indicating whether the Hat is published.')) # ->setDisplayOptions('form', [ # 'type' => 'boolean_checkbox', # 'weight' => -3, # ]) ->setDefaultValue(TRUE); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) ->setDescription(t('The time that the entity was created.')); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the entity was last edited.')); return $fields; } }