forked from drupalcommerce/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommerce.pages.inc
39 lines (35 loc) · 1.25 KB
/
commerce.pages.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* @file
* Callbacks for store add pages.
*/
use Drupal\Component\Utility\Xss;
use Drupal\Core\Url;
/**
* Prepares variables for the list of available bundles.
*
* Default template: commerce-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - bundle_type: The entity type of the bundles.
* - bundles: An array of bundles.
* - form_route_name: The add form route.
*/
function template_preprocess_commerce_add_list(&$variables) {
$bundle_type = \Drupal::entityManager()->getDefinition($variables['bundle_type']);
$variables += [
'class' => str_replace('_', '-', $bundle_type->getBundleOf()) . '-add-list',
// There is no link template for the add form, guess the route name.
'create_bundle_url' => Url::fromRoute('entity.' . $bundle_type->id() . '.add_form'),
'bundle_type_label' => $bundle_type->getLowercaseLabel(),
];
foreach ($variables['bundles'] as $bundle) {
$url = Url::fromRoute($variables['form_route_name'], [$bundle->getEntityTypeId() => $bundle->id()]);
$variables['bundles'][$bundle->id()] = [
'bundle' => $bundle->id(),
'add_link' => \Drupal::l($bundle->label(), $url),
'description' => Xss::filterAdmin($bundle->getDescription()),
];
}
}