Tripal
Public Member Functions | Static Public 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=[])
 
 validate ($field_def)
 
 install (array $collection_ids)
 
 addBundleField ($field_def)
 

Static Public Member Functions

static create (ContainerInterface $container)
 

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 deafult 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 deafult 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

{}

◆ 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.

◆ 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.

◆ validate()

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

Validates a field definition array.

This function can be used to check a field definition prior to adding the field to a Tripal content type.

Parameters
array$field_defA definition array for the field.
Returns
bool True if the array passes validation checks. False otherwise.

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: