You are here

public function TaxRateController::saveClone in Ubercart 8.4

Clones a tax rate.

Parameters

\Drupal\uc_tax\TaxRateInterface $uc_tax_rate: The tax rate entity.

1 string reference to 'TaxRateController::saveClone'
uc_tax.routing.yml in uc_tax/uc_tax.routing.yml
uc_tax/uc_tax.routing.yml

File

uc_tax/src/Controller/TaxRateController.php, line 35

Class

TaxRateController
Route controller for tax rates.

Namespace

Drupal\uc_tax\Controller

Code

public function saveClone(TaxRateInterface $uc_tax_rate) {
  $name = $uc_tax_rate
    ->label();

  // Tweak the name and unset the rate ID.
  $cloned_rate = $uc_tax_rate
    ->createDuplicate();
  $cloned_rate
    ->setLabel($this
    ->t('Copy of @name', [
    '@name' => $name,
  ]));

  // @todo Have to check for uniqueness of name first - in case we have
  // cloned this rate before ...
  $cloned_rate
    ->setId($uc_tax_rate
    ->id() . "_clone");

  // Save the new rate without clearing the Rules cache.
  $cloned_rate
    ->save();

  // Clone the associated conditions as well.
  // if ($conditions = rules_config_load('uc_tax_' . $uc_tax_rate->id())) {
  //   $conditions->id = NULL;
  //   $conditions->name = '';
  //   $conditions->save('uc_tax_' . $uc_tax_rate->id());
  // }
  // entity_flush_caches();
  // Display a message and redirect back to the methods page.
  $this
    ->messenger()
    ->addMessage($this
    ->t('Tax rate %name was cloned.', [
    '%name' => $name,
  ]));
  return $this
    ->redirect('entity.uc_tax_rate.collection');
}