class ProductVariationController in Commerce Core 8.2
Provides title callbacks for product variation routes.
Hierarchy
- class \Drupal\commerce_product\Controller\ProductVariationController implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of ProductVariationController
1 file declares its use of ProductVariationController
- ProductVariationRouteProvider.php in modules/
product/ src/ ProductVariationRouteProvider.php
File
- modules/
product/ src/ Controller/ ProductVariationController.php, line 15
Namespace
Drupal\commerce_product\ControllerView source
class ProductVariationController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Constructs a new ProductVariationController.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct(EntityRepositoryInterface $entity_repository, TranslationInterface $string_translation) {
$this->entityRepository = $entity_repository;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('string_translation'));
}
/**
* Provides the add title callback for product variations.
*
* @return string
* The title for the product variation add page.
*/
public function addTitle() {
return $this
->t('Add variation');
}
/**
* Provides the edit title callback for product variations.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return string
* The title for the product variation edit page.
*/
public function editTitle(RouteMatchInterface $route_match) {
$product_variation = $route_match
->getParameter('commerce_product_variation');
$product_variation = $this->entityRepository
->getTranslationFromContext($product_variation);
return $this
->t('Edit %label', [
'%label' => $product_variation
->label(),
]);
}
/**
* Provides the delete title callback for product variations.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return string
* The title for the product variation delete page.
*/
public function deleteTitle(RouteMatchInterface $route_match) {
$product_variation = $route_match
->getParameter('commerce_product_variation');
$product_variation = $this->entityRepository
->getTranslationFromContext($product_variation);
return $this
->t('Delete %label', [
'%label' => $product_variation
->label(),
]);
}
/**
* Provides the collection title callback for product variations.
*
* @return string
* The title for the product variation collection.
*/
public function collectionTitle() {
// Note that ProductVariationListBuilder::getForm() overrides the page
// title. The title defined here is used only for the breadcrumb.
return $this
->t('Variations');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProductVariationController:: |
protected | property | The entity repository. | |
ProductVariationController:: |
public | function | Provides the add title callback for product variations. | |
ProductVariationController:: |
public | function | Provides the collection title callback for product variations. | |
ProductVariationController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ProductVariationController:: |
public | function | Provides the delete title callback for product variations. | |
ProductVariationController:: |
public | function | Provides the edit title callback for product variations. | |
ProductVariationController:: |
public | function | Constructs a new ProductVariationController. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |