getEntityTypeId(); } } /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['id'] = BaseFieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the test entity.')) ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); $fields['uuid'] = BaseFieldDefinition::create('uuid') ->setLabel(t('UUID')) ->setDescription(t('The UUID of the test entity.')) ->setReadOnly(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') ->setLabel(t('Language code')) ->setDescription(t('The language code of the test entity.')); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of the test entity.')) ->setTranslatable(TRUE) ->setSetting('max_length', 32) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'string', 'weight' => -5, )) ->setDisplayOptions('form', array( 'type' => 'string_textfield', 'weight' => -5, )); // @todo: Add allowed values validation. $fields['type'] = BaseFieldDefinition::create('string') ->setLabel(t('Type')) ->setDescription(t('The bundle of the test entity.')) ->setRequired(TRUE); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The ID of the associated user.')) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') // Default EntityTest entities to have the root user as the owner, to // simplify testing. ->setDefaultValue(array(0 => array('target_id' => 1))) ->setTranslatable(TRUE) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'weight' => -1, 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ), )); return $fields; } /** * {@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; } /** * Sets the name. * * @param string $name * Name of the entity. * * @return $this */ public function setName($name) { $this->set('name', $name); return $this; } /** * Returns the name. * * @return string */ public function getName() { return $this->get('name')->value; } }