Tripal
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage Class Reference
Inheritance diagram for Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage:
Inheritance graph
[legend]
Collaboration diagram for Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage:
Collaboration graph
[legend]

Public Member Functions

 __construct (array $configuration, $plugin_id, $plugin_definition, TripalLogger $logger, ChadoConnection $connection, ChadoFieldDebugger $field_debugger)
 
- Public Member Functions inherited from Drupal\tripal\TripalStorage\TripalStorageBase
 __construct (array $configuration, $plugin_id, $plugin_definition, TripalLogger $logger)
 
 getFieldDefinition (string $field_name)
 
 addTypes (string $field_name, array $types)
 
 getTypes ()
 
 getPropertyType (string $field_name, string $key)
 
 removeTypes (string $field_name, array $types)
 
 markPropertiesForCaching (string $field_name, array &$prop_types)
 
 publishFormValidate ($form, FormStateInterface &$form_state)
 
 publishFromSubmit ($form, FormStateInterface &$form_state)
 
- Public Member Functions inherited from Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface
 getStoredValues ()
 
 findValues ($values)
 

Static Public Member Functions

static create (ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 

Protected Attributes

 $connection
 
 $field_debugger
 
 $records = NULL
 
- Protected Attributes inherited from Drupal\tripal\TripalStorage\TripalStorageBase
 $logger
 
 $field_definitions = []
 
 $property_types = []
 
 $cached_fields = []
 
bool $default_is_required = TRUE
 
static drupalEntityIdLookupCallback ($context)
 
 addFieldDefinition (string $field_name, object $field_definition)
 
 getStoredTypes ()
 
 getNonStoredTypes ()
 
 isDrupalStoreByFieldNameKey (string $field_name, string $key, object|null $property_type=NULL)
 
 insertValues (&$values)
 
 updateValues (&$values)
 
 loadValues (&$values, bool $ignore_cached_fields=TRUE)
 
 deleteValues ($values)
 
 findValues ($values, array $main_property_names=[], array $record_ids=[], array $options=[])
 
 validateValues ($values)
 
 publishForm ($form, FormStateInterface &$form_state)
 
 findAllRecordIds (string $bundle_id)
 
 getStoredTypesFilter (bool $required)
 
 setPropValues (&$values, ChadoRecords $records)
 
 buildChadoRecords ($values, bool $is_find=FALSE, bool $ignore_cached=FALSE)
 
 handleStoreID (array $context, StoragePropertyValue $prop_value)
 
 handleStorePkey (array $context, StoragePropertyValue $prop_value)
 
 handleStoreLink (array $context, StoragePropertyValue $prop_value)
 
 handleStore (array $context, StoragePropertyValue $prop_value)
 
 handleReadValue (array $context, StoragePropertyValue $prop_value)
 
 parsePath (string $field_name, string $base_table, mixed $path, array $aliases=[], string $as='', string $full_path='',)
 
 getPathValueColumn (array $path)
 
 handleJoins (array &$path_array, array $context)
 

Additional Inherited Members

- Protected Member Functions inherited from Drupal\tripal\TripalStorage\TripalStorageBase
 cloneValues ($values)
 
 resetValuesItem (&$values, $field_name, $delta)
 

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::__construct ( array  $configuration,
  $plugin_id,
  $plugin_definition,
TripalLogger  $logger,
ChadoConnection  $connection,
ChadoFieldDebugger  $field_debugger 
)

Implements __construct().

Since we have implemented the ContainerFactoryPluginInterface, the constructor will be passed additional parameters added by the create() function. This allows our plugin to use dependency injection without our plugin manager service needing to worry about it.

Parameters
array$configurationThe configuration for this plugin instance.
string$plugin_idThe unique id for this plugin instance.
mixed$plugin_definitionThe definition for this plugin instance.
\Drupal\tripal\Services\TripalLogger$loggerThe logger to provide feedback to the admin.
\Drupal\tripal_chado\Database\ChadoConnection$connectionThe current connection to chado.
\Drupal\tripal_chado\Services\ChadoFieldDebugger$field_debuggerThe field debugger.

Member Function Documentation

◆ addFieldDefinition()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::addFieldDefinition ( string  $field_name,
object  $field_definition 
)

Add field definition for the current field.

inheritdoc}

