You are here

public function MappingEditForm::gcOptionIdsFieldExists in GatherContent 8.3

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 MappingEditForm::gcOptionIdsFieldExists()
MappingEditForm::automaticTermsGenerator in src/Form/MappingEditForm.php
Generate automatically terms for local field from GatherContent options.
MappingEditForm::submitForm in 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…

File

src/Form/MappingEditForm.php, line 1105

Class

MappingEditForm
Class MappingEditForm.

Namespace

Drupal\gathercontent\Form

Code

public function gcOptionIdsFieldExists($vid) {
  if ($this->entityTypeManager
    ->hasDefinition('taxonomy_term')) {
    $entityFieldManager = \Drupal::service('entity_field.manager');
    $definitions = $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();
    }
  }
}