diff --git a/core/modules/system/lib/Drupal/system/Plugin/Condition/RouteCondition.php b/core/modules/system/lib/Drupal/system/Plugin/Condition/RouteCondition.php index 12113c3..ba4b1d3 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Condition/RouteCondition.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Condition/RouteCondition.php @@ -27,28 +27,47 @@ class RouteCondition extends ConditionPluginBase { /** * {@inheritdoc} */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form['pages'] = array( + '#type' => 'textfield', + '#title' => $this->t('Route'), + '#default_value' => $this->configuration['route'], + '#description' => $this->t("Specify a route by it's unique key."), + '#required' => TRUE, + ); + return parent::buildConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, array &$form_state) { + $this->configuration['route'] = $form_state['values']['route']; + parent::submitConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array('route' => ''); + } + + /** + * {@inheritdoc} + */ public function evaluate() { /* @var \Symfony\Component\HttpFoundation\Request $request */ $request = $this->getContextValue('request'); - $route_name = $request->get('_route'); - $route_parameters = $request->attributes->get('_route_params'); - - $routes = $this->configuration['routes']; - foreach ($routes as $name => $route_params) { - if ($route_name == $name) { - return TRUE; - } - } - return FALSE; + $route_name = $request->attributes->get('_route'); + return $route_name == $this->configuration['route']; } /** * {@inheritdoc} */ public function summary() { - $routes = $this->configuration['routes']; - $route_names = implode(", ", array_keys($routes)); - return $this->t('Return true on the following routes: @route_names', array('@route_names' => $route_names)); + return $this->t('Return true on the following route: @route', array('@route' => $this->configuration['route'])); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/Condition/RouteConditionTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/Condition/RouteConditionTest.php index 4843b5e..bc0e006 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Condition/RouteConditionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Condition/RouteConditionTest.php @@ -57,21 +57,17 @@ protected function setUp() { public function testConditions() { // Test a route with no params matches. - $routes = array( - 'node.view' => array(), - ); - $request = Request::create('/node/1'); $request->attributes->set('_route', 'node.view'); /* @var \Drupal\system\Plugin\Condition\RouteCondition $condition */ $condition = $this->pluginManager->createInstance('route'); - $condition->setConfig('routes', $routes) + $condition->setConfig('route', 'node.view') ->setContextValue('request', $request); $this->assertTrue($condition->execute(), 'A route with no params matches'); - $this->assertEqual($condition->summary(), 'Return true on the following routes: node.view', 'The condition summary matches for a route'); + $this->assertEqual($condition->summary(), 'Return true on the following route: node.view', 'The condition summary matches for a route'); // Test a route doesn't match.