EnableCurrency.php in Currency 8.3
Namespace
Drupal\currency\ControllerFile
src/Controller/EnableCurrency.phpView source
<?php
namespace Drupal\currency\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\currency\Entity\CurrencyInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Handles the "enable currency" route.
*/
class EnableCurrency extends ControllerBase implements ContainerInjectionInterface {
/**
* Constructs a new instance.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
*/
public function __construct(UrlGeneratorInterface $url_generator) {
$this->urlGenerator = $url_generator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('url_generator'));
}
/**
* Enables a currency.
*
* @param \Drupal\currency\Entity\CurrencyInterface $currency
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function execute(CurrencyInterface $currency) {
$currency
->enable();
$currency
->save();
return new RedirectResponse($this->urlGenerator
->generateFromRoute('entity.currency.collection', array(
'absolute' => TRUE,
)));
}
}
Classes
Name | Description |
---|---|
EnableCurrency | Handles the "enable currency" route. |