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 between organisations') ->setRequired(TRUE); $fields['status']->setDescription(t('A boolean indicating whether the Organisation Relation is published.')) ->setDisplayOptions('form', [ 'type' => 'boolean_checkbox', 'weight' => -3, ]); $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('Organisations')) ->setDescription(t('Linked organisations')) ->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', ]) ->setDefaultValueCallback('opencase_entities_organisation_relation_callback') ->setRequired(TRUE); return $fields; } } function opencase_entities_organisation_relation_callback() { return [\Drupal::request()->query->get('organisation_id')]; }