Tripal
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Drupal\tripal\Services\TripalEntityLookup Class Reference

Public Member Functions

 getRenderableItem ($displayed_string, $entity_id)
 
 getEntityId ($record_id, $termIdSpace, $termAccession, $base_table=NULL, $entity_type='tripal_entity')
 
 getBundleLabel (int $entity_id, string $entity_type='tripal_entity')
 
 getPublishedEntityIds ($bundle_id, $entity_type='tripal_entity')
 

Protected Member Functions

 getBundleFromCvTerm ($termIdSpace, $termAccession)
 
 getBundles (string $base_table)
 
 getEntityIdFromRecordId ($record_id, $bundle_id, $entity_type)
 
 getRequiredFields ($bundle_id, $entity_type)
 

Protected Attributes

array $bundle_base_table_cache = []
 
array $bundle_label_cache = []
 

Detailed Description

This class provides functions to assist with finding a Drupal entity that corresponds to a Chado record.

The two public functions defined here are: getEntityId() which looks up a Drupal entity id from a Chado record id getRenderableItem() is a helper function for field formatters, it will handle converting an entity_id into a render array element.

Member Function Documentation

◆ getBundleFromCvTerm()

Drupal\tripal\Services\TripalEntityLookup::getBundleFromCvTerm (   $termIdSpace,
  $termAccession 
)
protected

Retrieve a Tripal bundle id based on its CV term.

Parameters
string$termIdSpaceThe bundle's CV Term namespace e.g. "NCIT"
string$termAccessionThe bundle's CV term accession e.g. "C47954"
Returns
string|null The bundle id, or null if no match found.

◆ getBundleLabel()

Drupal\tripal\Services\TripalEntityLookup::getBundleLabel ( int  $entity_id,
string  $entity_type = 'tripal_entity' 
)

Retrieve the human-readable type (i.e. TripalEntityType label) for a given TripalEntity object.

Parameters
int$entity_idThe TripalEntity ID value. This might be -1 for an unpublished entity.
string$entity_typeThe type of entity, only 'tripal_entity' is supported.
Returns
string The label, or an empty string if it could not be determined.

◆ getBundles()

Drupal\tripal\Services\TripalEntityLookup::getBundles ( string  $base_table)
protected

Retrieve a list of Tripal bundles for a given base table.

Parameters
string$base_tableThe table name e.g. "contact"
Returns
array The bundle ids, or an empty array if no matches found.

◆ getEntityId()

Drupal\tripal\Services\TripalEntityLookup::getEntityId (   $record_id,
  $termIdSpace,
  $termAccession,
  $base_table = NULL,
  $entity_type = 'tripal_entity' 
)

Retrieve a Drupal entity ID for a record in a given bundle given the bundle's CV term.

Parameters
int$record_idThe primary key value for the requested record
string$termIdSpaceThe bundle's CV Term namespace e.g. for gene "SO"
string$termAccessionThe bundle's CV term accession e.g. for gene "0000704" If IdSpace and Accession are NULL, then any bundle using the base table is checked.
string$base_tableThe Chado base table for the requested entity e.g. for gene "feature". Only needed if term does not map to a content type.
string$entity_typeThe type of entity, only 'tripal_entity' is supported.
Returns
int|null The Drupal entity ID, or null if no match found.

◆ getEntityIdFromRecordId()

Drupal\tripal\Services\TripalEntityLookup::getEntityIdFromRecordId (   $record_id,
  $bundle_id,
  $entity_type 
)
protected

Retrieve the pkey for an entity corresponding to a given record in a given table.

Parameters
int$record_idThe primary key value for the requested record in its base table.
string$bundle_idThe name of the drupal bundle, e.g. for base table 'arraydesign' it is 'array_design'
string$entity_typeThe type of entity, only 'tripal_entity' is supported.
Returns
array The id for the requested Drupal entity in the tripal_entity table. Will be an empty array if there was no corresponding entity. This can happen if the content is not published, or if this is not a content type. If a given record was published as more than one content type, the returned array may have more than one entity id. This would happen in Tripal 3, for example if an analysis is published as both "Analysis", and as "Genome Assembly".

◆ getPublishedEntityIds()

Drupal\tripal\Services\TripalEntityLookup::getPublishedEntityIds (   $bundle_id,
  $entity_type = 'tripal_entity' 
)

Find all published entities within a given bundle. Unfortunately the drupal entity API 'loadMultiple' function is too slow, taking a second or two per entity. We instead query the Drupal field tables directly, because we just want a simple list of two of the columns.

Parameters
string$bundle_idThe name of the drupal bundle, e.g. for base table 'arraydesign' it is 'array_design'
string$entity_typeThe type of entity, only 'tripal_entity' is supported.
Returns
array A list of all published entities in the bundle. The key will be the chado table record ID, the values will be the entity IDs.

◆ getRenderableItem()

Drupal\tripal\Services\TripalEntityLookup::getRenderableItem (   $displayed_string,
  $entity_id 
)

This is used by field formatters to get a ready-to-use render array item to link to an entity.

Parameters
string$displayed_stringThe text that will be displayed as a url link.
int$entity_idThe primary key value for the Drupal entity. We store -1 in the Drupal field tables to indicate when there is no Drupal entity because the TripalEntity class won't save a zero when drupal_store is TRUE.
Returns
array If a link is possible, then appropriate render array values to generate the link. If no link is possible, then appropriate render array values for simple markup.

◆ getRequiredFields()

Drupal\tripal\Services\TripalEntityLookup::getRequiredFields (   $bundle_id,
  $entity_type 
)
protected

Retrieve a list of required fields in a given bundle

Parameters
string$bundle_idThe name of the drupal bundle, e.g. 'analysis'
string$entity_typeThe type of entity, only 'tripal_entity' is supported.
Returns
array A list of required fields. Key is field name, value is base table.

Member Data Documentation

◆ $bundle_base_table_cache

array Drupal\tripal\Services\TripalEntityLookup::$bundle_base_table_cache = []
protected

Caches bundle IDs used for a base table

◆ $bundle_label_cache

array Drupal\tripal\Services\TripalEntityLookup::$bundle_label_cache = []
protected

Caches bundle information keyed by bundle machine ID


The documentation for this class was generated from the following file: