You are here

class TransactionInlineForm in Transaction 8

Defines the inline form for the transaction entity.

Hierarchy

Expanded class hierarchy of TransactionInlineForm

1 file declares its use of TransactionInlineForm
transaction_ief.module in modules/transaction_ief/transaction_ief.module

File

modules/transaction_ief/src/Form/TransactionInlineForm.php, line 18

Namespace

Drupal\transaction_ief\Form
View source
class TransactionInlineForm extends EntityInlineForm {

  /**
   * The route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Constructs the inline entity form controller.
   *
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, EntityTypeInterface $entity_type, RouteMatchInterface $route_match, RequestStack $request_stack) {
    parent::__construct($entity_field_manager, $entity_type_manager, $module_handler, $entity_type);
    $this->routeMatch = $route_match;
    $this->requestStack = $request_stack;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($container
      ->get('entity_field.manager'), $container
      ->get('entity_type.manager'), $container
      ->get('module_handler'), $entity_type, $container
      ->get('current_route_match'), $container
      ->get('request_stack'));
  }

  /**
   * {@inheritdoc}
   */
  public function entityForm(array $entity_form, FormStateInterface $form_state) {

    /** @var \Drupal\transaction\TransactionInterface $transaction */
    $transaction = $entity_form['#entity'];

    // Discover the target entity by examining the current route or by getting
    // from the request argument with the same name as the target entity type.
    if (!$transaction
      ->getTargetEntityId()) {
      $route_options = $this->routeMatch
        ->getRouteObject()
        ->getOptions();
      $target_entity_type_id = isset($route_options['_transaction_target_entity_type_id']) ? $route_options['_transaction_target_entity_type_id'] : $transaction
        ->getType()
        ->getTargetEntityTypeId();
      if ($target_entity = $this->requestStack
        ->getCurrentRequest()
        ->get($target_entity_type_id)) {
        $transaction
          ->setTargetEntity($target_entity);
      }
    }
    return parent::entityForm($entity_form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityInlineForm::$entityFieldManager protected property The entity field manager.
EntityInlineForm::$entityType protected property The entity type managed by this handler.
EntityInlineForm::$entityTypeManager protected property The entity type manager.
EntityInlineForm::$moduleHandler protected property Module handler service.
EntityInlineForm::buildEntity protected function Builds an updated entity object based upon the submitted form values.
EntityInlineForm::delete public function Delete permanently saved entities. Overrides InlineFormInterface::delete
EntityInlineForm::entityFormSubmit public function Handles the submission of an entity form. Overrides InlineFormInterface::entityFormSubmit
EntityInlineForm::entityFormValidate public function Validates the entity form. Overrides InlineFormInterface::entityFormValidate
EntityInlineForm::getEntityLabel public function Gets the label of the given entity. Overrides InlineFormInterface::getEntityLabel
EntityInlineForm::getEntityType public function Gets the entity type managed by this handler. Overrides InlineFormInterface::getEntityType
EntityInlineForm::getEntityTypeLabels public function Gets the entity type labels (singular, plural). Overrides InlineFormInterface::getEntityTypeLabels 1
EntityInlineForm::getFormDisplay protected function Gets the form display for the given entity.
EntityInlineForm::getTableFields public function Gets the columns used to represent an entity in the IEF table. Overrides InlineFormInterface::getTableFields 1
EntityInlineForm::isTableDragEnabled public function Checks whether tabledrag should be enabled for the given table. Overrides InlineFormInterface::isTableDragEnabled
EntityInlineForm::save public function Saves the given entity. Overrides InlineFormInterface::save
EntityInlineForm::submitCleanFormState public static function Cleans up the form state for a submitted entity form.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TransactionInlineForm::$requestStack protected property The request stack.
TransactionInlineForm::$routeMatch protected property The route match.
TransactionInlineForm::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityInlineForm::createInstance
TransactionInlineForm::entityForm public function Builds the entity form. Overrides EntityInlineForm::entityForm
TransactionInlineForm::__construct public function Constructs the inline entity form controller. Overrides EntityInlineForm::__construct