Skip to content

Commit 6380291

Browse files
committed
Issue #2901230: Rename StoreContext to CurrentStore
1 parent 5b36239 commit 6380291

File tree

8 files changed

+58
-60
lines changed

8 files changed

+58
-60
lines changed

modules/cart/src/Form/AddToCartForm.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Drupal\commerce_cart\CartProviderInterface;
99
use Drupal\commerce_order\Resolver\OrderTypeResolverInterface;
1010
use Drupal\commerce_price\Resolver\ChainPriceResolverInterface;
11-
use Drupal\commerce_store\StoreContextInterface;
11+
use Drupal\commerce_store\CurrentStoreInterface;
1212
use Drupal\Component\Datetime\TimeInterface;
1313
use Drupal\Core\Entity\ContentEntityForm;
1414
use Drupal\Core\Entity\EntityInterface;
@@ -46,11 +46,11 @@ class AddToCartForm extends ContentEntityForm implements AddToCartFormInterface
4646
protected $orderTypeResolver;
4747

4848
/**
49-
* The store context.
49+
* The current store.
5050
*
51-
* @var \Drupal\commerce_store\StoreContextInterface
51+
* @var \Drupal\commerce_store\CurrentStoreInterface
5252
*/
53-
protected $storeContext;
53+
protected $currentStore;
5454