Reimplemented from Drupal\tripal\TripalStorage\TripalStorageBase.

◆ buildChadoRecords()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::buildChadoRecords (   $values,
bool  $is_find = FALSE,
bool  $ignore_cached = FALSE 
)
protected

Indexes a values array for easy lookup.

Parameters
array$valuesAssociative array 5-levels deep. The 1st level is the field name (e.g. ncbitaxon__common_name). The 2nd level is the delta value (e.g. 0). The 3rd level is a field key name (i.e. record_id and value). The 4th level must contain the following three keys/value pairs
  • "value": a \Drupal\tripal\TripalStorage\StoragePropertyValue object
  • "type": a\Drupal\tripal\TripalStorage\StoragePropertyType object
  • "definition": a \Drupal\Field\Entity\FieldConfig object When the function returns, any values retrieved from the data store will be set in the StoragePropertyValue object.
bool$is_findSet to TRUE if we are building the record array for finding records.
bool$ignore_cachedIf this is set to TRUE then any values that are part of a field where all properties are cached in Drupal are not added to ChadoRecords.

◆ create()

static Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::create ( ContainerInterface  $container,
array  $configuration,
  $plugin_id,
  $plugin_definition 
)
static

Implements ContainerFactoryPluginInterface->create().

Since we have implemented the ContainerFactoryPluginInterface this static function will be called behind the scenes when a Plugin Manager uses createInstance(). Specifically this method is used to determine the parameters to pass to the constructor.

Parameters
\Symfony\Component\DependencyInjection\ContainerInterface$containerThe container for the current page load.
array$configurationConfiguration for the current plugin instance.
string$plugin_idUnique ID for the current plugin instance.
mixed$plugin_definitionThe definition for the current plugin instance.
Returns
static

Reimplemented from Drupal\tripal\TripalStorage\TripalStorageBase.

◆ deleteValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::deleteValues (   $values)

Delete values from Chado.

inheritdoc}

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ drupalEntityIdLookupCallback()

static Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::drupalEntityIdLookupCallback (   $context)
static

Looks up the Drupal entity ID for fields.

Parameters
array$contextValues that a callback function might need in order to calculate the field's final value.
Returns
int The Drupal entity ID, or -1 if it doesn't exist. We use -1 because Tripal preSave will flag a zero for deletion.

◆ findAllRecordIds()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::findAllRecordIds ( string  $bundle_id)

Returns a list of all pkey_id values for a given base table.

Parameters
string$bundle_idThe name of the bundle.
Returns
array List of pkey_id values in no particular order.

◆ findValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::findValues (   $values,
array  $main_property_names = [],
array  $record_ids = [],
array  $options = [] 
)

Find values in Chado based on a number of records.

Parameters
array$valuesAn array of values indicating which records to find in chado.
array$main_property_namesAssociative array where key is field name, value is name of the main property.
array$record_idsWhen specified, only return records where the primary key is present in this array. Used by publish to publish in batches.
array$options
  • global_max_delta = Maximum number of linked records from a single table to return, zero for no limit.
  • cardinalities = associative array of cardinalities on a per-table basis, key is table name. If present, these override global_max_delta.
  • inhibit = Publish no records if the number exceeds max_delta.

◆ getNonStoredTypes()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::getNonStoredTypes ( )

Returns a list of property types that should not be stored in Drupal.This is the inverse of the getStoredTypes() method. It's needed because all field property types have a column in the Drupal table. However, the "Stored" ones save the value both in Drupal and in the storage backend and the "unstored" ones save an empty value in Drupal that is populated on load by the storage backend.

Returns
array Array of \Drupal\tripal\Base\StoragePropertyTypeBase objects.

See also
\Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface::getNonStoredTypes()

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ getPathValueColumn()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::getPathValueColumn ( array  $path)
protected

