You are here

class CourierChannelConverter in Courier 8

Same name in this branch
  1. 8 src/ParamConverter/CourierChannelConverter.php \Drupal\courier\ParamConverter\CourierChannelConverter
  2. 8 src/ProxyClass/ParamConverter/CourierChannelConverter.php \Drupal\courier\ProxyClass\ParamConverter\CourierChannelConverter
Same name and namespace in other branches
  1. 2.x src/ParamConverter/CourierChannelConverter.php \Drupal\courier\ParamConverter\CourierChannelConverter

Provides upcasting for a courier channel entity type ID.

Hierarchy

Expanded class hierarchy of CourierChannelConverter

1 string reference to 'CourierChannelConverter'
courier.services.yml in ./courier.services.yml
courier.services.yml
1 service uses CourierChannelConverter
courier.paramconverter.channel in ./courier.services.yml
Drupal\courier\ParamConverter\CourierChannelConverter

File

src/ParamConverter/CourierChannelConverter.php, line 12

Namespace

Drupal\courier\ParamConverter
View source
class CourierChannelConverter implements ParamConverterInterface {

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

  /**
   * Constructs a new EntityConverter.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    if ($definition = $this->entityTypeManager
      ->getDefinition($value, FALSE)) {
      if ($definition
        ->isSubclassOf('\\Drupal\\courier\\ChannelInterface')) {
        return $definition;
      }
    }
    return NULL;
  }

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

}

Members

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