5555
/**
5656
* The chain base price resolver.
@@ -88,20 +88,20 @@ class AddToCartForm extends ContentEntityForm implements AddToCartFormInterface
8888
* The cart provider.
8989
* @param \Drupal\commerce_order\Resolver\OrderTypeResolverInterface $order_type_resolver
9090
* The order type resolver.
91-
* @param \Drupal\commerce_store\StoreContextInterface $store_context
92-
* The store context.
91+
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
92+
* The current store.
9393
* @param \Drupal\commerce_price\Resolver\ChainPriceResolverInterface $chain_price_resolver
9494
* The chain base price resolver.
9595
* @param \Drupal\Core\Session\AccountInterface $current_user
9696
* The current user.
9797
*/
98-
public function __construct(EntityManagerInterface $entity_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, CartManagerInterface $cart_manager, CartProviderInterface $cart_provider, OrderTypeResolverInterface $order_type_resolver, StoreContextInterface $store_context, ChainPriceResolverInterface $chain_price_resolver, AccountInterface $current_user) {
98+
public function __construct(EntityManagerInterface $entity_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, CartManagerInterface $cart_manager, CartProviderInterface $cart_provider, OrderTypeResolverInterface $order_type_resolver, CurrentStoreInterface $current_store, ChainPriceResolverInterface $chain_price_resolver, AccountInterface $current_user) {
9999
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
100100

101101
$this->cartManager = $cart_manager;
102102
$this->cartProvider = $cart_provider;
103103
$this->orderTypeResolver = $order_type_resolver;
104-
$this->storeContext = $store_context;
104+
$this->currentStore = $current_store;
105105
$this->chainPriceResolver = $chain_price_resolver;
106106
$this->currentUser = $current_user;
107107
}
@@ -117,7 +117,7 @@ public static function create(ContainerInterface $container) {
117117
$container->get('commerce_cart.cart_manager'),
118118
$container->get('commerce_cart.cart_provider'),
119119
$container->get('commerce_order.chain_order_type_resolver'),
120-
$container->get('commerce_store.store_context'),
120+
$container->get('commerce_store.current_store'),
121121
$container->get('commerce_price.chain_price_resolver'),
122122
$container->get('current_user')
123123
);
@@ -261,7 +261,7 @@ protected function selectStore(PurchasableEntityInterface $entity) {
261261
throw new \Exception('The given entity is not assigned to any store.');
262262
}
263263
else {
264-
$store = $this->storeContext->getStore();
264+
$store = $this->currentStore->getStore();
265265
if (!in_array($store, $stores)) {
266266
// Indicates that the site listings are not filtered properly.
267267
throw new \Exception("The given entity can't be purchased from the current store.");

modules/price/src/Plugin/Field/FieldFormatter/PriceCalculatedFormatter.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Drupal\commerce\PurchasableEntityInterface;
77
use Drupal\commerce_price\NumberFormatterFactoryInterface;
88
use Drupal\commerce_price\Resolver\ChainPriceResolverInterface;
9-
use Drupal\commerce_store\StoreContextInterface;
9+
use Drupal\commerce_store\CurrentStoreInterface;
1010
use Drupal\Core\Cache\Cache;
1111
use Drupal\Core\Entity\EntityTypeManagerInterface;
1212
use Drupal\Core\Field\FieldDefinitionInterface;
@@ -51,11 +51,11 @@ class PriceCalculatedFormatter extends PriceDefaultFormatter implements Containe
5151
protected $currentUser;
5252

5353
/**
54-
* The store context.
54+
* The current store.
5555
*
56-
* @var \Drupal\commerce_store\StoreContextInterface
56+
* @var \Drupal\commerce_store\CurrentStoreInterface
5757
*/
58-
protected $storeContext;
58+
protected $currentStore;
5959

6060
/**
6161
* Constructs a new PriceCalculatedFormatter object.
@@ -80,16 +80,16 @@ class PriceCalculatedFormatter extends PriceDefaultFormatter implements Containe
8080
* The number formatter factory.
8181
* @param \Drupal\commerce_price\Resolver\ChainPriceResolverInterface $chain_price_resolver
8282
* The chain price resolver.
83-
* @param \Drupal\commerce_store\StoreContextInterface $store_context
84-
* The store context.
83+
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
84+
* The current store.
8585
* @param \Drupal\Core\Session\AccountInterface $current_user
8686
* The current user.
8787
*/
88-
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, NumberFormatterFactoryInterface $number_formatter_factory, ChainPriceResolverInterface $chain_price_resolver, StoreContextInterface $store_context, AccountInterface $current_user) {
88+
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, NumberFormatterFactoryInterface $number_formatter_factory, ChainPriceResolverInterface $chain_price_resolver, CurrentStoreInterface $current_store, AccountInterface $current_user) {
8989
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $entity_type_manager, $number_formatter_factory);
9090

9191
$this->chainPriceResolver = $chain_price_resolver;
92-
$this->storeContext = $store_context;
92+
$this->currentStore = $current_store;
9393
$this->currencyStorage = $entity_type_manager->getStorage('commerce_currency');
9494
$this->currentUser = $current_user;
9595
}
@@ -109,7 +109,7 @@ public static function create(ContainerInterface $container, array $configuratio
109109
$container->get('entity_type.manager'),
110110
$container->get('commerce_price.number_formatter_factory'),
111111
$container->get('commerce_price.chain_price_resolver'),
112-
$container->get('commerce_store.store_context'),
112+
$container->get('commerce_store.current_store'),
113113
$container->get('current_user')
114114
);
115115
}
@@ -118,8 +118,7 @@ public static function create(ContainerInterface $container, array $configuratio
118118
* {@inheritdoc}
119119
*/
120120
public function viewElements(FieldItemListInterface $items, $langcode) {
121-
$store = $this->storeContext->getStore();
122-
$context = new Context($this->currentUser, $store);
121+
$context = new Context($this->currentUser, $this->currentStore->getStore());
123122
$elements = [];
124123
/** @var \Drupal\commerce_price\Plugin\Field\FieldType\PriceItem $item */
125124
foreach ($items as $delta => $item) {

modules/store/commerce_store.services.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
2-
commerce_store.store_context:
3-
class: Drupal\commerce_store\StoreContext
2+
commerce_store.current_store:
3+
class: Drupal\commerce_store\CurrentStore
44
arguments: ['@request_stack', '@commerce_store.chain_store_resolver']
55

66
commerce_store.chain_store_resolver:
@@ -16,12 +16,12 @@ services:
1616

1717
commerce_store.store_country_resolver:
1818
class: Drupal\commerce_store\Resolver\StoreCountryResolver
19-
arguments: ['@commerce_store.store_context']
19+
arguments: ['@commerce_store.current_store']
2020
tags:
2121
- { name: commerce.country_resolver, priority: -90 }
2222

2323
cache_context.store:
2424
class: Drupal\commerce_store\Cache\Context\StoreCacheContext
25-
arguments: ['@commerce_store.store_context']
25+
arguments: ['@commerce_store.current_store']
2626
tags:
2727
- { name: cache.context}

modules/store/src/Cache/Context/StoreCacheContext.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Drupal\commerce_store\Cache\Context;
44

5-
use Drupal\commerce_store\StoreContextInterface;
5+
use Drupal\commerce_store\CurrentStoreInterface;
66
use Drupal\Core\Cache\Context\CacheContextInterface;
77
use Drupal\Core\Cache\CacheableMetadata;
88

@@ -14,20 +14,20 @@
1414
class StoreCacheContext implements CacheContextInterface {
1515

1616
/**
17-
* The store context.
17+
* The current store.
1818
*
19-
* @var \Drupal\commerce_store\StoreContextInterface
19+
* @var \Drupal\commerce_store\CurrentStoreInterface
2020
*/
21-
protected $storeContext;
21+
protected $currentStore;
2222

2323
/**
2424
* Constructs a new StoreCacheContext class.
2525
*
26-
* @param \Drupal\commerce_store\StoreContextInterface $context
27-
* The store context.
26+
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
27+
* The current store.
2828
*/
29-
public function __construct(StoreContextInterface $context) {
30-
$this->storeContext = $context;
29+
public function __construct(CurrentStoreInterface $current_store) {
30+
$this->currentStore = $current_store;
3131
}
3232

3333
/**
@@ -41,7 +41,7 @@ public static function getLabel() {
4141
* {@inheritdoc}
4242
*/
4343
public function getContext() {
44-
return $this->storeContext->getStore()->id();
44+
return $this->currentStore->getStore()->id();
4545
}
4646

4747
/**

modules/store/src/StoreContext.php renamed to modules/store/src/CurrentStore.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\HttpFoundation\RequestStack;
77

88
/**
9-
* Holds a reference to the active store, resolved on demand.
9+
* Holds a reference to the current store, resolved on demand.
1010
*
1111
* The ChainStoreResolver runs the registered store resolvers one by one until
1212
* one of them returns the store.
@@ -19,7 +19,7 @@
1919
* @see \Drupal\commerce_store\Resolver\ChainStoreResolver
2020
* @see \Drupal\commerce_store\Resolver\DefaultStoreResolver
2121
*/
22-
class StoreContext implements StoreContextInterface {
22+
class CurrentStore implements CurrentStoreInterface {
2323

2424
/**
2525
* The request stack.
@@ -43,7 +43,7 @@ class StoreContext implements StoreContextInterface {
4343
protected $stores;
4444

4545
/**
46-
* Constructs a new StoreContext object.
46+
* Constructs a new CurrentStore object.
4747
*
4848
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
4949
* The request stack.

modules/store/src/StoreContextInterface.php renamed to modules/store/src/CurrentStoreInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
/**
66
* Holds a reference to the active store, resolved on demand.
7-
*
8-
* @see \Drupal\commerce_store\StoreContext
97
*/
10-
interface StoreContextInterface {
8+
interface CurrentStoreInterface {
119

1210
/**
1311
* Gets the active store for the current request.

modules/store/src/Plugin/views/argument_default/ActiveStore.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Drupal\commerce_store\Plugin\views\argument_default;
44

5-
use Drupal\commerce_store\StoreContextInterface;
5+
use Drupal\commerce_store\CurrentStoreInterface;
66
use Drupal\Core\Cache\Cache;
77
use Drupal\Core\Cache\CacheableDependencyInterface;
88
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
@@ -19,11 +19,11 @@
1919
class ActiveStore extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
2020

2121
/**
22-
* The store context.
22+
* The current store.
2323
*
24-
* @var \Drupal\commerce_store\StoreContextInterface
24+
* @var \Drupal\commerce_store\CurrentStoreInterface
2525
*/
26-
protected $storeContext;
26+
protected $currentStore;
2727

2828
/**
2929
* Constructs a PluginBase object.
@@ -34,12 +34,13 @@ class ActiveStore extends ArgumentDefaultPluginBase implements CacheableDependen
3434
* The plugin_id for the plugin instance.
3535
* @param mixed $plugin_definition
3636
* The plugin implementation definition.
37-
* @param \Drupal\commerce_store\StoreContextInterface $store_context
38-
* The store context.
37+
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
38+
* The current store.
3939
*/
40-
public function __construct(array $configuration, $plugin_id, $plugin_definition, StoreContextInterface $store_context) {
40+
public function __construct(array $configuration, $plugin_id, $plugin_definition, CurrentStoreInterface $current_store) {
4141
parent::__construct($configuration, $plugin_id, $plugin_definition);
42-
$this->storeContext = $store_context;
42+
43+
$this->currentStore = $current_store;
4344
}
4445

4546
/**
@@ -50,15 +51,15 @@ public static function create(ContainerInterface $container, array $configuratio
5051
$configuration,
5152
$plugin_id,
5253
$plugin_definition,
53-
$container->get('commerce_store.store_context')
54+
$container->get('commerce_store.current_store')
5455
);
5556
}
5657

5758
/**
5859
* {@inheritdoc}
5960
*/
6061
public function getArgument() {
61-
return $this->storeContext->getStore()->id();
62+
return $this->currentStore->getStore()->id();
6263
}
6364

6465
/**
@@ -79,7 +80,7 @@ public function getCacheContexts() {
7980
* {@inheritdoc}
8081
*/
8182
public function getCacheTags() {
82-
return $this->storeContext->getStore()->getCacheTags();
83+
return $this->currentStore->getStore()->getCacheTags();
8384
}
8485

8586
}

modules/store/src/Resolver/StoreCountryResolver.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Drupal\commerce\Country;
66
use Drupal\commerce\Resolver\CountryResolverInterface;
7-
use Drupal\commerce_store\StoreContextInterface;
7+
use Drupal\commerce_store\CurrentStoreInterface;
88

99
/**
1010
* Returns the store's billing country.
@@ -20,27 +20,27 @@
2020
class StoreCountryResolver implements CountryResolverInterface {
2121

2222
/**
23-
* The store context.
23+
* The current store.
2424
*
25-
* @var \Drupal\commerce_store\StoreContextInterface
25+
* @var \Drupal\commerce_store\CurrentStoreInterface
2626
*/
27-
protected $storeContext;
27+
protected $currentStore;
2828

2929
/**
3030
* Constructs a new StoreCountryResolver object.
3131
*
32-
* @param \Drupal\commerce_store\StoreContextInterface $store_context
33-
* The store context.
32+
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
33+
* The current store.
3434
*/
35-
public function __construct(StoreContextInterface $store_context) {
36-
$this->storeContext = $store_context;
35+
public function __construct(CurrentStoreInterface $current_store) {
36+
$this->currentStore = $current_store;
3737
}
3838

3939
/**
4040
* {@inheritdoc}
4141
*/
4242
public function resolve() {
43-
$store = $this->storeContext->getStore();
43+
$store = $this->currentStore->getStore();
4444
if ($store) {
4545
return new Country($store->getAddress()->getCountryCode());
4646
}

0 commit comments

Comments
 (0)