You are here

protected function TransactorBase::createFieldConfig in Transaction 8

Creates a field config.

Parameters

string $field_name: The field name.

array $field_info: The field info array as defined in the transactor plugin.

string $bundle: The bundle.

string $label: The field label.

string $transaction_type_id: The transaction type ID.

Return value

\Drupal\field\Entity\FieldConfig The created field config object.

1 call to TransactorBase::createFieldConfig()
TransactorBase::submitConfigurationForm in src/TransactorBase.php
Handles the settings form submit for this transactor plugin.

File

src/TransactorBase.php, line 585

Class

TransactorBase
Provides a base class for transactor plugins.

Namespace

Drupal\transaction

Code

protected function createFieldConfig($field_name, array $field_info, $bundle, $label, $transaction_type_id) {

  // Set the new transaction type id in reference fields to this
  // transaction type.
  $handler_settings = isset($field_info['handler_settings']) ? $field_info['handler_settings'] : [];
  if (isset($handler_settings['target_bundles'])) {
    foreach ($handler_settings['target_bundles'] as $target_bundle_key => $target_bundle) {
      if ($target_bundle === NULL) {
        $handler_settings['target_bundles'][$target_bundle_key] = $transaction_type_id;
      }
    }
  }

  // Attach to bundle.
  $new_field = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => $field_info['entity_type'],
    'bundle' => $bundle,
    'label' => $label,
    'settings' => [
      'handler' => 'default',
      'handler_settings' => $handler_settings,
    ],
    'required' => $field_info['required'],
  ]);
  $new_field
    ->save();
  return $new_field;
}