View source
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\transaction\TransactionInterface;
function transaction_field_formatter_info_alter(array &$info) {
$info['string']['field_types'][] = 'transaction_description';
$info['string']['field_types'][] = 'transaction_details';
}
function transaction_entity_type_alter(array &$entity_types) {
$tabs = \Drupal::config('transaction.settings')
->get('tabs') ?: [];
foreach ($tabs as $tab) {
list($transaction_type_id, $target_entity_type_id) = explode('-', $tab);
$entity_types[$target_entity_type_id]
->setLinkTemplate("transaction-{$transaction_type_id}", "/transaction/{$transaction_type_id}/{$target_entity_type_id}/{{$target_entity_type_id}}");
}
}
function transaction_inline_entity_form_entity_form_alter(array $entity_form, FormStateInterface $form_state) {
if (\Drupal::moduleHandler()
->moduleExists('transaction_ief')) {
return $entity_form;
}
$entity = $entity_form['#entity'];
if ($entity instanceof TransactionInterface && !$entity
->getTargetEntityId()) {
$entity
->setTargetEntity(\Drupal::request()
->get($entity
->getType()
->getTargetEntityTypeId()));
}
return $entity_form;
}