本文整理汇总了PHP中Drupal\Core\Routing\RouteMatchInterface::getRouteObject方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatchInterface::getRouteObject方法的具体用法?PHP RouteMatchInterface::getRouteObject怎么用?PHP RouteMatchInterface::getRouteObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Routing\RouteMatchInterface
的用法示例。
在下文中一共展示了RouteMatchInterface::getRouteObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$requirements = $current_route->getRequirements();
// Setting _method and _schema is deprecated since 2.7. Using
// setMethods() and setSchemes() are now the recommended ways.
unset($requirements['_method']);
unset($requirements['_schema']);
$route->setRequirements($requirements);
$route->setPath($current_route->getPath());
$route->setSchemes($current_route->getSchemes());
$route->setMethods($current_route->getMethods());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheContexts(['route']);
}
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例2: applies
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match)
{
if ($route_match->getRouteObject() !== null) {
$URI = $route_match->getRouteObject()->getPath();
// Use this theme on a certain route.
return substr($URI, 1, 4) == 'view';
}
}
示例3: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
}
}
示例4: isAdminRoute
/**
* Determines whether the active route is an admin one.
*
* @param \Symfony\Component\Routing\Route $route
* (optional) The route to determine whether it is an admin one. Per default
* this falls back to the route object on the active request.
*
* @return bool
* Returns TRUE if the route is an admin one, otherwise FALSE.
*/
public function isAdminRoute(Route $route = NULL)
{
if (!$route) {
$route = $this->routeMatch->getRouteObject();
if (!$route) {
return FALSE;
}
}
return (bool) $route->getOption('_admin_route');
}
示例5: processOutbound
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters)
{
if ($route_name === '<current>') {
if ($current_route = $this->routeMatch->getRouteObject()) {
$route->setPath($current_route->getPath());
$route->setRequirements($current_route->getRequirements());
$route->setOptions($current_route->getOptions());
$route->setDefaults($current_route->getDefaults());
$parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
} else {
// If we have no current route match available, point to the frontpage.
$route->setPath('/');
}
}
}
示例6: 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);
}
}
示例7: applies
/**
* @inheritdoc
*/
public function applies(RouteMatchInterface $route_match)
{
if ($route_match->getRouteObject()) {
return $route_match->getRouteName() == 'dmaps.locations.geocoder_options';
}
return FALSE;
}
示例8: 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;
}
}
示例9: 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,
];
}
示例10: loadBrowser
/**
* Loads entity browser object for this page.
*
* @return \Drupal\entity_browser\EntityBrowserInterface
* Loads the entity browser object
*/
protected function loadBrowser()
{
/** @var $route \Symfony\Component\Routing\Route */
$route = $this->currentRouteMatch->getRouteObject();
/** @var $browser \Drupal\entity_browser\EntityBrowserInterface */
return $this->browserStorage->load($route->getDefault('entity_browser_id'));
}
示例11: 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;
}
示例12: __construct
/**
* Constructs a new Entity Clone form.
*
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match service.
* @param \Drupal\Core\StringTranslation\TranslationManager $string_translation
* The string translation manager.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function __construct(EntityTypeManager $entity_type_manager, RouteMatchInterface $route_match, TranslationManager $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslationManager = $string_translation;
$parameter_name = $route_match->getRouteObject()->getOption('_entity_clone_entity_type_id');
$this->entity = $route_match->getParameter($parameter_name);
$this->entityTypeDefinition = $entity_type_manager->getDefinition($this->entity->getEntityTypeId());
}
示例13: entityTokens
/**
* Prints the loaded structure of the current entity.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* A RouteMatch object.
*
* @return array
* Array of page elements to render.
*/
public function entityTokens(RouteMatchInterface $route_match)
{
$output = [];
$parameter_name = $route_match->getRouteObject()->getOption('_token_entity_type_id');
$entity = $route_match->getParameter($parameter_name);
if ($entity && $entity instanceof EntityInterface) {
$output = $this->renderTokenTree($entity);
}
return $output;
}
示例14: view
/**
* Build the view draft page.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return array
* Render array.
*
* @throws \Exception
* Thrown when the entity is not found in the given graph.
*/
public function view(RouteMatchInterface $route_match)
{
$parameter_name = $route_match->getRouteObject()->getOption('entity_type_id');
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $route_match->getParameter($parameter_name);
$storage = $this->entityManager->getStorage($entity->getEntityTypeId());
$graph_name = $route_match->getRouteObject()->getOption('graph_name');
$storage->setRequestGraphs($entity->id(), [$graph_name]);
$draft_entity = $storage->load($entity->id());
if (!$draft_entity) {
// Should not occur: RdfGraphAccessCheck validates that the entity exists.
throw new \Exception('Entity not loaded from graph');
}
$page = $this->entityManager->getViewBuilder($entity->getEntityTypeId())->view($draft_entity, 'full');
$page['#pre_render'][] = [$this, 'buildTitle'];
$page['#entity_type'] = $entity->getEntityTypeId();
$page['#' . $page['#entity_type']] = $draft_entity;
return $page;
}
示例15: processPlaceholders
/**
* {@inheritdoc}
*/
public function processPlaceholders(array $placeholders)
{
// Routes can opt out from using the BigPipe HTML delivery technique.
if ($this->routeMatch->getRouteObject()->getOption('_no_big_pipe')) {
return [];
}
if (!$this->sessionConfiguration->hasSession($this->requestStack->getCurrentRequest())) {
return [];
}
return $this->doProcessPlaceholders($placeholders);
}