You are here

public function MappingEditFormBase::gcOptionIdsFieldExists in GatherContent 8.5

Same name and namespace in other branches
  1. 8.4 gathercontent_ui/src/Form/MappingEditFormBase.php \Drupal\gathercontent_ui\Form\MappingEditFormBase::gcOptionIdsFieldExists()

Validate if gathercontent_option_ids field exists on specified vocabulary.

If field doesn't exists, create it for specified vocabulary.

Parameters

string $vid: Taxonomy vocabulary identifier.

2 calls to MappingEditFormBase::gcOptionIdsFieldExists()
MappingEditForm::submitForm in gathercontent_ui/src/Form/MappingEditForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…
MappingEditFormBase::automaticTermsGenerator in gathercontent_ui/src/Form/MappingEditFormBase.php
Generate automatically terms for local field from GatherContent options.

File

gathercontent_ui/src/Form/MappingEditFormBase.php, line 301

Class

MappingEditFormBase
Class MappingEditFormBase.

Namespace

Drupal\gathercontent_ui\Form

Code

public function gcOptionIdsFieldExists($vid) {
  if ($this->entityTypeManager
    ->hasDefinition('taxonomy_term')) {
    $definitions = $this->entityFieldManager
      ->getFieldStorageDefinitions('taxonomy_term');
    if (!isset($definitions['gathercontent_option_ids'])) {
      FieldStorageConfig::create([
        'field_name' => 'gathercontent_option_ids',
        'entity_type' => 'taxonomy_term',
        'type' => 'string',
        'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
        'locked' => TRUE,
        'persist_with_no_fields' => TRUE,
        'settings' => [
          'is_ascii' => FALSE,
          'case_sensitive' => FALSE,
        ],
      ])
        ->save();
    }
    $field_config = FieldConfig::loadByName('taxonomy_term', $vid, 'gathercontent_option_ids');
    if (is_null($field_config)) {
      FieldConfig::create([
        'field_name' => 'gathercontent_option_ids',
        'entity_type' => 'taxonomy_term',
        'bundle' => $vid,
        'label' => 'GatherContent Option IDs',
      ])
        ->save();
    }
  }
}