devel_wizard-2.x-dev/templates/spell/plugin_manager/param_converter.php.twig

templates/spell/plugin_manager/param_converter.php.twig
<?php

declare(strict_types=1);

namespace {{ paramConverter.namespace }};

use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;

/**
 * Converts {{ label }} ID into a {{ label }} instance.
 *
 * @code
 * # my_module_01.routing.yml
 * my_module_01.route_01:
 *   path: '/my_module_01/foo/{{ '{' }}{{ object }}{{ '}' }}'
 *   options:
 *     parameters:
 *       spell:
 *         type: '{{ module }}:{{ object }}'
 *   defaults: {}
 *   requirements: {}
 * @endcode
 */
class {{ paramConverter.class }} implements ParamConverterInterface {

  protected {{ managerInterface.class }} ${{ objectLowerCamel }}Manager;

  public function __construct({{ managerInterface.class }} ${{ objectLowerCamel }}Manager) {
    $this->{{ objectLowerCamel }}Manager = ${{ objectLowerCamel }}Manager;
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return ($definition['type'] ?? NULL) === '{{ module }}:{{ object }}';
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    /* @noinspection PhpUnhandledExceptionInspection */
    return $this->{{ objectLowerCamel }}Manager->hasDefinition($value) ?
      $this->{{ objectLowerCamel }}Manager->createInstance($value)
      : NULL;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc