本文整理汇总了PHP中Drupal\Core\Routing\RouteMatchInterface::getRouteName方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatchInterface::getRouteName方法的具体用法?PHP RouteMatchInterface::getRouteName怎么用?PHP RouteMatchInterface::getRouteName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Routing\RouteMatchInterface
的用法示例。
在下文中一共展示了RouteMatchInterface::getRouteName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* {@inheritdoc}
*/
public function build()
{
$config = $this->configuration;
$cacheability = new CacheableMetadata();
$tabs = ['#theme' => 'menu_local_tasks'];
// Add only selected levels for the printed output.
if ($config['primary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 0);
$cacheability = $cacheability->merge($links['cacheability']);
// Do not display single tabs.
$tabs += ['#primary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
}
if ($config['secondary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 1);
$cacheability = $cacheability->merge($links['cacheability']);
// Do not display single tabs.
$tabs += ['#secondary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
}
$build = [];
$cacheability->applyTo($build);
if (empty($tabs['#primary']) && empty($tabs['#secondary'])) {
return $build;
}
return $build + $tabs;
}
示例2: applies
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match)
{
if (strpos($route_match->getRouteName(), 'view.tmgmt_local_manage_translate_task') === 0 || strpos($route_match->getRouteName(), 'view.tmgmt_local_task_overview') === 0 || $route_match->getParameter('tmgmt_local_task') instanceof LocalTaskInterface || $route_match->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
return TRUE;
}
return FALSE;
}
示例3: blockAccess
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account)
{
$route_name = $this->routeMatch->getRouteName();
if ($account->isAnonymous() && !in_array($route_name, array('user.login', 'user.logout'))) {
return AccessResult::allowed()->addCacheContexts(['route.name', 'user.roles:anonymous']);
}
return AccessResult::forbidden();
}
示例4: build
/**
* {@inheritdoc}
*/
public function build()
{
$route_name = $this->routeMatch->getRouteName();
$local_actions = $this->localActionManager->getActionsForRoute($route_name);
if (empty($local_actions)) {
return [];
}
return $local_actions;
}
示例5: getActiveHelp
/**
* Returns the help associated with the active menu item.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*/
protected function getActiveHelp(Request $request)
{
// Do not show on a 403 or 404 page.
if ($request->attributes->has('exception')) {
return '';
}
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
return $help ? implode("\n", $help) : '';
}
示例6: isApplicable
/**
* {@inheritdoc}
*/
public function isApplicable()
{
// Remove on Admin routes.
$is_admin_route = $this->adminContext->isAdminRoute();
// Remove on Block Demo page.
$is_admin_demo_route = $this->routeMatch->getRouteName() === 'block.admin_demo';
// @todo Check if there is actually a different admin theme.
// https://www.drupal.org/node/2784853
return $this->account->hasPermission('administer blocks') && !$is_admin_route && !$is_admin_demo_route;
}
示例7: onView
/**
* Ensures that the theme registry was not initialized.
*/
public function onView(GetResponseEvent $event)
{
$current_route = $this->currentRouteMatch->getRouteName();
$entity_autcomplete_route = array('system.entity_autocomplete');
if (in_array($current_route, $entity_autcomplete_route)) {
if ($this->container->initialized('theme.registry')) {
throw new \Exception('registry initialized');
}
}
}
示例8: onResponse
/**
* Adds the route name as a cache tag to all cacheable responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
*/
public function onResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
if ($response instanceof CacheableResponseInterface) {
$cacheability_metadata = $response->getCacheableMetadata();
// If the route specifies a 'base route name', use that. Otherwise fall
// back to the route name. The 'base route name' is specified in
// \Drupal\page_manager\Routing\PageManagerRoutes.
$route_name = $this->routeMatch->getParameter('base_route_name') ?: $this->routeMatch->getRouteName();
$cacheability_metadata->addCacheTags(['page_manager_route_name:' . $route_name]);
}
}
示例9: isFrontPage
/**
* {@inheritdoc}
*/
public function isFrontPage()
{
// Cache the result as this is called often.
if (!isset($this->isCurrentFrontPage)) {
$this->isCurrentFrontPage = FALSE;
// Ensure that the code can also be executed when there is no active
// route match, like on exception responses.
if ($this->routeMatch->getRouteName()) {
$url = Url::fromRouteMatch($this->routeMatch);
$this->isCurrentFrontPage = $url->getRouteName() && '/' . $url->getInternalPath() === $this->getFrontPagePath();
}
}
return $this->isCurrentFrontPage;
}
示例10: determineBlockContext
/**
* {@inheritdoc}
*/
protected function determineBlockContext()
{
if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
$context = new Context(new ContextDefinition($route_contexts['node']['type']));
if ($node = $this->routeMatch->getParameter('node')) {
$context->setContextValue($node);
}
$this->addContext('node', $context);
} elseif ($this->routeMatch->getRouteName() == 'node.add') {
$node_type = $this->routeMatch->getParameter('node_type');
$context = new Context(new ContextDefinition('entity:node'));
$context->setContextValue(Node::create(array('type' => $node_type->id())));
$this->addContext('node', $context);
}
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
$account = $this->currentUser();
$account_is_user = $this->user->id() == $account->id();
if ($form_state['values']['set'] == 'new') {
// Save a new shortcut set with links copied from the user's default set.
/* @var \Drupal\shortcut\Entity\ShortcutSet $set */
$set = $this->shortcutSetStorage->create(array('id' => $form_state['values']['id'], 'label' => $form_state['values']['label']));
$set->save();
$replacements = array('%user' => $this->user->label(), '%set_name' => $set->label(), '@switch-url' => $this->url($this->routeMatch->getRouteName(), array('user' => $this->user->id())));
if ($account_is_user) {
// Only administrators can create new shortcut sets, so we know they have
// access to switch back.
drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
} else {
drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
}
$form_state['redirect_route'] = array('route_name' => 'shortcut.set_customize', 'route_parameters' => array('shortcut_set' => $set->id()));
} else {
// Switch to a different shortcut set.
/* @var \Drupal\shortcut\Entity\ShortcutSet $set */
$set = $this->shortcutSetStorage->load($form_state['values']['set']);
$replacements = array('%user' => $this->user->label(), '%set_name' => $set->label());
drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
}
// Assign the shortcut set to the provided user account.
$this->shortcutSetStorage->assignUser($set, $this->user);
}
示例12: addPage
/**
* Displays add links for the available bundles.
*
* Redirects to the add form if there's only one bundle available.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The route match.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|array
* If there's only one available bundle, a redirect response.
* Otherwise, a render array with the add links for each bundle.
*/
public function addPage(RouteMatchInterface $routeMatch) {
$routeName = $routeMatch->getRouteName();
$defaults = $routeMatch->getRouteObject()->getDefaults();
if (empty($defaults['_bundle_type'])) {
throw new \InvalidArgumentException(sprintf('The route "%s" must have a "_bundle_type" default parameter.', $routeName));
}
$formRouteName = str_replace('.add_page', '.add_form', $routeName);
$bundleType = $defaults['_bundle_type'];
$bundles = $this->entityManager()->getStorage($bundleType)->loadMultiple();
// Filter out the bundles the user doesn't have access to.
$accessControlHandler = $this->entityManager()->getAccessControlHandler($bundleType);
$bundles = array_filter($bundles, function($bundle) use ($accessControlHandler) {
return $accessControlHandler->createAccess($bundle->id());
});
// Redirect if there's only one bundle available.
if (count($bundles) == 1) {
$bundle = reset($bundles);
return $this->redirect($formRouteName, [$bundleType => $bundle->id()]);
}
return [
'#theme' => 'commerce_add_list',
'#bundles' => $bundles,
'#bundle_type' => $bundleType,
'#form_route_name' => $formRouteName,
];
}
示例13: build
/**
* {@inheritdoc}
*/
public function build()
{
// Do not show on a 403 or 404 page.
if ($this->request->attributes->has('exception')) {
return [];
}
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
$build = [];
// Remove any empty strings from $help.
foreach (array_filter($help) as $item) {
// Convert strings to #markup render arrays so that they will XSS admin
// filtered.
$build[] = is_array($item) ? $item : ['#markup' => $item];
}
return $build;
}
示例14: applies
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match)
{
if ($route_match->getRouteName() == 'diff.revisions_diff') {
if ($route_match->getParameter('filter') == 'raw-plain') {
return TRUE;
}
}
}
示例15: getRuntimeContexts
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids)
{
$result = [];
$context = new Context(new ContextDefinition('entity:node', NULL, FALSE));
if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
if ($node = $this->routeMatch->getParameter('node')) {
$context->setContextValue($node);
}
} elseif ($this->routeMatch->getRouteName() == 'node.add') {
$node_type = $this->routeMatch->getParameter('node_type');
$context->setContextValue(Node::create(array('type' => $node_type->id())));
}
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts(['route']);
$context->addCacheableDependency($cacheability);
$result['node'] = $context;
return $result;
}