A helper function to quickly get the value column information from a path.

Parameters
array$pathThe parsed path of the field property.

◆ getStoredTypes()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::getStoredTypes ( )

Returns a list of property types that should be stored.In order to link data in the storage backend, the storage system must link the record in someway with Drupal entities. This most likely happens in tables in the Drupal schema (usually the public schema). This function should return the list of properties that must be stored in order to uniquely identify an entity in the datastore.

Returns
array Array of \Drupal\tripal\Base\StoragePropertyTypeBase objects.

See also
\Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface::getStoredTypes()

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ getStoredTypesFilter()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::getStoredTypesFilter ( bool  $required)
protected

Helper function for getStoredTypes() and getNonStoredTypes().

Parameters
bool$requiredTRUE to return types that are required. FALSE to return types that are not required.
Returns
array Array of \Drupal\tripal\Base\StoragePropertyTypeBase objects.

◆ handleJoins()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleJoins ( array &  $path_array,
array  $context 
)
protected

A helper function for the buildChadoRecords() function.

Adds the joins to the ChadoRecord object.

Parameters
array$path_arrayThe join path array.
array$contextThe field/property context provided by the buildChadoRecords() function.

◆ handleReadValue()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleReadValue ( array  $context,
StoragePropertyValue  $prop_value 
)
protected

A helper function for the buildChadoRecords() function.

Add chado record information for a specific ChadoStorageProperty where the action is read_value.

READ_VALUE: selecting a single column. This cannot be used for inserting or updating values. Instead we use store actions for that. If reading a value from a non-base table, then the path should be provided.

Parameters
array$contextThe field/property context provided by the buildChadoRecords() function.
\Drupal\tripal\TripalStorage\StoragePropertyValue$prop_valueThe value object for the property we are adding records for. Note: We will always have a StoragePropertyValue for a property even if the value is not set. This method is expected to check if the value is empty or not.

◆ handleStore()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleStore ( array  $context,
StoragePropertyValue  $prop_value 
)
protected

A helper function for the buildChadoRecords() function.

Add chado record information for a specific ChadoStorageProperty where the action is store.

STORE: indicates that the value of this property can be loaded and stored in the Chado table indicated by this property.

Parameters
array$contextThe field/property context provided by the buildChadoRecords() function.
\Drupal\tripal\TripalStorage\StoragePropertyValue$prop_valueThe value object for the property we are adding records for. Note: We will always have a StoragePropertyValue for a property even if the value is not set. This method is expected to check if the value is empty or not.

◆ handleStoreID()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleStoreID ( array  $context,
StoragePropertyValue  $prop_value 
)
protected

A helper function for the buildChadoRecords() function.

Add chado record information for a specific ChadoStorageProperty where the action is store_id.

STORE ID: stores the primary key value for a core table in chado.

Note: There may be more core tables in properties for this field then just the base table. For example, a field involving a two-join linker table will include two core tables.

Parameters
array$contextThe field/property context provided by the buildChadoRecords() function.
\Drupal\tripal\TripalStorage\StoragePropertyValue$prop_valueThe value object for the property we are adding records for. Note: We will always have a StoragePropertyValue for a property even if the value is not set. This method is expected to check if the value is empty or not.

◆ handleStoreLink()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleStoreLink ( array  $context,
StoragePropertyValue  $prop_value 
)
protected

A helper function for the buildChadoRecords() function.

Add chado record information for a specific ChadoStorageProperty where the action is store_link.

STORE LINK: performs a join between two tables, one of which is a core table and one of which is a linking table. The value which is saved in this property is the left_table_id indicated in other key/value pairs.

NOTE: A JOIN is not added to the query but rather this property stores the id that a join would normally look up. This is much more performant.

Parameters
array$contextThe field/property context provided by the buildChadoRecords() function.
\Drupal\tripal\TripalStorage\StoragePropertyValue$prop_valueThe value object for the property we are adding records for. Note: We will always have a StoragePropertyValue for a property even if the value is not set. This method is expected to check if the value is empty or not.

