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

Public Member Functions

 fieldSettingsForm (array $form, FormStateInterface $form_state)
 
 storageSettingsForm (array &$form, FormStateInterface $form_state, $has_data)
 
 tripalStorageId ()
 
 tripalSave ($field_item, $field_name, $prop_types, $prop_values, $entity)
 
 tripalLoad ($field_item, $field_name, $prop_types, $prop_values, $entity)
 
 tripalClear ($field_item, $field_name, $prop_types, $prop_values, $entity)
 
 sanitizeKey ($key)
 
 tripalValuesTemplate ($field_definition, $default_value=NULL)
 
 getFieldMaxDelta ()
 

Static Public Member Functions

static defaultFieldSettings ()
 
static defaultStorageSettings ()
 
static buildVocabularyTermTable (array &$elements, TripalTerm $term, TripalIdSpaceBase $idSpace, TripalVocabularyBase $vocabulary,)
 
static buildFieldTermForm ($field, $form, FormStateInterface $form_state)
 
static fieldSettingsFormValidate (array $form, FormStateInterface $form_state)
 
static propertyDefinitions (FieldStorageDefinitionInterface $field_definition)
 
static schema (FieldStorageDefinitionInterface $field_definition)
 
static getFormStateSettings (FormStateInterface $form_state)
 
static discover (TripalEntityType $bundle, string $field_id, array $field_types, array $field_instances)
 
static generateFieldName (TripalEntityType $bundle, string $extra, int $cvterm_id=0)
 
- Static Public Member Functions inherited from Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface
static tripalTypes ($field_definition)
 

Detailed Description

Defines the Tripal field item base class.

Member Function Documentation

◆ buildFieldTermForm()

static Drupal\tripal\TripalField\TripalFieldItemBase::buildFieldTermForm (   $field,
  $form,
FormStateInterface  $form_state 
)
static

Provides the form for setting a cv term on a field.

Parameters
$field
array$form
\Drupal\Core\Form\FormStateInterface$form_state

◆ buildVocabularyTermTable()

static Drupal\tripal\TripalField\TripalFieldItemBase::buildVocabularyTermTable ( array &  $elements,
TripalTerm  $term,
TripalIdSpaceBase  $idSpace,
TripalVocabularyBase  $vocabulary 
)
static

A helper function for the fieldSettingsForm.

Builds the table the describes the term assigned to the field.

Parameters
array$elements
\Drupal\tripal\TripalVocabTerms\TripalTerm$term
\Drupal\tripal\TripalVocabTerms\TripalIdSpaceBase$idSpace
\Drupal\tripal\TripalVocabTerms\TripalVocabularyBase$vocabulary

◆ defaultFieldSettings()

static Drupal\tripal\TripalField\TripalFieldItemBase::defaultFieldSettings ( )
static

{}

Reimplemented in Drupal\tripal\Plugin\Field\FieldType\TripalBooleanTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalIntegerTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalStringTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalTextTypeItem, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAdditionalTypeTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAnalysisTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoArrayDesignTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAssayTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoBiomaterialTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoContactByRoleTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoContactTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoDbxrefTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoFeatureMapTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoFeatureTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoOrganismTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoProjectTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoPropertyTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoProtocolTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoRelationshipTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceChecksumTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceCoordinatesDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceLengthTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSourceDataTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStockTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStringTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStudyTypeDefault, and Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSynonymTypeDefault.

◆ defaultStorageSettings()

static Drupal\tripal\TripalField\TripalFieldItemBase::defaultStorageSettings ( )
static

{}

Reimplemented in Drupal\tripal\Plugin\Field\FieldType\TripalBooleanTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalIntegerTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalStringTypeItem, Drupal\tripal\Plugin\Field\FieldType\TripalTextTypeItem, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAdditionalTypeTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAnalysisTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoArrayDesignTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoAssayTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoBiomaterialTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoBooleanTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoContactByRoleTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoContactTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoDbxrefTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoFeatureMapTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoFeatureTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoIntegerTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoOrganismTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoProjectTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoPropertyTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoProtocolTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoRelationshipTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceChecksumTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceCoordinatesDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceLengthTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSequenceTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSourceDataTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStockTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStringTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoStudyTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoSynonymTypeDefault, Drupal\tripal_chado\Plugin\Field\FieldType\ChadoTextTypeDefault, and Drupal\tripal_chado\TripalField\ChadoFieldItemBase.

