Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Resource routes uri translations #16429

Merged
merged 1 commit into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/Illuminate/Routing/ResourceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class ResourceRegistrar
*/
protected static $singularParameters = true;

/**
* Uri translations.
*
* @var array
*/
protected static $uriTranslations = [
'create' => 'create',
'edit' => 'edit',
];

/**
* Create a new resource registrar instance.
*
Expand Down Expand Up @@ -290,7 +300,7 @@ protected function addResourceIndex($name, $base, $controller, $options)
*/
protected function addResourceCreate($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name).'/create';
$uri = $this->getResourceUri($name).'/'.static::$uriTranslations['create'];

$action = $this->getResourceAction($name, $controller, 'create', $options);

Expand Down Expand Up @@ -344,7 +354,7 @@ protected function addResourceShow($name, $base, $controller, $options)
*/
protected function addResourceEdit($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name).'/{'.$base.'}/edit';
$uri = $this->getResourceUri($name).'/{'.$base.'}/'.static::$uriTranslations['edit'];

$action = $this->getResourceAction($name, $controller, 'edit', $options);

Expand Down Expand Up @@ -418,4 +428,25 @@ public static function setParameters(array $parameters = [])
{
static::$parameterMap = $parameters;
}

/**
* Get the uri translations.
*
* @return array
*/
public static function getUriTranslations()
{
return static::$uriTranslations;
}

/**
* Set the uri translations.
*
* @param array $translations
* @return void
*/
public static function setUriTranslations(array $translations = [])
{
static::$uriTranslations = array_merge(static::$uriTranslations, $translations);
}
}
11 changes: 11 additions & 0 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ public function resourceParameters(array $parameters = [])
ResourceRegistrar::setParameters($parameters);
}

/**
* Set the uri translations.
*
* @param array $translations
* @return void
*/
public function uriTranslations(array $translations = [])
{
ResourceRegistrar::setUriTranslations($translations);
}

/**
* Register an array of resource controllers.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,17 @@ public function testResourceRouting()

$this->assertEquals('foo-bars/{foo_bar}', $routes[0]->getUri());
$this->assertEquals('prefix.foo-bars.show', $routes[0]->getName());

ResourceRegistrar::setUriTranslations([
'create' => 'ajouter',
'edit' => 'modifier',
]);
$router = $this->getRouter();
$router->resource('foo', 'FooController');
$routes = $router->getRoutes();

$this->assertEquals('foo/ajouter', $routes->getByName('foo.create')->getUri());
$this->assertEquals('foo/{foo}/modifier', $routes->getByName('foo.edit')->getUri());
}

public function testResourceRoutingParameters()
Expand Down