You are here

class EntityParamConverter in Content Planner 8

Class EntityParamConverter.

Hierarchy

Expanded class hierarchy of EntityParamConverter

1 string reference to 'EntityParamConverter'
content_kanban.services.yml in modules/content_kanban/content_kanban.services.yml
modules/content_kanban/content_kanban.services.yml
1 service uses EntityParamConverter
content_kanban.entity_params in modules/content_kanban/content_kanban.services.yml
Drupal\content_kanban\ParamConverter\EntityParamConverter

File

modules/content_kanban/src/ParamConverter/EntityParamConverter.php, line 14

Namespace

Drupal\content_kanban\ParamConverter
View source
class EntityParamConverter implements ParamConverterInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * EntityParamConverter constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
   *   The entity type manager service.
   */
  public function __construct(EntityTypeManager $entityTypeManager) {
    $this->entityTypeManager = $entityTypeManager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    try {
      $entityType = $this->entityTypeManager
        ->getStorage($defaults['entity_type']);
      $entity = $entityType
        ->load($value);
      return $entity;
    } catch (InvalidPluginDefinitionException $e) {
      watchdog_exception('content_kanban', $e);
    } catch (PluginNotFoundException $e) {
      watchdog_exception('content_kanban', $e);
    }
    return NULL;
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
EntityParamConverter::$entityTypeManager protected property The entity type manager.
EntityParamConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
EntityParamConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
EntityParamConverter::__construct public function EntityParamConverter constructor.