◆ discover()

static Drupal\tripal\TripalField\TripalFieldItemBase::discover ( TripalEntityType  $bundle,
string  $field_id,
array  $field_types,
array  $field_instances 
)
static

Finds new instances of this field for a given content type.Fields are added to Tripal using the tripal.tripalfield_collection.* configuration file during installation of a module. In some cases, however, not all possible instances of a field can be added to a content type at installation of the module. This function can be called to discover if new instances of a field are appropriate for a given content type. An example of this is the chado_property_type_default field. This function should examine its storage backend and return a list of new fields instances that could be added to the content type (i.e., bundle).

Parameters
\Drupal\tripal\Entity\TripalEntityType$bundleThe entity type object for which new field instances should be found.
string$field_idThe id of the field.
array$field_typesAn array where each item defines a field type that is attached to this bundle. Each item is itself an array of the annotation defined at the top of that particular field type class.
array$field_instancesAn array of FieldConfig objects where each object defines a field attached to this content type. This differs from $field_types in that (1) there will be multiple entries if there a multiple instances of a single field type and (2) it includes the specific settings needed to create the field. As such, the FieldConfig object can be used to add existing fields to the field list returned by this method.
Returns
array An associative array that follows the same structure as expected by tripal.tripalfield_collection.* configuration.

See also
\Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface::discover()

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.

Reimplemented in Drupal\tripal_test\Plugin\Field\FieldType\TripalTestTextTypeItem.

◆ fieldSettingsForm()

Drupal\tripal\TripalField\TripalFieldItemBase::fieldSettingsForm ( array  $form,
FormStateInterface  $form_state 
)

◆ fieldSettingsFormValidate()

static Drupal\tripal\TripalField\TripalFieldItemBase::fieldSettingsFormValidate ( array  $form,
FormStateInterface  $form_state 
)
static

Form element validation handler.

Parameters
array$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state of the (entire) configuration form.

◆ generateFieldName()

static Drupal\tripal\TripalField\TripalFieldItemBase::generateFieldName ( TripalEntityType  $bundle,
string  $extra,
int  $cvterm_id = 0 
)
static

A helper function to create an appropriate field name.

This function can be used by a field's discover() method to generate an appropriate field name. It will always include the bundle type as the prefix, followed by an underscore, followed by extra text provided. It ensures that only alphanumeric values are present in the name and that it doesn't exceed Drupal's maximum length.

Parameters

Drupal\tripal\Entity\TripalEntityType TripalEntityType $bundle The TripalEntityType object with information about the bundle.

Parameters
string$extraExtra text to add to the field name after the bundle name.
int$cvterm_idThe cvterm_id value, only used when we need to truncate a long name. You may leave this set to the default of zero if the cvterm_id is not readily available, in which case a random unique ID is used, however we recommend using the actual cvterm_id if it is available so that the field name generated is predictable and reproducible.
Returns
string The generated field name.

◆ getFieldMaxDelta()

Drupal\tripal\TripalField\TripalFieldItemBase::getFieldMaxDelta ( )

Retrieve the max delta value specific to this field.

Returns
int The max delta value specific to this field.

◆ getFormStateSettings()

static Drupal\tripal\TripalField\TripalFieldItemBase::getFormStateSettings ( FormStateInterface  $form_state)
static

Returns the settings from the form state.

Under Drupal ~10.2 the settings array is located in a subform. This function will figure out where it is, and return it.

Parameters
\Drupal\Core\Form\FormStateInterface$form_stateThe form state of the (entire) configuration form.
Returns
array The settings array

◆ propertyDefinitions()

static Drupal\tripal\TripalField\TripalFieldItemBase::propertyDefinitions ( FieldStorageDefinitionInterface  $field_definition)
static

{}

◆ sanitizeKey()

