本文整理汇总了PHP中Symfony\Component\Routing\Route::addDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::addDefaults方法的具体用法?PHP Route::addDefaults怎么用?PHP Route::addDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::addDefaults方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load($resource, $type = null)
{
if (true === $this->loaded) {
throw new \RuntimeException('Do not add this loader twice');
}
$routes = new RouteCollection();
$contextConfigLoader = $this->contextConfigLoader;
foreach ($contextConfigLoader->getRouting() as $routing) {
foreach ($routing as $id => $info) {
if (array_key_exists('pattern', $info)) {
$route = new Route($info['pattern']);
// merge options and defaults
if (array_key_exists('defaults', $info)) {
$route->addDefaults($info['defaults']);
}
if (array_key_exists('options', $info)) {
$route->addOptions($info['options']);
}
if (array_key_exists('requirements', $info)) {
$route->addRequirements($info['requirements']);
}
}
$routes->add($id, $route);
}
}
return $routes;
}
示例2: getDownloadRoute
/**
* Build the route for the actual download path.
*/
protected function getDownloadRoute(EntityTypeInterface $entity_type)
{
$entity_type_id = $entity_type->id();
$route = new Route("/rdf-export/{$entity_type_id}/{{$entity_type_id}}/{export_format}");
$route->addDefaults(['_controller' => '\\Drupal\\rdf_export\\Controller\\RdfExportController::download', '_title' => 'RDF Export'])->addRequirements(['_permission' => 'export rdf metadata'])->setOption('entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
示例3: getDevelRenderRoute
/**
* Gets the devel render route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getDevelRenderRoute(EntityTypeInterface $entity_type)
{
if ($devel_render = $entity_type->getLinkTemplate('devel-render')) {
$entity_type_id = $entity_type->id();
$route = new Route($devel_render);
$route->addDefaults(['_controller' => '\\Drupal\\devel\\Controller\\DevelController::entityRender', '_title' => 'Devel Render'])->addRequirements(['_permission' => 'access devel information'])->setOption('_admin_route', TRUE)->setOption('_devel_entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
}
示例4: getRdfGraphRoute
/**
* Gets the devel load route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRdfGraphRoute(EntityTypeInterface $entity_type, $graph_definition)
{
if ($rdf_draft = $entity_type->getLinkTemplate('rdf-draft-' . $graph_definition['name'])) {
$entity_type_id = $entity_type->id();
$route = new Route($rdf_draft);
$route->addDefaults(['_controller' => '\\Drupal\\rdf_draft\\Controller\\RdfController::view', '_title' => (string) t('View @title', ['@title' => (string) $graph_definition['title']])])->addRequirements(['_access_rdf_graph' => 'TRUE'])->setOption('entity_type_id', $entity_type_id)->setOption('graph_name', $graph_definition['name'])->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
return NULL;
}
示例5: getRevisionViewRoute
/**
* Gets the entity revision view route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionViewRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('revision')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('revision'));
$route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionController::view', '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title']);
$route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.view"]);
$route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
return $route;
}
}
示例6: getLatestVersionRoute
/**
* Gets the moderation-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getLatestVersionRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('latest-version') && $entity_type->hasViewBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('latest-version'));
$route->addDefaults(['_entity_view' => "{$entity_type_id}.full", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title'])->setRequirement('_entity_access', "{$entity_type_id}.view")->setRequirement('_permission', 'view latest version,view any unpublished content')->setRequirement('_content_moderation_latest_version', 'TRUE')->setOption('_content_moderation_entity_type', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id, 'load_forward_revision' => 1]]);
// Entity types with serial IDs can specify this in their route
// requirements, improving the matching process.
if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
$route->setRequirement($entity_type_id, '\\d+');
}
return $route;
}
}
示例7: getEntityCloneRoute
/**
* Gets the entity_clone route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getEntityCloneRoute(EntityTypeInterface $entity_type) {
if ($clone_form = $entity_type->getLinkTemplate('clone-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($clone_form);
$route
->addDefaults([
'_form' => '\Drupal\entity_clone\Form\EntityCloneForm',
'_title' => 'Clone ' . $entity_type->getLabel(),
])
->addRequirements([
'_permission' => 'clone ' . $entity_type->id() . ' entity',
])
->setOption('_entity_clone_entity_type_id', $entity_type_id)
->setOption('_admin_route', TRUE)
->setOption('parameters', [
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
]);
return $route;
}
}
示例8: getDeleteFormRoute
/**
* Gets the delete-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getDeleteFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('delete-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('delete-form'));
$route->addDefaults(['_entity_form' => "{$entity_type_id}.delete", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::deleteTitle'])->setRequirement('_entity_access', "{$entity_type_id}.delete")->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
// Entity types with serial IDs can specify this in their route
// requirements, improving the matching process.
if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
$route->setRequirement($entity_type_id, '\\d+');
}
return $route;
}
}
示例9: getDeleteFormRoute
/**
* Gets the delete-form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getDeleteFormRoute(EntityTypeInterface $entity_type)
{
if ($entity_type->hasLinkTemplate('delete-form')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('delete-form'));
$route->addDefaults(['_entity_form' => "{$entity_type_id}.delete", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::deleteTitle'])->setRequirement('_entity_access', "{$entity_type_id}.delete")->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
return $route;
}
}
示例10: getRevisionHistoryRoute
/**
* Gets the entity revision version history route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionHistoryRoute($entity_type)
{
if ($entity_type->hasLinkTemplate('version-history')) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('version-history'));
$route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionOverviewController::revisionOverviewController', '_title' => 'Revisions']);
$route->setRequirement('_entity_access_revision', "{$entity_type_id}.list");
$route->setOption('entity_type_id', $entity_type->id());
$route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()]]);
return $route;
}
}
示例11: getCollectionRoute
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type)
{
// If the entity type does not provide an admin permission, there is no way
// to control access, so we cannot provide a route in a sensible way.
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass() && ($admin_permission = $entity_type->getAdminPermission())) {
$route = new Route($entity_type->getLinkTemplate('collection'));
$route->addDefaults(['_entity_list' => $entity_type->id(), '_title' => '@label entities', '_title_arguments' => ['@label' => $entity_type->getLabel()]])->setRequirement('_permission', $admin_permission);
return $route;
}
}
示例12: addLocaleToRoute
/**
* Adds the locale to the route if prepend_locale is enabled.
*
* @param Route $route The route
*/
private function addLocaleToRoute(Route $route)
{
if ($this->prependLocale) {
$route->setPath('/{_locale}' . $route->getPath());
$route->addRequirements(['_locale' => '[a-z]{2}(\\-[A-Z]{2})?']);
} else {
$route->addDefaults(['_locale' => null]);
}
}