You are here

class ViewModeConverter in Hierarchical Term Formatter 8

Converts route parameter into loaded view mode.

Hierarchy

Expanded class hierarchy of ViewModeConverter

1 string reference to 'ViewModeConverter'
hierarchical_term_formatter_test.services.yml in tests/modules/hierarchical_term_formatter_test/hierarchical_term_formatter_test.services.yml
tests/modules/hierarchical_term_formatter_test/hierarchical_term_formatter_test.services.yml
1 service uses ViewModeConverter
view_mode in tests/modules/hierarchical_term_formatter_test/hierarchical_term_formatter_test.services.yml
Drupal\hierarchical_term_formatter_test\ParamConverter\ViewModeConverter

File

tests/modules/hierarchical_term_formatter_test/src/ParamConverter/ViewModeConverter.php, line 12

Namespace

Drupal\hierarchical_term_formatter_test\ParamConverter
View source
class ViewModeConverter implements ParamConverterInterface {

  /**
   * A storage instance for entity_view_mode entity.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs a ViewModeConverter object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->storage = $entity_manager
      ->getStorage('entity_view_mode');
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    $display_name = 'node.' . $value;
    return $this->storage
      ->load($display_name);
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ViewModeConverter::$storage protected property A storage instance for entity_view_mode entity.
ViewModeConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
ViewModeConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
ViewModeConverter::__construct public function Constructs a ViewModeConverter object.