You are here

LayoutParagraphsTempstoreParamConverter.php in Layout Paragraphs 2.0.x

File

src/Routing/LayoutParagraphsTempstoreParamConverter.php
View source
<?php

namespace Drupal\layout_paragraphs\Routing;

use Symfony\Component\Routing\Route;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\layout_paragraphs\LayoutParagraphsLayout;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository;

/**
 * Layout paragraphs tempstore param converter service.
 *
 * @internal
 *   Tagged services are internal.
 */
class LayoutParagraphsTempstoreParamConverter implements ParamConverterInterface {

  /**
   * The layout paragraphs layout tempstore.
   *
   * @var \Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository
   */
  protected $layoutParagraphsLayoutTempstore;

  /**
   * The Entity Type Manager service.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface;
   */
  protected $entityTypeManager;

  /**
   * Constructs a new LayoutParagraphsEditorTempstoreParamConverter.
   *
   * @param \Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository $layout_paragraphs_layout_tempstore
   *   The layout tempstore repository.
   */
  public function __construct(LayoutParagraphsLayoutTempstoreRepository $layout_paragraphs_layout_tempstore, EntityTypeManagerInterface $entity_type_manager) {
    $this->layoutParagraphsLayoutTempstore = $layout_paragraphs_layout_tempstore;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    if (empty($defaults['layout_paragraphs_layout'])) {
      return NULL;
    }
    $key = $defaults['layout_paragraphs_layout'];
    return $this->layoutParagraphsLayoutTempstore
      ->getWithStorageKey($key);
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return !empty($definition['layout_paragraphs_layout_tempstore']);
  }

}

Classes

Namesort descending Description
LayoutParagraphsTempstoreParamConverter Layout paragraphs tempstore param converter service.