◆ handleStorePkey()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::handleStorePkey ( array  $context,
StoragePropertyValue  $prop_value 
)
protected

A helper function for the buildChadoRecords() function.

Add chado record information for a specific ChadoStorageProperty where the action is store_pkey.

STORE PKEY: stores the primary key value of a linking table.

NOTE: A linking table is not a core table. This is important because during insert and update, the core tables are handled first and then linking tables are handled after.

Parameters
array$contextThe field/property context provided by the buildChadoRecords() function.
\Drupal\tripal\TripalStorage\StoragePropertyValue$prop_valueThe value object for the property we are adding records for. Note: We will always have a StoragePropertyValue for a property even if the value is not set. This method is expected to check if the value is empty or not.

◆ insertValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::insertValues ( $values)

Insert values into chado.

inheritdoc}

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ isDrupalStoreByFieldNameKey()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::isDrupalStoreByFieldNameKey ( string  $field_name,
string  $key,
object|null  $property_type = NULL 
)

Check if a single field property should be cached in the Drupal tables.This interacts with tripal_entity_type.default_cache_backend_field_values setting in the base implementation of this method.WARNING: This method should only be called after the property type for this field.key combo has been added.

Parameters
string$field_nameThe name of the field thhe property to check is part of.
string$keyThe storage property key to check.
object | null$property_typeAn instance of the propertyType to be checked. Optional. If not provided it will be looked up by the field name and key.
Returns
bool|null TRUE if it should be saved to the Drupal field table and FALSE otherwise. If an error is encountered then NULL is returned.

Reimplemented from Drupal\tripal\TripalStorage\TripalStorageBase.

◆ loadValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::loadValues ( $values,
bool  $ignore_cached_fields = TRUE 
)

Load values from Chado.

inheritdoc}

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ parsePath()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::parsePath ( string  $field_name,
string  $base_table,
mixed  $path,
array  $aliases = [],
string  $as = '',
string  $full_path = '' 
)
protected

Parses a field property path string into an array structure.

Parameters
string$field_nameThe name of the field.
string$base_tableThe name of the base table for thie field.
mixed$pathA string continaining the path. Note: this is a recursive function and on recursive calls this variable will be an array.
array$aliasesOptional. The list of table aliases provdied by the table_alias_mapping argument of a field. If this variable is an empty array then the function will use the table name provided in the path.
string$asAn alias to be used for the Chado table column that contains the value. This argument will rename the column.
string$full_pathThis argument is used by recursion to build the string path for each level. It should not be set by the callee.
Returns
array An array describing the path.

◆ publishForm()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::publishForm (   $form,
FormStateInterface &  $form_state 
)

Provides form elements to be added to the Tripal entity publish form.

Parameters
array$formThe form array definition.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state object.
Returns
array A new form array definition containing the form elements to add to the publish form.
See also
\Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterfacepublishForm()

See also
\Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface::publishForm()

Reimplemented from Drupal\tripal\TripalStorage\TripalStorageBase.

◆ setPropValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::setPropValues ( $values,
ChadoRecords  $records 
)
protected

Sets the property values using the records returned from Chado.

Parameters
array$valuesArray of \Drupal\tripal\TripalStorage\StoragePropertyValue objects.
\Drupal\tripal_chado\TripalStorage\ChadoRecords$recordsAn instance of a ChadoRecords object from which values will be pulled. We don't use the built in member variable and instead allow it to be passed in because the findValues() function can generate copies of the $records array and use that to set multiple values.

◆ updateValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::updateValues ( $values)

Update values in chado.

inheritdoc}

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.

◆ validateValues()

Drupal\tripal_chado\Plugin\TripalStorage\ChadoStorage::validateValues (   $values)

Performs validation checks on values.

Parameters
array$valuesArray of \Drupal\tripal\TripalStorage\StoragePropertyValue objects.
Returns
array An array of \Symfony\Component\Validator\ConstraintViolation objects.

Implements Drupal\tripal\TripalStorage\Interfaces\TripalStorageInterface.


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