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 static function preCreate(EntityStorageInterface $storage_controller, array &$values) { parent::preCreate($storage_controller, $values); $values += [ 'user_id' => \Drupal::currentUser()->id(), ]; } /** * {@inheritdoc} */ public function setOwner(UserInterface $account) { $this->set('user_id', $account->id()); return $this; } /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); // Add the published field. $fields += static::publishedBaseFieldDefinitions($entity_type); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Entered by')) ->setDescription(t('The user ID of author of the Event entity.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setSetting('handler', 'default'); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of the Event entity.')) ->setSettings([ 'max_length' => 50, 'text_processing' => 0, ]) ->setDefaultValue('') ->setDisplayOptions('form', [ 'type' => 'string_textfield', 'weight' => -4, ]) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE) ->setRequired(TRUE); $fields['status']->setDescription(t('A boolean indicating whether the Event is published.')); $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.')); $fields['activity_date_time'] = BaseFieldDefinition::create('datetime') ->setLabel(t('Date and time')) ->setRevisionable(TRUE) ->setRequired(TRUE) // Uses the currentDateTime function from the Activity entity ->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCActivity::currentDateTime') ->setDisplayOptions('view', [ 'label' => 'above', 'type' => 'datetime_default', 'settings' => [ 'format_type' => 'medium', ], 'weight' => -3, ]) ->setDisplayOptions('form', [ 'type' => 'datetime_default', 'weight' => -3, ]); $fields['description'] = BaseFieldDefinition::create('string_long') ->setLabel(t('Description')) ->setRevisionable(TRUE) ->setSettings([ 'max_length' => 50, 'text_processing' => 0, ]) ->setDefaultValue('') ->setDisplayOptions('view', [ 'label' => 'above', 'type' => 'basic_string', 'weight' => -1, ]) ->setDisplayOptions('form', [ 'type' => 'string_textarea', 'weight' => -1, ]) ->setRequired(FALSE); $fields['attendees'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Attendees')) ->setDescription(t('People attending this event.')) ->setSetting('target_type', 'oc_actor') ->setSetting('handler', 'default') ->setTranslatable(TRUE) ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) ->setDisplayOptions('view', [ 'type' => 'string', 'weight' => 50, ]) ->setDisplayOptions('form', [ 'type' => 'entity_reference_autocomplete_tags', 'weight' => 50, ]) ->setRequired(FALSE); return $fields; } }