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 static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields = parent::baseFieldDefinitions($entity_type); // Add the published field. $fields += static::publishedBaseFieldDefinitions($entity_type); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of the Organisation Relation entity.')) ->setSettings([ 'max_length' => 50, 'text_processing' => 0, ]) ->setDefaultValue('Link') ->setRequired(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.')); $fields['organisations'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Organisation to Link To')) ->setSetting('target_type', 'oc_organisation') ->setSetting('handler', 'default') ->setCardinality(2) ->setDisplayOptions('form', [ 'label' => 'above', 'type' => 'entity_reference_autocomplete', 'weight' => -2, 'settings' => [ 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ], ]) ->setDisplayOptions('view', [ 'label' => 'above', ]) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE) ->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCOrganisationRelation::defaultValueCallback') ->setRequired(TRUE); return $fields; } function defaultValueCallback() { return [\Drupal::request()->query->get('organisation_id')]; } }