Verified Commit a894a04b authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3277784 by Tim Bozeman, mrinalini9, larowlan: copyRawVariables should...

Issue #3277784 by Tim Bozeman, mrinalini9, larowlan: copyRawVariables should support default route parameters
parent b653e639
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@ protected function copyRawVariables(array $defaults) {
    foreach (array_intersect_key($defaults, $variables) as $key => $value) {
      $raw_variables[$key] = $value;
    }
    // Route defaults that do not start with a leading "_" are also
    // parameters, even if they are not included in path or host patterns.
    foreach ($route->getDefaults() as $name => $value) {
      if (!isset($raw_variables[$name]) && substr($name, 0, 1) !== '_') {
        $raw_variables[$name] = $value;
      }
    }
    return new ParameterBag($raw_variables);
  }

+5 −1
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public function testEnhance() {
   */
  public function testCopyRawVariables() {
    $route = new Route('/test/{id}');
    $route->setDefault('node_type', 'page');
    $defaults = [
      RouteObjectInterface::ROUTE_OBJECT => $route,
      'id' => '1',
@@ -90,7 +91,10 @@ public function testCopyRawVariables() {

        return $defaults;
      });
    $expected = new ParameterBag(['id' => 1]);
    $expected = new ParameterBag([
      'id' => 1,
      'node_type' => 'page',
    ]);
    $result = $this->paramConversionEnhancer->enhance($defaults, new Request());
    $this->assertEquals($result['_raw_variables'], $expected);
  }