protected function TransactorBase::buildTransactionFieldsForm in Transaction 8
Build configuration form fields to the transaction.
Parameters
array $form: The transaction type form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The form array.
1 call to TransactorBase::buildTransactionFieldsForm()
- TransactorBase::buildConfigurationForm in src/
TransactorBase.php - Provides a form for this transactor plugin settings.
File
- src/
TransactorBase.php, line 162
Class
- TransactorBase
- Provides a base class for transactor plugins.
Namespace
Drupal\transactionCode
protected function buildTransactionFieldsForm(array $form, FormStateInterface $form_state) {
if (!empty($this->pluginDefinition['transaction_fields'])) {
$form['transaction_fields'] = [
'#type' => 'details',
'#title' => $this
->t('Transaction fields'),
'#description' => $this
->t('Fields in the transaction entity used by this type of transaction.'),
'#open' => TRUE,
'#tree' => FALSE,
'#weight' => 10,
];
/** @var \Drupal\transaction\TransactionTypeInterface $transaction_type */
$transaction_type = $form_state
->getFormObject()
->getEntity();
$transactor_settings = $transaction_type
->getPluginSettings();
// Plugin field definitions.
foreach ($this->pluginDefinition['transaction_fields'] as $field) {
// Set transaction as the entity type in the field info.
$field['entity_type'] = 'transaction';
$field['settings'] = isset($field['settings']) ? $field['settings'] : [];
// Entity reference fields in the transaction entity with no target
// type in settings points to the target entity type.
if ($field['type'] == 'entity_reference' && !isset($field['settings']['target_type'])) {
$field['settings']['target_type'] = $transaction_type
->getTargetEntityTypeId();
$field['handler_settings']['target_bundles'] = $transaction_type
->getBundles(TRUE);
}
$form['transaction_fields'] += $this
->fieldReferenceSettingsFormField($field, isset($transactor_settings[$field['name']]) ? $transactor_settings[$field['name']] : NULL, $this
->getAvailableFields('transaction', $field['type'], [], $field['settings']));
$form_state
->setTemporaryValue('field_info_' . $field['name'], $field);
}
}
return $form;
}