ViewModeConverter.php in Hierarchical Term Formatter 8
File
tests/modules/hierarchical_term_formatter_test/src/ParamConverter/ViewModeConverter.php
View source
<?php
namespace Drupal\hierarchical_term_formatter_test\ParamConverter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;
class ViewModeConverter implements ParamConverterInterface {
protected $storage;
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->storage = $entity_manager
->getStorage('entity_view_mode');
}
public function convert($value, $definition, $name, array $defaults) {
$display_name = 'node.' . $value;
return $this->storage
->load($display_name);
}
public function applies($definition, $name, Route $route) {
if (!empty($definition['type']) && $definition['type'] == 'view_mode') {
return TRUE;
}
return FALSE;
}
}