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

Public Member Functions

 __construct (TripalIdSpaceManager $idSpaceManager, TripalVocabularyManager $vocabularyManager, TripalLogger $logger)
 
 setFieldDefDefaults (array $field_def=[])
 
 install (array $collection_ids)
 
 addBundleField ($field_def)
 

Static Public Member Functions

static create (ContainerInterface $container)
 
static getFieldArrayFromFieldInstance (FieldConfig $instance)
 

Protected Member Functions

 updateFieldName (array $discovered_field)
 
 recheckTerms (array &$field_status, string $field_name)
 

Protected Attributes

 $idSpaceManager
 
 $vocabularyManager
 
 $logger
 

Detailed Description

Provides an tripalStorage plugin manager.

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal\Services\TripalFieldCollection::__construct ( TripalIdSpaceManager  $idSpaceManager,
TripalVocabularyManager  $vocabularyManager,
TripalLogger  $logger 
)

Constructor

Member Function Documentation

◆ addBundleField()

Drupal\tripal\Services\TripalFieldCollection::addBundleField (   $field_def)

Adds a field to a Tripal entity type.

Parameters
string$bundleThe bundle name (e.g. organism).
array$field_defAn associative array providing the necessary information about a field instance for this entity type. The following key/values are supported
  • name: (string) The machine-readable name for this field.
  • content_type: (string) The machine-readable name of the content type.
  • type: (string) The field type
  • label: (string) The default label for the field.
  • idSpace: (string) The name of the ID space for this field.
  • term: (string) The controlled vocabulary term accession for this field.
  • required: (bool) True if the field is required. False otherwise. If not set then defaults to False.
  • cardinality: (int) Set to -1 for unlimited or any number.
  • storage_settings: (array) An array of settings specific to storage by the storage back-end. It must contain the following keys:
    • storage_plugin_id: the name of the storage plugin (e.g. 'chado_storage').
    • storage_plugin_setings: an array of any settings that the storage plugin expects for the field.
  • settings: (array) Any other settings needed for the field. Every field can have different settings.
  • display: Provides details for display of the field. By default it should provide the following keys:
    • view: an array of settings for the "view" display. The keys of this array should be the names of the available view modes. By default it should always provide a 'default' key. Each display mode can then have the following key/value pairs:
      • weight: indicates the weight (or position) of the field in the display.
      • region: the name of the region where the field should be placed. By default there are two regions: 'content' or 'hidden'. If the field should not be visible by default use 'hidden'.
      • label: indicates where on the page the field label should be placed in relationship to the value. Valid values include 'above', 'inline' or 'hidden'.
    • form: an array of settings for the "form" display. The keys of this array should be the names of the available form modes. By default it should always provide a 'default' key. Each display mode can then have the following key/value pairs:
      • weight: indicates the weight (or position) of the field in the display.
      • region: the name of the region where the field should be placed. By default there are two regions: 'content' or 'hidden'. If the field should not be visible by default use 'hidden'.

An example field defintion:

$fields_service = \Drupal::service('tripal.fields');
$field_def = [
'name' => 'organism_genus',
'content_type' => 'organism',
'label' => 'Genus',
'type' => 'tripal_string_type',
'description' => "The genus name of the organism.",
'cardinality' => 1,
'required' => TRUE,
'storage_settings' => [
'storage_plugin_id' => 'drupal_sql_storage',
'storage_plugin_settings'=> [
],
'max_length' => 255,
],
'settings' => [
'termIdSpace' => 'TAXRANK',
'termAccession' => "0000005",
],
'display' => [
'view' => [
'default' => [
'region' => 'content',
'label' => 'above',
'weight' => 15
],
],
'form' => [
'default'=> [
'region'=> 'content',
'weight' => 15
],
],
],
];
$fields_service->addBundleField($field_def);
Returns
bool True if the field was added successfully. False otherwise.

◆ create()

static Drupal\tripal\Services\TripalFieldCollection::create ( ContainerInterface  $container)
static

{}

◆ getFieldArrayFromFieldInstance()

static Drupal\tripal\Services\TripalFieldCollection::getFieldArrayFromFieldInstance ( FieldConfig  $instance)
static

Provides a compatible array for a field based on it's Field Config.

This is to be used in the discover process to add existing fields to the field list in a standardized way.

Parameters
FieldConfig$instanceThe existing field to generate an array for so it can be added to the field list as an existing field.
Returns
array An array which matches the form expected to be a single item in the discover method.

◆ install()

Drupal\tripal\Services\TripalFieldCollection::install ( array  $collection_ids)

Attaches fields to Tripal content types.

Parameters
array$collection_idsAn array of the collection 'id' you would like to install.

◆ recheckTerms()

Drupal\tripal\Services\TripalFieldCollection::recheckTerms ( array &  $field_status,
string  $field_name 
)
protected

If a new field's name conflicts with an existing one, update the new field's name to eliminate the duplication.

Parameters
array&$field_statusHolds the status of each field. Will be updated if necessary.
string$field_nameName of one existing field to check against
Returns
void

◆ setFieldDefDefaults()

Drupal\tripal\Services\TripalFieldCollection::setFieldDefDefaults ( array  $field_def = [])

Adds default values for keys in the field definition array.

This function will only add defaults if the value is not already present in the $field_def array. You can retrieve a fully populated definition array, with defaults, by not passing an argument. This function will remove any keys in the definition array that are not supported.

Returns
array $field_def Optional. A field definition array to which any default values should be added.

◆ updateFieldName()

Drupal\tripal\Services\TripalFieldCollection::updateFieldName ( array  $discovered_field)
protected

Updates a field name if it is already used for a different field.

Parameters
string$discovered_fieldCurrent field with duplicated name
Returns
string The updated field name

Member Data Documentation

◆ $idSpaceManager

Drupal tripal TripalVocabTerms PluginManagers TripalIdSpaceManager Drupal\tripal\Services\TripalFieldCollection::$idSpaceManager
protected

The IdSpace service

◆ $logger

TripalLogger Drupal\tripal\Services\TripalFieldCollection::$logger
protected

A logger object.

◆ $vocabularyManager

Drupal tripal TripalVocabTerms PluginManagers TripalVocabularyManager Drupal\tripal\Services\TripalFieldCollection::$vocabularyManager
protected

The vocabulary service


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