Commit 78cded08 authored by bojanz's avatar bojanz

Add the enable/disable operations for currencies.

parent d7783513
......@@ -37,3 +37,27 @@ entity.commerce_currency.delete_form:
_title: 'Delete a currency'
requirements:
_permission: 'administer stores'
entity.commerce_currency.enable:
path: '/admin/commerce/config/currency/{commerce_currency}/enable'
defaults:
_controller: '\Drupal\commerce_price\Controller\CurrencyController::performOperation'
op: 'enable'
options:
parameters:
commerce_currency:
type: entity:commerce_currency
requirements:
_permission: 'administer stores'
entity.commerce_currency.disable:
path: '/admin/commerce/config/currency/{commerce_currency}/disable'
defaults:
_controller: '\Drupal\commerce_price\Controller\CurrencyController::performOperation'
op: 'disable'
options:
parameters:
commerce_currency:
type: entity:commerce_currency
requirements:
_permission: 'administer stores'
<?php
/**
* @file
* Contains Drupal\commerce_price\Controller\CurrencyController
*/
namespace Drupal\commerce_price\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Route controller for currencies.
*/
class CurrencyController extends ControllerBase {
/**
* Performs an operation on the currency entity.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The route match.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect back to the currency listing.
*/
public function performOperation(RouteMatchInterface $routeMatch) {
$currency = $routeMatch->getParameter('commerce_currency');
$op = $routeMatch->getParameter('op');
$currency->$op()->save();
if ($op == 'enable') {
drupal_set_message($this->t('The %label currency has been enabled.', array('%label' => $currency->label())));
}
elseif ($op == 'disable') {
drupal_set_message($this->t('The %label currency has been disabled.', array('%label' => $currency->label())));
}
$url = $currency->urlInfo('collection');
return $this->redirect($url->getRouteName(), $url->getRouteParameters(), $url->getOptions());
}
}
......@@ -43,6 +43,8 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
* links = {
* "edit-form" = "/admin/commerce/config/currency/{commerce_currency}",
* "delete-form" = "/admin/commerce/config/currency/{commerce_currency}/delete",
* "enable" = "/admin/commerce/config/currency/{commerce_currency}/enable",
* "disable" = "/admin/commerce/config/currency/{commerce_currency}/disable",
* "collection" = "/admin/commerce/config/currency"
* }
* )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment