本文整理汇总了PHP中Drupal\Core\Routing\RouteProviderInterface类的典型用法代码示例。如果您正苦于以下问题:PHP RouteProviderInterface类的具体用法?PHP RouteProviderInterface怎么用?PHP RouteProviderInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RouteProviderInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: onRequest
/**
* Loads all non-admin routes right before the actual page is rendered.
*
* @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
* The event to process.
*/
public function onRequest(KernelEvent $event)
{
// Only preload on normal HTML pages, as they will display menu links.
if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
if ($routes = $this->state->get('routing.non_admin_routes', [])) {
// Preload all the non-admin routes at once.
$this->routeProvider->preLoadRoutes($routes);
}
}
}
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:RoutePreloader.php
示例2: setUp
public function setUp()
{
$this->routeProvider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->pluginDefinition = array('class' => '\\Drupal\\config_translation\\ConfigNamesMapper', 'base_route_name' => 'system.site_information_settings', 'title' => 'System information', 'names' => array('system.site'), 'weight' => 42);
$this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
$this->localeConfigManager = $this->getMockBuilder('Drupal\\locale\\LocaleConfigManager')->disableOriginalConstructor()->getMock();
$this->configMapperManager = $this->getMock('Drupal\\config_translation\\ConfigMapperManagerInterface');
$this->baseRoute = new Route('/admin/config/system/site-information');
$this->routeProvider->expects($this->any())->method('getRouteByName')->with('system.site_information_settings')->will($this->returnValue($this->baseRoute));
$this->configNamesMapper = new TestConfigNamesMapper('system.site_information_settings', $this->pluginDefinition, $this->getConfigFactoryStub(), $this->typedConfigManager, $this->localeConfigManager, $this->configMapperManager, $this->routeProvider, $this->getStringTranslationStub());
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:ConfigNamesMapperTest.php
示例3: setUp
public function setUp()
{
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
$this->routeProvider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->routeProvider->expects($this->any())->method('getRouteByName')->with('entity.language_entity.edit_form')->will($this->returnValue(new Route('/admin/config/regional/language/edit/{language_entity}')));
$definition = array('class' => '\\Drupal\\config_translation\\ConfigEntityMapper', 'base_route_name' => 'entity.language_entity.edit_form', 'title' => '!label language', 'names' => array(), 'entity_type' => 'language_entity', 'route_name' => 'config_translation.item.overview.entity.language_entity.edit_form');
$typed_config_manager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
$locale_config_manager = $this->getMockBuilder('Drupal\\locale\\LocaleConfigManager')->disableOriginalConstructor()->getMock();
$this->configEntityMapper = new ConfigEntityMapper('language_entity', $definition, $this->getConfigFactoryStub(), $typed_config_manager, $locale_config_manager, $this->getMock('Drupal\\config_translation\\ConfigMapperManagerInterface'), $this->routeProvider, $this->getStringTranslationStub(), $this->entityManager);
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:11,代码来源:ConfigEntityMapperTest.php
示例4: onRequest
/**
* Loads all non-admin routes right before the actual page is rendered.
*
* @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
* The event to process.
*/
public function onRequest(KernelEvent $event)
{
// Only preload on normal HTML pages, as they will display menu links.
if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
// Ensure that the state query is cached to skip the database query, if
// possible.
$key = 'routing.non_admin_routes';
if ($cache = $this->cache->get($key)) {
$routes = $cache->data;
} else {
$routes = $this->state->get($key, []);
$this->cache->set($key, $routes, Cache::PERMANENT, ['routes']);
}
if ($routes) {
// Preload all the non-admin routes at once.
$this->routeProvider->preLoadRoutes($routes);
}
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:25,代码来源:RoutePreloader.php
示例5: getRouteParameters
/**
* {@inheritdoc}
*/
public function getRouteParameters(RouteMatchInterface $route_match)
{
$parameters = isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : array();
$route = $this->routeProvider->getRouteByName($this->getRouteName());
$variables = $route->compile()->getVariables();
// Normally the \Drupal\Core\ParamConverter\ParamConverterManager has
// processed the Request attributes, and in that case the _raw_variables
// attribute holds the original path strings keyed to the corresponding
// slugs in the path patterns. For example, if the route's path pattern is
// /filter/tips/{filter_format} and the path is /filter/tips/plain_text then
// $raw_variables->get('filter_format') == 'plain_text'.
$raw_variables = $route_match->getRawParameters();
foreach ($variables as $name) {
if (isset($parameters[$name])) {
continue;
}
if ($raw_variables && $raw_variables->has($name)) {
$parameters[$name] = $raw_variables->get($name);
} elseif ($value = $route_match->getRawParameter($name)) {
$parameters[$name] = $value;
}
}
// The UrlGenerator will throw an exception if expected parameters are
// missing. This method should be overridden if that is possible.
return $parameters;
}
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:29,代码来源:LocalActionDefault.php
示例6: getRouteByNames
protected function getRouteByNames(DrupalStyle $io, $route_name)
{
$routes = $this->routeProvider->getRoutesByNames($route_name);
foreach ($routes as $name => $route) {
$tableHeader = [$this->trans('commands.router.debug.messages.route'), '<info>' . $name . '</info>'];
$tableRows = [];
$tableRows[] = ['<comment>' . $this->trans('commands.router.debug.messages.path') . '</comment>', $route->getPath()];
$tableRows[] = ['<comment>' . $this->trans('commands.router.debug.messages.defaults') . '</comment>'];
$attributes = $this->addRouteAttributes($route->getDefaults());
foreach ($attributes as $attribute) {
$tableRows[] = $attribute;
}
$tableRows[] = ['<comment>' . $this->trans('commands.router.debug.messages.requirements') . '</comment>'];
$requirements = $this->addRouteAttributes($route->getRequirements());
foreach ($requirements as $requirement) {
$tableRows[] = $requirement;
}
$tableRows[] = ['<comment>' . $this->trans('commands.router.debug.messages.options') . '</comment>'];
$options = $this->addRouteAttributes($route->getOptions());
foreach ($options as $option) {
$tableRows[] = $option;
}
$io->table($tableHeader, $tableRows, 'compact');
}
}
开发者ID:GDrupal,项目名称:DrupalConsole,代码行数:25,代码来源:DebugCommand.php
示例7: canRedirect
/**
* Determines if redirect may be performed.
*
* @param Request $request
* The current request object.
* @param string $route_name
* The current route name.
*
* @return bool
* TRUE if redirect may be performed.
*/
public function canRedirect(Request $request, $route_name = NULL)
{
$can_redirect = TRUE;
if (isset($route_name)) {
$route = $this->routeProvider->getRouteByName($route_name);
if ($this->config->get('access_check')) {
// Do not redirect if is a protected page.
$can_redirect &= $this->accessManager->check($route, $request, $this->account);
}
} else {
$route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
}
if (strpos($request->getScriptName(), 'index.php') === FALSE) {
// Do not redirect if the root script is not /index.php.
$can_redirect = FALSE;
} elseif (!($request->isMethod('GET') || $request->isMethod('HEAD'))) {
// Do not redirect if this is other than GET request.
$can_redirect = FALSE;
} elseif ($this->state->get('system.maintenance_mode') || defined('MAINTENANCE_MODE')) {
// Do not redirect in offline or maintenance mode.
$can_redirect = FALSE;
} elseif ($this->config->get('ignore_admin_path') && isset($route)) {
// Do not redirect on admin paths.
$can_redirect &= !(bool) $route->getOption('_admin_route');
}
return $can_redirect;
}
开发者ID:isramv,项目名称:camp-gdl,代码行数:38,代码来源:RedirectChecker.php
示例8: isValid
/**
* {@inheritdoc}
*/
public function isValid($path)
{
// External URLs and the front page are always valid.
if ($path == '<front>' || UrlHelper::isExternal($path)) {
return TRUE;
}
// Check the routing system.
$collection = $this->routeProvider->getRoutesByPattern('/' . $path);
if ($collection->count() == 0) {
return FALSE;
}
$request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), '/' . $path);
$request->attributes->set('_system_path', $path);
// We indicate that a menu administrator is running the menu access check.
$request->attributes->set('_menu_admin', TRUE);
// Attempt to match this path to provide a fully built request to the
// access checker.
try {
$request->attributes->add($this->requestMatcher->matchRequest($request));
} catch (ParamNotConvertedException $e) {
return FALSE;
}
// Consult the access manager.
$routes = $collection->all();
$route = reset($routes);
return $this->accessManager->check($route, $request, $this->account);
}
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:PathValidator.php
示例9: onPageContext
/**
* Adds in the current user as a context.
*
* @param \Drupal\page_manager\Event\PageManagerContextEvent $event
* The page entity context event.
*/
public function onPageContext(PageManagerContextEvent $event)
{
$request = $this->requestStack->getCurrentRequest();
$page = $event->getPage();
$routes = $this->routeProvider->getRoutesByPattern($page->getPath())->all();
$route = reset($routes);
if ($route && ($route_contexts = $route->getOption('parameters'))) {
foreach ($route_contexts as $route_context_name => $route_context) {
// Skip this parameter.
if ($route_context_name == 'page_manager_page_variant' || $route_context_name == 'page_manager_page') {
continue;
}
$context_name = $this->t('{@name} from route', ['@name' => $route_context_name]);
if ($request->attributes->has($route_context_name)) {
$value = $request->attributes->get($route_context_name);
} else {
// @todo Find a way to add in a fake value for configuration.
$value = NULL;
}
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['route']);
$context = new Context(new ContextDefinition($route_context['type'], $context_name, FALSE), $value);
$context->addCacheableDependency($cacheability);
$page->addContext($route_context_name, $context);
}
}
}
开发者ID:ns-oxit-study,项目名称:drupal-8-training,代码行数:33,代码来源:RouteParamContext.php
示例10: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
$this->data['routing'] = [];
foreach ($this->routeProvider->getAllRoutes() as $route_name => $route) {
// @TODO Find a better visual representation.
$this->data['routing'][] = ['name' => $route_name, 'path' => $route->getPath()];
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:11,代码来源:RoutingDataCollector.php
示例11: load
/**
* {@inheritdoc}
*/
public function load($menu_name, MenuTreeParameters $parameters)
{
$data = $this->treeStorage->loadTreeData($menu_name, $parameters);
// Pre-load all the route objects in the tree for access checks.
if ($data['route_names']) {
$this->routeProvider->getRoutesByNames($data['route_names']);
}
return $this->createInstances($data['tree']);
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:12,代码来源:MenuLinkTree.php
示例12: canRedirect
/**
* Checks access to the route.
*
* @param string $route_name
* The current route name.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return bool
* TRUE if access is granted.
*/
public function canRedirect($route_name, Request $request)
{
$do_redirect = TRUE;
/** @var \Symfony\Component\Routing\Route $route */
$route = $this->routeProvider->getRouteByName($route_name);
if ($this->config->get('access_check')) {
$do_redirect &= $this->accessManager->check($route, $request, $this->account);
}
if ($this->config->get('ignore_admin_path')) {
$do_redirect &= !(bool) $route->getOption('_admin_route');
}
return $do_redirect;
}
开发者ID:Progressable,项目名称:openway8,代码行数:24,代码来源:RedirectChecker.php
示例13: rewrite
/**
* {@inheritdoc}
*/
public function rewrite(FunctionCallNode $call, TargetInterface $target)
{
$arguments = $call->getArguments();
if ($arguments[0] instanceof StringNode) {
$path = $arguments[0]->toValue();
// If the URL has a scheme (e.g., http://), it's external.
if (parse_url($path, PHP_URL_SCHEME)) {
return ClassMethodCallNode::create('\\Drupal\\Core\\Url', 'fromUri')->appendArgument(clone $arguments[0]);
} elseif ($this->routeExists($path)) {
$route = $this->routeProvider->getRoutesByPattern('/' . $path)->getIterator()->key();
return ClassMethodCallNode::create('\\Drupal\\Core\\Url', 'fromRoute')->appendArgument(StringNode::fromValue($route));
}
}
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:17,代码来源:URL.php
示例14: getActionsForRoute
/**
* {@inheritdoc}
*/
public function getActionsForRoute($route_appears)
{
if (!isset($this->instances[$route_appears])) {
$route_names = array();
$this->instances[$route_appears] = array();
// @todo - optimize this lookup by compiling or caching.
foreach ($this->getDefinitions() as $plugin_id => $action_info) {
if (in_array($route_appears, $action_info['appears_on'])) {
$plugin = $this->createInstance($plugin_id);
$route_names[] = $plugin->getRouteName();
$this->instances[$route_appears][$plugin_id] = $plugin;
}
}
// Pre-fetch all the action route objects. This reduces the number of SQL
// queries that would otherwise be triggered by the access manager.
if (!empty($route_names)) {
$this->routeProvider->getRoutesByNames($route_names);
}
}
$links = array();
/** @var $plugin \Drupal\Core\Menu\LocalActionInterface */
foreach ($this->instances[$route_appears] as $plugin_id => $plugin) {
$route_name = $plugin->getRouteName();
$route_parameters = $plugin->getRouteParameters($this->routeMatch);
$links[$plugin_id] = array('#theme' => 'menu_local_action', '#link' => array('title' => $this->getTitle($plugin), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($this->routeMatch)), '#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account), '#weight' => $plugin->getWeight());
}
return $links;
}
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:31,代码来源:LocalActionManager.php
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$settings = $this->config('rest_api_doc.settings');
$enabled_route_names = $settings->get('routes');
$available_route_names = $this->state->get('rest_api_doc.rest_route_names');
if (empty($available_route_names)) {
return array(
'no_routes' => array(
'#markup' => $this->t('No REST enabled routes exist, please configure your REST end-points'),
),
);
}
else {
$routes = $this->routeProvider->getRoutesByNames($available_route_names);
$descriptions = array();
foreach ($routes as $route_name => $route) {
$descriptions[$route_name] = $route_name . ' (' . $route->getPath() . ')';
}
$form['routes'] = array(
'#type' => 'checkboxes',
'#title' => $this->t('Enabled routes'),
'#description' => $this->t('Provide documentation for the following route names'),
'#options' => array_combine($available_route_names, $descriptions),
'#default_value' => $enabled_route_names,
);
$form['overview'] = array(
'#type' => 'textarea',
'#default_value' => $settings->get('overview'),
'#title' => $this->t('REST API overview'),
'#description' => $this->t('Description to show on summary page. You may use site-wide tokens and some markup.'),
);
}
return parent::buildForm($form, $form_state);
}
开发者ID:ashzadeh,项目名称:afbs-ang,代码行数:36,代码来源:RestApiDocSettingsForm.php
示例16: alterLocalTasks
/**
* Alters base_route and parent_id into the views local tasks.
*/
public function alterLocalTasks(&$local_tasks)
{
$view_route_names = $this->state->get('views.view_route_names');
foreach ($this->getApplicableMenuViews() as $pair) {
list($view_id, $display_id) = $pair;
/** @var $executable \Drupal\views\ViewExecutable */
$executable = $this->viewStorage->load($view_id)->getExecutable();
$executable->setDisplay($display_id);
$menu = $executable->display_handler->getOption('menu');
// We already have set the base_route for default tabs.
if (in_array($menu['type'], array('tab'))) {
$plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
$view_route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];
// Don't add a local task for views which override existing routes.
if ($view_route_name != $plugin_id) {
unset($local_tasks[$plugin_id]);
continue;
}
// Find out the parent route.
// @todo Find out how to find both the root and parent tab.
$path = $executable->display_handler->getPath();
$split = explode('/', $path);
array_pop($split);
$path = implode('/', $split);
$pattern = '/' . str_replace('%', '{}', $path);
if ($routes = $this->routeProvider->getRoutesByPattern($pattern)) {
foreach ($routes->all() as $name => $route) {
$local_tasks['views_view:' . $plugin_id]['base_route'] = $name;
// Skip after the first found route.
break;
}
}
}
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:38,代码来源:ViewsLocalTask.php
示例17: getTasksBuild
/**
* {@inheritdoc}
*/
public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability)
{
$tree = $this->getLocalTasksForRoute($current_route_name);
$build = array();
// Collect all route names.
$route_names = array();
foreach ($tree as $instances) {
foreach ($instances as $child) {
$route_names[] = $child->getRouteName();
}
}
// Pre-fetch all routes involved in the tree. This reduces the number
// of SQL queries that would otherwise be triggered by the access manager.
$routes = $route_names ? $this->routeProvider->getRoutesByNames($route_names) : array();
foreach ($tree as $level => $instances) {
/** @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */
foreach ($instances as $plugin_id => $child) {
$route_name = $child->getRouteName();
$route_parameters = $child->getRouteParameters($this->routeMatch);
// Given that the active flag depends on the route we have to add the
// route cache context.
$cacheability->addCacheContexts(['route']);
$active = $this->isRouteActive($current_route_name, $route_name, $route_parameters);
// The plugin may have been set active in getLocalTasksForRoute() if
// one of its child tabs is the active tab.
$active = $active || $child->getActive();
// @todo It might make sense to use link render elements instead.
$link = ['title' => $this->getTitle($child), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $child->getOptions($this->routeMatch)];
$access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE);
$build[$level][$plugin_id] = ['#theme' => 'menu_local_task', '#link' => $link, '#active' => $active, '#weight' => $child->getWeight(), '#access' => $access];
$cacheability->addCacheableDependency($access)->addCacheableDependency($child);
}
}
return $build;
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:38,代码来源:LocalTaskManager.php
示例18: getTasksBuild
/**
* {@inheritdoc}
*/
public function getTasksBuild($current_route_name)
{
$tree = $this->getLocalTasksForRoute($current_route_name);
$build = array();
// Collect all route names.
$route_names = array();
foreach ($tree as $instances) {
foreach ($instances as $child) {
$route_names[] = $child->getRouteName();
}
}
// Pre-fetch all routes involved in the tree. This reduces the number
// of SQL queries that would otherwise be triggered by the access manager.
$routes = $route_names ? $this->routeProvider->getRoutesByNames($route_names) : array();
foreach ($tree as $level => $instances) {
/** @var $instances \Drupal\Core\Menu\LocalTaskInterface[] */
foreach ($instances as $plugin_id => $child) {
$route_name = $child->getRouteName();
$route_parameters = $child->getRouteParameters($this->routeMatch);
// Find out whether the user has access to the task.
$access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account);
if ($access) {
$active = $this->isRouteActive($current_route_name, $route_name, $route_parameters);
// The plugin may have been set active in getLocalTasksForRoute() if
// one of its child tabs is the active tab.
$active = $active || $child->getActive();
// @todo It might make sense to use link render elements instead.
$link = array('title' => $this->getTitle($child), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $child->getOptions($this->routeMatch));
$build[$level][$plugin_id] = array('#theme' => 'menu_local_task', '#link' => $link, '#active' => $active, '#weight' => $child->getWeight(), '#access' => $access);
}
}
}
return $build;
}
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:LocalTaskManager.php
示例19: getBaseRoute
/**
* {@inheritdoc}
*/
public function getBaseRoute()
{
if ($this->routeCollection) {
return $this->routeCollection->get($this->getBaseRouteName());
} else {
return $this->routeProvider->getRouteByName($this->getBaseRouteName());
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:11,代码来源:ConfigNamesMapper.php
示例20: testGetRouteParametersForDynamicRouteWithUpcastedParameters
/**
* Tests the getRouteParameters method for a route with upcasted parameters.
*
* @covers ::getRouteParameters
*/
public function testGetRouteParametersForDynamicRouteWithUpcastedParameters()
{
$this->pluginDefinition = array('route_name' => 'test_route');
$route = new Route('/test-route/{parameter}');
$this->routeProvider->expects($this->once())->method('getRouteByName')->with('test_route')->will($this->returnValue($route));
$this->setupLocalTaskDefault();
$route_match = new RouteMatch('', $route, array('parameter' => (object) 'example2'), array('parameter' => 'example'));
$this->assertEquals(array('parameter' => 'example'), $this->localTaskBase->getRouteParameters($route_match));
}
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:14,代码来源:LocalTaskDefaultTest.php
注:本文中的Drupal\Core\Routing\RouteProviderInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论