class ContentRoute in Drupal 7 to 8/9 Module Upgrader 8
Plugin annotation
@Converter(
id = "default",
description = @Translation("Converts a menu item to a _controller route."),
dependencies = { "router.route_provider", "plugin.manager.drupalmoduleupgrader.rewriter" }
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\drupalmoduleupgrader\PluginBase implements ContainerFactoryPluginInterface
- class \Drupal\drupalmoduleupgrader\ConverterBase implements ConverterInterface
- class \Drupal\drupalmoduleupgrader\Plugin\DMU\Routing\ContentRoute implements ContainerFactoryPluginInterface, RouteConverterInterface uses StringTransformTrait
- class \Drupal\drupalmoduleupgrader\ConverterBase implements ConverterInterface
- class \Drupal\drupalmoduleupgrader\PluginBase implements ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ContentRoute
File
- src/
Plugin/ DMU/ Routing/ ContentRoute.php, line 30
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\RoutingView source
class ContentRoute extends ConverterBase implements RouteConverterInterface, ContainerFactoryPluginInterface {
use StringTransformTrait;
/**
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $rewriters;
/**
* Constructs a RouteConverterBase object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, TranslationInterface $translator, LoggerInterface $log, RouteProviderInterface $route_provider, PluginManagerInterface $rewriters) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $translator, $log);
$this->routeProvider = $route_provider;
$this->rewriters = $rewriters;
}
/**
* Conform with ConverterInterface, which we implement through ConverterBase.
* Because route conversion is so complex, the Routing plugin never calls
* this method. It relies instead on the other methods defined in
* RouteConverterInterface.
*/
public final function convert(TargetInterface $target) {
}
/**
* {@inheritdoc}
*/
public function getName(TargetInterface $target, Drupal7Route $route) {
$name = $target
->id() . '.' . $this
->unPrefix($route['page callback'], $target
->id());
$arguments = array_filter($route['page arguments'], 'is_string');
if ($arguments) {
$name .= '_' . implode('_', $arguments);
}
return $name;
}
/**
* {@inheritdoc}
*/
public function buildPath(TargetInterface $target, Drupal7Route $route) {
// The parameter map modifies the path in-place, so we'll clone it in order
// to keep this method non-destructive.
$path = clone $route
->getPath();
$this
->buildParameterMap($target, $route)
->applyPath($path);
return $path;
}
/**
* Builds a parameter map from the aggregated arguments of the title,
* access, and page callbacks.
*
* @return \Drupal\drupalmoduleupgrader\Routing\ParameterMap
*/
protected function buildParameterMap(TargetInterface $target, Drupal7Route $route) {
$map = new ParameterMap(clone $route
->getPath(), []);
$indexer = $target
->getIndexer('function');
if ($indexer
->has($route['title callback'])) {
$map
->merge(new ParameterMap($route
->getPath(), $indexer
->get($route['title callback'])
->getParameters()
->toArray(), $route['title arguments']));
}
if ($indexer
->has($route['access callback'])) {
$map
->merge(new ParameterMap($route
->getPath(), $indexer
->get($route['access callback'])
->getParameters()
->toArray(), $route['access arguments']));
}
if ($indexer
->has($route['page callback'])) {
$map
->merge(new ParameterMap($route
->getPath(), $indexer
->get($route['page callback'])
->getParameters()
->toArray(), $route['page arguments']));
}
return $map;
}
/**
* {@inheritdoc}
*/
public function buildRouteDefinition(TargetInterface $target, Drupal7Route $route) {
$indexer = $target
->getIndexer('function');
$definition = new CoreRoute('');
$this
->buildParameterMap($target, $route)
->applyRoute($definition);
$controller = $this
->getController($target, $route)
->getName()
->getAbsolutePath();
if ($route
->containsKey('title')) {
$definition
->setDefault('_title', $route['title']);
}
elseif ($indexer
->has($route['title callback'])) {
$definition
->setDefault('_title_callback', $controller . '::' . $route['title callback']);
}
if ($route
->isAbsoluteAccess()) {
$definition
->setRequirement('_access', $route['access callback'] ? 'true' : 'false');
}
elseif ($route
->isPermissionBased()) {
$definition
->setRequirement('_permission', $route['access arguments'][0]);
}
elseif ($indexer
->has($route['access callback'])) {
$definition
->setRequirement('_custom_access', $controller . '::' . $route['access callback']);
}
if ($indexer
->has($route['page callback'])) {
$definition
->setDefault('_controller', $controller . '::' . $route['page callback']);
}
return new Drupal8Route($this
->getName($target, $route), $definition, $this->routeProvider);
}
/**
* {@inheritdoc}
*/
public function buildRoute(TargetInterface $target, Drupal7Route $route) {
$definition = $this
->buildRouteDefinition($target, $route);
$map = $this
->buildParameterMap($target, $route);
$map
->applyRoute($definition
->unwrap());
$indexer = $target
->getIndexer('function');
foreach ($map
->toArray() as $function_name => $parameters) {
if ($parameters && $indexer
->has($function_name)) {
/** @var \Pharborist\Functions\FunctionDeclarationNode $function */
$function = $indexer
->get($function_name);
foreach ($parameters as $parameter_name => $info) {
$parameter = $function
->getParameterByName($parameter_name)
->setName($info['name'], TRUE);
if (isset($info['type'])) {
$plugin_id = '_rewriter:' . $info['type'];
if ($this->rewriters
->hasDefinition($plugin_id)) {
$this->rewriters
->createInstance($plugin_id)
->rewrite($parameter);
}
}
}
}
}
$class_indexer = $target
->getIndexer('class');
if ($class_indexer
->has('DefaultController')) {
$controller = $class_indexer
->get('DefaultController');
}
else {
$controller = $this
->getController($target, $route);
$class_indexer
->addFile($this
->writeClass($target, $controller));
}
if ($indexer
->has($route['title callback'])) {
if (!$controller
->hasMethod($route['title callback'])) {
$indexer
->get($route['title callback'])
->cloneAsMethodOf($controller);
}
}
if ($indexer
->has($route['access callback'])) {
$func = $indexer
->get($route['access callback']);
$returns = $func
->find(Filter::isInstanceOf('\\Pharborist\\ReturnStatementNode'));
foreach ($returns as $ret) {
$call = ClassMethodCallNode::create('\\Drupal\\Core\\Access\\AccessResult', 'allowedIf')
->appendArgument($ret
->getExpression());
$ret
->replaceWith(ReturnStatementNode::create($call));
}
// The access callback always receives an $account parameter.
if ($func
->hasParameter('account')) {
$func
->getParameter('account')
->setTypeHint('Drupal\\Core\\Session\\AccountInterface');
}
else {
$account = ParameterNode::create('account')
->setTypeHint('Drupal\\Core\\Session\\AccountInterface');
$func
->appendParameter($account);
}
if (!$controller
->hasMethod($route['access callback'])) {
$func
->cloneAsMethodOf($controller);
}
}
if ($indexer
->has($route['page callback'])) {
if (!$controller
->hasMethod($route['page callback'])) {
$indexer
->get($route['page callback'])
->cloneAsMethodOf($controller);
}
}
$this
->writeClass($target, $controller);
}
protected function getController(TargetInterface $target, Drupal7Route $route) {
$render = [
'#theme' => 'dmu_controller',
'#module' => $target
->id(),
];
return $this
->parse($render);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentRoute:: |
protected | property | ||
ContentRoute:: |
protected | property | ||
ContentRoute:: |
protected | function | Builds a parameter map from the aggregated arguments of the title, access, and page callbacks. | 1 |
ContentRoute:: |
public | function |
Builds the Drupal 8 path for the route. Overrides RouteConverterInterface:: |
|
ContentRoute:: |
public | function |
Builds the Drupal 8 route, making any needed changes to the original module
and/or callback. Overrides RouteConverterInterface:: |
1 |
ContentRoute:: |
public | function |
Builds the Drupal 8 definition for the route, without making any changes
to the original module or callback. Overrides RouteConverterInterface:: |
1 |
ContentRoute:: |
final public | function |
Conform with ConverterInterface, which we implement through ConverterBase.
Because route conversion is so complex, the Routing plugin never calls
this method. It relies instead on the other methods defined in
RouteConverterInterface. Overrides ConverterInterface:: |
|
ContentRoute:: |
protected | function | 1 | |
ContentRoute:: |
public | function |
Generates the route's machine-readable name. Overrides RouteConverterInterface:: |
1 |
ContentRoute:: |
public | function |
Constructs a RouteConverterBase object. Overrides PluginBase:: |
1 |
ConverterBase:: |
protected | function | Builds a FIXME notice using either the text in the plugin definition, or passed-in text. | |
ConverterBase:: |
constant | |||
ConverterBase:: |
protected | function | Executes the target module's implementation of the specified hook, and returns the result. | |
ConverterBase:: |
protected | function | Creates an empty implementation of a hook. | |
ConverterBase:: |
public | function |
Returns if this conversion applies to the target module. If FALSE,
the convert() method will not be called. Overrides ConverterInterface:: |
4 |
ConverterBase:: |
constant | |||
ConverterBase:: |
protected | function | Parses a generated class into a syntax tree. | |
ConverterBase:: |
protected | function | Parametrically rewrites a function. | |
ConverterBase:: |
public | function | Writes a file to the target module's directory. | |
ConverterBase:: |
public | function | Writes a class to the target module's PSR-4 root. | |
ConverterBase:: |
protected | function | Writes out arbitrary data in YAML format. | |
ConverterBase:: |
protected | function | Writes a service definition to the target module's services.yml file. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | ||
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTransformTrait:: |
public | function | Deletes %wildcards from a route path. | |
StringTransformTrait:: |
public | function | Deletes {wildcards} from a route path. | |
StringTransformTrait:: |
public | function | Generates an identifier (prefixed with the module name, if $this->module exists) from an arbitrary string. | |
StringTransformTrait:: |
public | function | Generates an identifier from a Drupal 7 path. | |
StringTransformTrait:: |
public | function | Generates an identifier from a path. | |
StringTransformTrait:: |
public | function | Converts a string toCamelCase :) | |
StringTransformTrait:: |
public | function | Converts a string ToTitleCase. | |
StringTransformTrait:: |
public | function | Trims a prefix (as well as leading or trailing underscore, if any) from a string. | |
StringTransformTrait:: |
public | function | Trims a suffix (as well as leading underscore, if any) from a string. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |