本文整理汇总了PHP中Drupal\Core\Routing\RouteMatchInterface::getParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatchInterface::getParameter方法的具体用法?PHP RouteMatchInterface::getParameter怎么用?PHP RouteMatchInterface::getParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Routing\RouteMatchInterface
的用法示例。
在下文中一共展示了RouteMatchInterface::getParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: access
/**
* Checks if the user has access to underlying storage for a Panels display.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
{
$panels_storage_type = $route_match->getParameter('panels_storage_type');
$panels_storage_id = $route_match->getParameter('panels_storage_id');
$op = $route->getRequirement('_panels_storage_access');
return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account);
}
示例2: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = array();
$breadcrumb[] = $this->l($this->t('Home'), '<front>');
$entity = $this->entityManager->getStorage($route_match->getParameter('entity_type'))->load($route_match->getParameter('entity_id'));
$breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo());
return $breadcrumb;
}
示例3: build
/**
* @inheritdoc
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = new Breadcrumb();
$geocoder = $route_match->getParameter('service');
$current_route = $route_match->getRouteName();
$links = [Link::createFromRoute($this->t('Home'), '<front>'), Link::createFromRoute($this->t('Administration'), 'system.admin'), Link::createFromRoute($this->t('Configuration'), 'system.admin_config'), Link::createFromRoute($this->t('Dmaps'), 'dmaps.settings'), Link::createFromRoute($this->t('Geocoding'), 'dmaps.locations.geocoding_options'), Link::createFromRoute($this->t('Geocoding %service', ['%service' => $geocoder]), $current_route, ['iso' => $route_match->getParameter('iso'), 'service' => $geocoder])];
$breadcrumb->setLinks($links);
return $breadcrumb;
}
示例4: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$route_name = $route_match->getRouteName();
if ($route_name == 'node.view' && $route_match->getParameter('node') && isset($route_match->getParameter('node')->taxonomy_catalog)) {
return $this->catalogBreadcrumb($route_match->getParameter('node'));
} elseif (substr($route_name, 0, 16) == 'view.uc_catalog.' && $route_match->getParameter('arg_term_node_tid_depth')) {
return $this->catalogTermBreadcrumb($route_match->getParameter('arg_term_node_tid_depth'));
}
}
示例5: testGetParameter
/**
* @covers ::getParameter
* @covers \Drupal\Core\Routing\RouteMatch::getParameterNames
* @dataProvider routeMatchProvider
*/
public function testGetParameter(RouteMatchInterface $route_match, Route $route, $parameters, $expected_filtered_parameters)
{
foreach ($expected_filtered_parameters as $name => $expected_value) {
$this->assertSame($expected_value, $route_match->getParameter($name));
}
foreach (array_diff_key($parameters, $expected_filtered_parameters) as $name) {
$this->assertNull($route_match->getParameter($name));
}
}
示例6: 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]);
}
}
示例7: getTitle
/**
* {@inheritdoc}
*/
public function getTitle()
{
$route = $this->routeProvider->getRouteByName($this->getRouteName());
$param = $route->getDefault('event');
if ($event = $this->currentRoute->getParameter($param)) {
if ($this->eventManager->getMeta($event)->isDefaultRules('rng_event.register')) {
return $this->t('Customize access rules');
} else {
return $this->t('Reset access rules to site default');
}
}
}
示例8: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = [Link::createFromRoute($this->t('Home'), '<front>')];
$entity = $route_match->getParameter('entity');
$breadcrumb[] = new Link($entity->label(), $entity->urlInfo());
if (($pid = $route_match->getParameter('pid')) && ($comment = $this->storage->load($pid))) {
/** @var \Drupal\comment\CommentInterface $comment */
// Display link to parent comment.
// @todo Clean-up permalink in https://www.drupal.org/node/2198041
$breadcrumb[] = new Link($comment->getSubject(), $comment->urlInfo());
}
return $breadcrumb;
}
示例9: getArgument
/**
* {@inheritdoc}
*/
public function getArgument()
{
// If there is a user object in the current route.
if ($user = $this->routeMatch->getParameter('user')) {
if ($user instanceof UserInterface) {
return $user->id();
}
}
// If option to use node author; and node in current route.
if (!empty($this->options['user']) && ($node = $this->routeMatch->getParameter('node'))) {
if ($node instanceof NodeInterface) {
return $node->getOwnerId();
}
}
}
示例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: performOperation
/**
* Performs an operation on the currency entity.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The route match.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect back to the currency listing.
*/
public function performOperation(RouteMatchInterface $routeMatch) {
$currency = $routeMatch->getParameter('commerce_currency');
$op = $routeMatch->getParameter('op');
$currency->$op()->save();
if ($op == 'enable') {
drupal_set_message($this->t('The %label currency has been enabled.', ['%label' => $currency->label()]));
}
elseif ($op == 'disable') {
drupal_set_message($this->t('The %label currency has been disabled.', ['%label' => $currency->label()]));
}
$url = $currency->urlInfo('collection');
return $this->redirect($url->getRouteName(), $url->getRouteParameters(), $url->getOptions());
}
示例12: handle
/**
* Handler a response for a given view and display.
*
* @param string $view_id
* The ID of the view
* @param string $display_id
* The ID of the display.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @return null|void
*/
public function handle($view_id, $display_id, RouteMatchInterface $route_match)
{
$args = array();
$route = $route_match->getRouteObject();
$map = $route->hasOption('_view_argument_map') ? $route->getOption('_view_argument_map') : array();
foreach ($map as $attribute => $parameter_name) {
// Allow parameters be pulled from the request.
// The map stores the actual name of the parameter in the request. Views
// which override existing controller, use for example 'node' instead of
// arg_nid as name.
if (isset($map[$attribute])) {
$attribute = $map[$attribute];
}
if ($arg = $route_match->getRawParameter($attribute)) {
} else {
$arg = $route_match->getParameter($attribute);
}
if (isset($arg)) {
$args[] = $arg;
}
}
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase $class */
$class = $route->getOption('_view_display_plugin_class');
if ($route->getOption('returns_response')) {
/** @var \Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface $class */
return $class::buildResponse($view_id, $display_id, $args);
} else {
$build = $class::buildBasicRenderable($view_id, $display_id, $args, $route);
Page::setPageRenderArray($build);
return $build;
}
}
示例13: access
/**
* Checks access to the translation overview for the entity and bundle.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param string $entity_type_id
* The entity type ID.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(RouteMatchInterface $route_match, AccountInterface $account, $entity_type_id)
{
/* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
if ($entity && $entity->isTranslatable()) {
// Get entity base info.
$bundle = $entity->bundle();
// Get entity access callback.
$definition = $this->entityManager->getDefinition($entity_type_id);
$translation = $definition->get('translation');
$access_callback = $translation['content_translation']['access_callback'];
$access = call_user_func($access_callback, $entity);
if ($access->isAllowed()) {
return $access;
}
// Check "translate any entity" permission.
if ($account->hasPermission('translate any entity')) {
return AccessResult::allowed()->cachePerPermissions()->inheritCacheability($access);
}
// Check per entity permission.
$permission = "translate {$entity_type_id}";
if ($definition->getPermissionGranularity() == 'bundle') {
$permission = "translate {$bundle} {$entity_type_id}";
}
return AccessResult::allowedIfHasPermission($account, $permission)->inheritCacheability($access);
}
// No opinion.
return AccessResult::neutral();
}
示例14: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$book_nids = array();
$breadcrumb = new Breadcrumb();
$links = array(Link::createFromRoute($this->t('Home'), '<front>'));
$book = $route_match->getParameter('node')->book;
$depth = 1;
// We skip the current node.
while (!empty($book['p' . ($depth + 1)])) {
$book_nids[] = $book['p' . $depth];
$depth++;
}
$parent_books = $this->nodeStorage->loadMultiple($book_nids);
if (count($parent_books) > 0) {
$depth = 1;
while (!empty($book['p' . ($depth + 1)])) {
if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
$access = $parent_book->access('view', $this->account, TRUE);
$breadcrumb->addCacheableDependency($access);
if ($access->isAllowed()) {
$breadcrumb->addCacheableDependency($parent_book);
$links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
}
}
$depth++;
}
}
$breadcrumb->setLinks($links);
$breadcrumb->addCacheContexts(['route.book_navigation']);
return $breadcrumb;
}
示例15: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = new Breadcrumb();
$breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
$term = $route_match->getParameter('taxonomy_term');
// Breadcrumb needs to have terms cacheable metadata as a cacheable
// dependency even though it is not shown in the breadcrumb because e.g. its
// parent might have changed.
$breadcrumb->addCacheableDependency($term);
// @todo This overrides any other possible breadcrumb and is a pure
// hard-coded presumption. Make this behavior configurable per
// vocabulary or term.
$parents = $this->termStorage->loadAllParents($term->id());
// Remove current term being accessed.
array_shift($parents);
foreach (array_reverse($parents) as $term) {
$term = $this->entityManager->getTranslationFromContext($term);
$breadcrumb->addCacheableDependency($term);
$breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())));
}
// This breadcrumb builder is based on a route parameter, and hence it
// depends on the 'route' cache context.
$breadcrumb->addCacheContexts(['route']);
return $breadcrumb;
}