Drupal\tripal\TripalField\TripalFieldItemBase::sanitizeKey (   $key)

Sanitizes a property key.

Property keys are often controlled vocabulary IDs, which is the IdSpace and accession separated by a colon. The colon is not supported by the storage backend and must be converted to an underscore. This function performs that task.

Parameters
string$key
Returns
string A sanitizied string.

◆ schema()

static Drupal\tripal\TripalField\TripalFieldItemBase::schema ( FieldStorageDefinitionInterface  $field_definition)
static

{}

◆ storageSettingsForm()

Drupal\tripal\TripalField\TripalFieldItemBase::storageSettingsForm ( array &  $form,
FormStateInterface  $form_state,
  $has_data 
)

◆ tripalClear()

Drupal\tripal\TripalField\TripalFieldItemBase::tripalClear (   $field_item,
  $field_name,
  $prop_types,
  $prop_values,
  $entity 
)

{Clears all field values from the given entity.This is to prevent Drupal from storing field values when they are being stored in the Tripal field storage backend.

Parameters
\Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface$field_itemThe field item for which properties should be saved.
string$field_nameThe name of the field.
array$prop_typesArray of \Drupal\tripal\TripalStorage\StoragePropertyType objects.
array$prop_valuesArray of \Drupal\tripal\TripalStorage\StoragePropertyValue objects.
\Drupal\tripal\TripalStorage\TripalEntityBase$entityThe entity.
}

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.

◆ tripalLoad()

Drupal\tripal\TripalField\TripalFieldItemBase::tripalLoad (   $field_item,
  $field_name,
  $prop_types,
  $prop_values,
  $entity 
)

{Loads the values from the given array of properties to the given entity.

Parameters
\Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface$field_itemThe field item for which properties should be saved.
string$field_nameThe name of the field.
array$prop_typesArray of \Drupal\tripal\TripalStorage\StoragePropertyType objects.
array$prop_valuesArray of \Drupal\tripal\TripalStorage\StoragePropertyValue objects.
\Drupal\tripal\TripalStorage\TripalEntityBase$entityThe entity.
}

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.

◆ tripalSave()

Drupal\tripal\TripalField\TripalFieldItemBase::tripalSave (   $field_item,
  $field_name,
  $prop_types,
  $prop_values,
  $entity 
)

{Saves the values to the given array of properties from the given entity.

Parameters
\Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface$field_itemThe field item for which properties should be saved.
string$field_nameThe name of the field.
array$prop_typesArray of \Drupal\tripal\TripalStorage\StoragePropertyType objects.
array$prop_valuesArray of \Drupal\tripal\TripalStorage\StoragePropertyValue objects.
\Drupal\tripal\TripalStorage\TripalEntityBase$entityThe entity.
}

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.

◆ tripalStorageId()

Drupal\tripal\TripalField\TripalFieldItemBase::tripalStorageId ( )

{Returns the tripal storage plugin id for this field.

Returns
string The tripal storage plugin id.
}

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.

◆ tripalValuesTemplate()

Drupal\tripal\TripalField\TripalFieldItemBase::tripalValuesTemplate (   $field_definition,
  $default_value = NULL 
)

{Returns an array of StoragePropertyValue objects.This array seves as as "template" for loading, storing and finding fields in the underlying data store. Each fiels' property types will have a corresponding value in this array. If the $default_value is provided then the property whose key is returend by the mainPropertyName() function will get set.Fields normally do not need to implement this function. However, if the $default_value argument is used and the default value is not the value stored in the underlying datastore (e.g., the value is a combination of all of the property values), then the implementing function can override this function to split the value and set the values for the other properties.

Parameters
object$field_definitionThe field configuration object. This can be an instance of: \Drupal\field\Entity\FieldStorageConfig or \Drupal\field\Entity\FieldConfig
$default_valueOptional. If a value is provided then then the property whose key is returned by the mainPropertyName() function will get set to the value provided.
Returns
array Array of \Drupal\tripal\TripalStorage\StoragePropertyValue property value templates.
}

Implements Drupal\tripal\TripalField\Interfaces\TripalFieldItemInterface.


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