From 96d0649c6fb415cb06ed7a689d69e52bcce544dd Mon Sep 17 00:00:00 2001 From: Eric Funk Date: Fri, 13 Dec 2013 10:36:47 +0100 Subject: [PATCH] Parse variablePattern and add mandatory fields to defaults --- Admin/RouteAdmin.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Admin/RouteAdmin.php b/Admin/RouteAdmin.php index a85ba5a3..eb364b0b 100644 --- a/Admin/RouteAdmin.php +++ b/Admin/RouteAdmin.php @@ -125,6 +125,19 @@ protected function configureFieldsForDefaults() $defaults[$name] = array($name, 'text', array('required' => false)); } } + + //parse variable pattern and add defaults for it - taken from routecompiler + /** @var $route Route */ + $route = $this->subject; + if ($route && $route->getVariablePattern()) { + preg_match_all('#\{\w+\}#', $route->getVariablePattern(), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + foreach ($matches as $match) { + $name = substr($match[0][0], 1, -1); + if (!isset($defaults[$name])) { + $defaults[$name] = array($name, 'text', array('required' => true)); + } + } + } return $defaults; }