Skip to content

Commit

Permalink
Merge pull request #1588 from tripal/7v4g1-1565-Remove_bio_data
Browse files Browse the repository at this point in the history
Remove 'bio_data' from Tripal
  • Loading branch information
spficklin committed Aug 9, 2023
2 parents d584796 + 0cc4704 commit 0ee074f
Show file tree
Hide file tree
Showing 27 changed files with 1,572 additions and 1,691 deletions.
2 changes: 1 addition & 1 deletion tripal/config/schema/tripal.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ tripal.tripalentitytype_collection.*:
type: string
label: "Category"
nullable: false
name:
id:
type: string
label: "A machine readable content type id (a.k.a., the bundle ID or Entity Type ID)"
nullable: false
Expand Down
7 changes: 2 additions & 5 deletions tripal/config/schema/tripal_entity_type.schema.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
tripal.bio_data.*:
tripal.content_type.*:
type: config_entity
label: 'Tripal Content Type'
mapping:
id:
type: integer
label: 'ID'
name:
type: string
label: 'Name'
label: 'ID'
label:
type: label
label: 'Label'
Expand Down
4 changes: 2 additions & 2 deletions tripal/js/tripal.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
*/
TripalAjaxField.prototype.attach = function () {
$.ajax({
url : baseurl + '/bio_data/ajax/field_attach/' + this.id,
url : baseurl + '/tripal/ajax/field_attach/' + this.id,
dataType: 'json',
type : 'GET',
success : this.setFieldContent.bind(this)
Expand Down Expand Up @@ -212,7 +212,7 @@ function tripal_navigate_field_pager(id, page) {
jQuery('#' + id + '-spinner').show();
jQuery.ajax({
type : 'GET',
url : Drupal.settings['basePath'] + 'bio_data/ajax/field_attach/' + id,
url : Drupal.settings['basePath'] + 'tripal/ajax/field_attach/' + id,
data : {'page': page},
success: function (response) {
jQuery('#' + id + ' .field-items').replaceWith(response['content']);
Expand Down
4 changes: 2 additions & 2 deletions tripal/src/Controller/TripalEntityUIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function tripalContentAddPage() {
$bundles[$category]['members'][] = [
'title' => $entity->getLabel(),
'help' => $entity->getHelpText(),
'url' => Url::fromRoute('entity.tripal_entity.add_form', ['tripal_entity_type' => $entity->getName()]),
'url' => Url::fromRoute('entity.tripal_entity.add_form', ['tripal_entity_type' => $entity->id()]),
];
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public function tripalContentAddPage() {
*/
public function tripalCheckForFields($tripal_entity_type) {

$bundle_name = $tripal_entity_type->getName();
$bundle_name = $tripal_entity_type->id();
$term = $tripal_entity_type->getTerm();

//$added = tripal_create_bundle_fields($bundle, $term);
Expand Down
41 changes: 13 additions & 28 deletions tripal/src/Entity/TripalEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\user\UserInterface;
use Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface;
use Drupal\field\Entity\FieldConfig;
use Symfony\Component\Routing\Route;


/**
Expand Down Expand Up @@ -47,12 +48,12 @@
* "status" = "status",
* },
* links = {
* "canonical" = "/bio_data/{tripal_entity}",
* "add-page" = "/bio_data/add",
* "add-form" = "/bio_data/add/{tripal_entity_type}",
* "edit-form" = "/bio_data/{tripal_entity}/edit",
* "delete-form" = "/bio_data/{tripal_entity}/delete",
* "collection" = "/admin/content/bio_data",
* "canonical" = "/tripal/{tripal_entity}",
* "add-page" = "/tripal/add",
* "add-form" = "/tripal/add/{tripal_entity_type}",
* "edit-form" = "/tripal/{tripal_entity}/edit",
* "delete-form" = "/tripal/{tripal_entity}/delete",
* "collection" = "/admin/content/tripal",
* },
* bundle_entity_type = "tripal_entity_type",
* field_ui_base_route = "entity.tripal_entity_type.edit_form"
Expand All @@ -69,7 +70,7 @@ class TripalEntity extends ContentEntityBase implements TripalEntityInterface {
* @code
$values = [
'title' => 'laceytest'.time(),
'type' => 'bio_data_1',
'type' => 'organism',
'uid' => 1,
];
$entity = \Drupal\tripal\Entity\TripalEntity::create($values);
Expand All @@ -79,7 +80,7 @@ class TripalEntity extends ContentEntityBase implements TripalEntityInterface {
* @param array $values
* - *title: the title of the entity.
* - *user_id: the user_id of the user who authored the content.
* - *type: the type of tripal entity this is (e.g. bio_data_1)
* - *type: the type of tripal entity this is (e.g. organism)
* - status: whether the entity is published or not (boolean)
* - created: the unix timestamp for when this content was created.
* @return object
Expand Down Expand Up @@ -153,35 +154,20 @@ public function getTitle() {
* The alias to use. It can contain tokens the correspond to field values.
* Token should be be compatible with those returned by
* tripal_get_entity_tokens().
* @param array $cache
* This array is used to store objects you want to cache for performance
* reasons, as well as, cache related options. The following are supported:
* - TripalEntityType $bundle
* The bundle for the current entity.
*/
public function setAlias($path_alias = NULL, $cache = []) {
public function setAlias($path_alias = NULL) {

$system_path = "/bio_data/" . $this->getID();
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();

$system_path = "/tripal/" . $this->getID();

// If no alias was supplied then we should try to generate one using the
// default format set by admins.
if (!$path_alias) {

// Load the TripalEntityType entity for this TripalEntity (if it's not
// cached). First get the format for the url alias based on the bundle
// of the entity. Then replace all the tokens with values from the entity fields.
if (isset($cache['bundle'])) {
$bundle = $cache['bundle'];
}
else {
$bundle = \Drupal\tripal\Entity\TripalEntityType::load($this->getType());
}

$bundle = \Drupal\tripal\Entity\TripalEntityType::load($this->getType());
$path_alias = $bundle->getURLFormat();
$path_alias = $this->replaceTokens($path_alias,
['tripal_entity_type' => $bundle]);

}

// Ensure there is a leading slash.
Expand All @@ -196,7 +182,6 @@ public function setAlias($path_alias = NULL, $cache = []) {
$path = \Drupal::entityTypeManager()->getStorage('path_alias')->create([
'path' => $system_path,
'alias' => $path_alias,
'langcode' => $langcode,
]);
$path->save();
}
Expand Down
62 changes: 12 additions & 50 deletions tripal/src/Entity/TripalEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@
* "html" = "Drupal\tripal\Routing\TripalEntityTypeHtmlRouteProvider",
* },
* },
* config_prefix = "bio_data",
* config_prefix = "content_type",
* admin_permission = "manage tripal content types",
* bundle_of = "tripal_entity",
* entity_keys = {
* "id" = "name",
* "id" = "id",
* "label" = "label",
* },
* links = {
* "canonical" = "/admin/structure/bio_data/{tripal_entity_type}",
* "add-form" = "/admin/structure/bio_data/add",
* "edit-form" = "/admin/structure/bio_data/manage/{tripal_entity_type}",
* "delete-form" = "/admin/structure/bio_data/manage/{tripal_entity_type}/delete",
* "collection" = "/admin/structure/bio_data"
* "canonical" = "/admin/structure/tripal/{tripal_entity_type}",
* "add-form" = "/admin/structure/tripal/add",
* "edit-form" = "/admin/structure/tripal/manage/{tripal_entity_type}",
* "delete-form" = "/admin/structure/tripal/manage/{tripal_entity_type}/delete",
* "collection" = "/admin/structure/tripal"
* },
* config_export = {
* "id",
* "name",
* "label",
* "termIdSpace",
* "termAccession",
Expand All @@ -67,13 +66,6 @@ class TripalEntityType extends ConfigEntityBundleBase implements TripalEntityTyp
*/
protected $id;

/**
* The Tripal Content machine name.
*
* @var string
*/
protected $name;

/**
* The Tripal Content type label.
*
Expand Down Expand Up @@ -207,15 +199,6 @@ public static function create(array $values = []) {
*/
public function save() {

// First we want to set an id for this content type.
if ($this->isNew()) {
$config = \Drupal::service('config.factory')->getEditable('tripal.settings');
$max_id = $config->get('tripal_entity_type.max_id');
$this->id = $max_id + 1;
$this->name = 'bio_data_' . $this->id;
$config->set('tripal_entity_type.max_id', $this->id)->save();
}

// Set defaults for anything not already set.
$this->setDefaults();

Expand All @@ -240,8 +223,8 @@ public function validate() {
if ($this->label === NULL) {
throw new \Exception("The label is required when creating a TripalEntityType.");
}
if ($this->name === NULL) {
throw new \Exception("The name is required when creating a TripalEntityType.");
if ($this->id === NULL) {
throw new \Exception("The id is required when creating a TripalEntityType.");
}
if ($this->help_text === NULL) {
throw new \Exception("The help text is required when creating a TripalEntityType.");
Expand Down Expand Up @@ -287,7 +270,7 @@ public function setDefaults() {
* {@inheritdoc}
*/
public function id() {
return $this->name;
return $this->id;
}

/**
Expand All @@ -297,27 +280,6 @@ public function getID() {
return $this->id;
}

/**
* {@inheritdoc}
*/
public function setID($id) {
$this->id = $id;
}

/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}

/**
* {@inheritdoc}
*/
public function setName($name) {
$this->name = $name;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -595,8 +557,7 @@ public function getTokens($options = []) {
'required' => TRUE,
];

$instances = \Drupal::service('entity_field.manager')
->getFieldDefinitions('tripal_entity', $this->name);
$instances = \Drupal::service('entity_field.manager')->getFieldDefinitions('tripal_entity', $this->id);
foreach ($instances as $instance_name => $instance) {

$use_field = TRUE;
Expand Down Expand Up @@ -718,4 +679,5 @@ public static function sortByCategory(TripalEntityTypeInterface $a, TripalEntity
return strnatcasecmp($b_value, $a_value);
}
}

}
37 changes: 0 additions & 37 deletions tripal/src/Entity/TripalEntityTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,6 @@
*/
interface TripalEntityTypeInterface extends ConfigEntityInterface {

/**
* Gets the index of the machine name (e.g. 1).
*
* @return string
* Index of the machine name of the Tripal Entity Type.
*/
public function getID();

/**
* Sets the index of the machine name.
*
* @param integer $id
* The index of the machine name of the Tripal Entity Type.
*
* @return \Drupal\tripal\Entity\TripalEntityTypeInterface
* The called Tripal Entity Type entity.
*/
public function setID($id);

/**
* Gets the machine name of the Tripal Entity Type (e.g. bio_data_1).
*
* @return string
* Machine name of the Tripal Entity Type.
*/
public function getName();

/**
* Sets the machine name of the Tripal Entity Type.
*
* @param string $name
* The machine name of the Tripal Entity Type.
*
* @return \Drupal\tripal\Entity\TripalEntityTypeInterface
* The called Tripal Entity Type entity.
*/
public function setName($name);

/**
* Gets the Tripal Entity Type label (e.g. gene).
Expand Down
2 changes: 1 addition & 1 deletion tripal/src/Form/TripalEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function save(array $form, FormStateInterface $form_state) {
$entity->setTitle($values['title'][0]['value']);
$entity->setOwnerId($values['uid'][0]['target_id']);
$status = parent::save($form, $form_state);
// $entity->setAlias();
$entity->setAlias();

switch ($status) {
case SAVED_NEW:
Expand Down

0 comments on commit 0ee074f

Please sign in to comment.