protected function LocalTaxTypeBase::buildRateSummary in Commerce Core 8.2
Builds the summary of all available tax rates.
Return value
array The summary form element.
5 calls to LocalTaxTypeBase::buildRateSummary()
- CanadianSalesTax::buildConfigurationForm in modules/
tax/ src/ Plugin/ Commerce/ TaxType/ CanadianSalesTax.php - Form constructor.
- EuropeanUnionVat::buildConfigurationForm in modules/
tax/ src/ Plugin/ Commerce/ TaxType/ EuropeanUnionVat.php - Form constructor.
- NorwegianVat::buildConfigurationForm in modules/
tax/ src/ Plugin/ Commerce/ TaxType/ NorwegianVat.php - Form constructor.
- SwissVat::buildConfigurationForm in modules/
tax/ src/ Plugin/ Commerce/ TaxType/ SwissVat.php - Form constructor.
- UnitedKingdomVat::buildConfigurationForm in modules/
tax/ src/ Plugin/ Commerce/ TaxType/ UnitedKingdomVat.php - Form constructor.
File
- modules/
tax/ src/ Plugin/ Commerce/ TaxType/ LocalTaxTypeBase.php, line 277
Class
- LocalTaxTypeBase
- Provides the base class for local tax types.
Namespace
Drupal\commerce_tax\Plugin\Commerce\TaxTypeCode
protected function buildRateSummary() {
$zones = $this
->getZones();
usort($zones, function ($a, $b) {
/** @var \Drupal\commerce_tax\TaxZone $a */
/** @var \Drupal\commerce_tax\TaxZone $b */
return strcmp($a
->getLabel(), $b
->getLabel());
});
$element = [
'#type' => 'details',
'#title' => $this
->t('Tax rates'),
'#markup' => $this
->t('The following tax rates are provided:'),
'#open' => TRUE,
];
$element['table'] = [
'#type' => 'table',
'#header' => [
$this
->t('Tax rate'),
[
'data' => $this
->t('Percentage'),
'colspan' => 2,
],
],
'#input' => FALSE,
];
foreach ($zones as $zone) {
if (count($zones) > 1) {
$element['table'][$zone
->getId()] = [
'#attributes' => [
'class' => [
'region-title',
],
'no_striping' => TRUE,
],
'label' => [
'#markup' => $zone
->getLabel(),
'#wrapper_attributes' => [
'colspan' => 3,
],
],
];
}
foreach ($zone
->getRates() as $rate) {
$formatted_percentages = array_map(function ($percentage) {
/** @var \Drupal\commerce_tax\TaxRatePercentage $percentage */
return $percentage
->toString();
}, $rate
->getPercentages());
$element['table'][$zone
->getId() . '|' . $rate
->getId()] = [
'rate' => [
'#markup' => $rate
->getLabel(),
],
'percentages' => [
'#markup' => implode('<br>', $formatted_percentages),
],
];
}
}
return $element;
}