You are here

AddCurrency.php in Currency 8.3

File

src/Controller/AddCurrency.php
View source
<?php

namespace Drupal\currency\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Handles the "add currency" route.
 */
class AddCurrency extends ControllerBase implements ContainerInjectionInterface {

  /**
   * The currency storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $currencyStorage;

  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
   *   The entity form builder.
   * @param \Drupal\Core\Entity\EntityStorageInterface $currency_storage
   *   The currency storage.
   */
  public function __construct(EntityFormBuilderInterface $entity_form_builder, EntityStorageInterface $currency_storage) {
    $this->currencyStorage = $currency_storage;
    $this->entityFormBuilder = $entity_form_builder;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $container
      ->get('entity_type.manager');
    return new static($container
      ->get('entity.form_builder'), $entity_type_manager
      ->getStorage('currency'));
  }

  /**
   * Builds a currency add form.
   *
   * @return array
   *   A renderable array.
   */
  public function execute() {
    $currency = $this->currencyStorage
      ->create([]);
    return $this->entityFormBuilder
      ->getForm($currency);
  }

}

Classes

Namesort descending Description
AddCurrency Handles the "add currency" route.