getEntityTypeId()] = $this->uuid(); } return $uri_route_parameters; } /** * {@inheritdoc} */ public static function preCreate(EntityStorageInterface $storage_controller, array &$values) { parent::preCreate($storage_controller, $values); $values += array( 'user_id' => \Drupal::currentUser()->id(), ); } /** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); // Reindex the entity when it is updated. The entity is automatically // indexed when it is added, simply by being added to the {fedora_resource} table. // Only required if using the core search index. if ($update) { if (\Drupal::moduleHandler()->moduleExists('search')) { search_mark_for_reindex('fedora_resource_search', $this->id()); } } } /** * {@inheritdoc} */ public function getType() { return $this->bundle(); } /** * {@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 ? NODE_PUBLISHED : NODE_NOT_PUBLISHED); return $this; } /** * {@inheritdoc} */ public function hasParent() { return ($this->get('fedora_has_parent') !== null); } /** * {@inheritdoc} */ public function getParent() { return $this->get('fedora_has_parent')->getEntity(); } /** * {@inheritdoc} */ public function getParentId() { return $this->get('fedora_has_parent')->getEntity()->id(); } /** * {@inheritdoc} */ public function setParent(EntityTypeInterface $entity) { $this->set('fedora_has_parent', $entity); return $this; } /** * Default value callback for 'fedora_has_parent' base field definition. * * @see ::baseFieldDefinitions() * * @return array * An array of default values. */ public static function getFedoraRoot() { // Just stub code, we need to figure out what "root is" in this context return array('root'); } /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['id'] = BaseFieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the Fedora resource entity.')) ->setReadOnly(TRUE); $fields['vid'] = BaseFieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The Fedora resource revision ID.')) ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); $fields['type'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Type')) ->setDescription(t('The Fedora resource type/bundle.')) ->setSetting('target_type', 'fedora_resource_type') ->setRequired(TRUE); $fields['uuid'] = BaseFieldDefinition::create('uuid') ->setLabel(t('UUID')) ->setDescription(t('The UUID of the Fedora resource entity.')) ->setReadOnly(TRUE); $fields['user_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Authored by')) ->setDescription(t('The user ID of author of the Fedora resource entity.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId') ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'author', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ), )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['fedora_has_parent'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Fedora has Parent')) ->setDescription(t('Parent Fedora Resource.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'fedora_resource') ->setSetting('handler', 'default') ->setDefaultValueCallback('Drupal\islandora\Entity\FedoraResource::getFedoraRoot') ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'author', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ), )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['ldp_contains'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('LDP Contains')) ->setDescription(t('Contains Fedora Resource.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'fedora_resource_type') ->setSetting('handler', 'default') ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'author', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ), )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of the Fedora resource entity.')) ->setSettings(array( 'max_length' => 50, 'text_processing' => 0, )) ->setDefaultValue('') ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'string', 'weight' => -4, )) ->setDisplayOptions('form', array( 'type' => 'string_textfield', 'weight' => -4, )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Publishing status')) ->setDescription(t('A boolean indicating whether the Fedora resource is published.')) ->setDefaultValue(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') ->setLabel(t('Language code')) ->setDescription(t('The language code for the Fedora resource entity.')) ->setDisplayOptions('form', array( 'type' => 'language_select', 'weight' => 10, )) ->setDisplayConfigurable('form', 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['promote'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Promoted to front page')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDefaultValue(TRUE) ->setDisplayOptions('form', array( 'type' => 'boolean_checkbox', 'settings' => array( 'display_label' => TRUE, ), 'weight' => 15, )) ->setDisplayConfigurable('form', TRUE); $fields['sticky'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Sticky at top of lists')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDefaultValue(FALSE) ->setDisplayOptions('form', array( 'type' => 'boolean_checkbox', 'settings' => array( 'display_label' => TRUE, ), 'weight' => 16, )) ->setDisplayConfigurable('form', TRUE); $fields['revision_timestamp'] = BaseFieldDefinition::create('created') ->setLabel(t('Revision timestamp')) ->setDescription(t('The time that the current revision was created.')) ->setQueryable(FALSE) ->setRevisionable(TRUE); $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Revision user ID')) ->setDescription(t('The user ID of the author of the current revision.')) ->setSetting('target_type', 'user') ->setQueryable(FALSE) ->setRevisionable(TRUE); $fields['revision_log'] = BaseFieldDefinition::create('string_long') ->setLabel(t('Revision log message')) ->setDescription(t('Briefly describe the changes you have made.')) ->setRevisionable(TRUE) ->setDefaultValue('') ->setDisplayOptions('form', array( 'type' => 'string_textarea', 'weight' => 25, 'settings' => array( 'rows' => 4, ), )); $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Revision translation affected')) ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.')) ->setReadOnly(TRUE) ->setRevisionable(TRUE) ->setTranslatable(TRUE); return $fields; } }