You are here

class ProductVariationController in Commerce Core 8.2

Provides title callbacks for product variation routes.

Hierarchy

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\Controller
View 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

Namesort descending Modifiers Type Description Overrides
ProductVariationController::$entityRepository protected property The entity repository.
ProductVariationController::addTitle public function Provides the add title callback for product variations.
ProductVariationController::collectionTitle public function Provides the collection title callback for product variations.
ProductVariationController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ProductVariationController::deleteTitle public function Provides the delete title callback for product variations.
ProductVariationController::editTitle public function Provides the edit title callback for product variations.
ProductVariationController::__construct public function Constructs a new ProductVariationController.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.