summaryrefslogtreecommitdiffstats
path: root/core/modules/views_ui
diff options
context:
space:
mode:
authorLee Rowlands2017-10-11 05:52:34 (GMT)
committerLee Rowlands2017-10-11 05:52:34 (GMT)
commit4997192be0c16d2d597718bdb384951580083bb0 (patch)
treec4829ee270ba1438148f5ffa30c2615b8c0fe347 /core/modules/views_ui
parent342b49212e922c3756bf9c808260ae4285a934ac (diff)
Issue #2449143 by damiankloip, tedbow, Wim Leers, dawehner, Pavan B S, Tybor, effulgentsia, larowlan: REST views specify HTML as a possible request format, so if there is a "regular" HTML view on the same path, it will serve JSON
Diffstat (limited to 'core/modules/views_ui')
-rw-r--r--core/modules/views_ui/src/ViewEditForm.php23
-rw-r--r--core/modules/views_ui/src/ViewListBuilder.php15
2 files changed, 29 insertions, 9 deletions
diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php
index 7066476..1781e33 100644
--- a/core/modules/views_ui/src/ViewEditForm.php
+++ b/core/modules/views_ui/src/ViewEditForm.php
@@ -15,6 +15,7 @@ use Drupal\user\SharedTempStoreFactory;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
/**
* Form controller for the Views edit form.
@@ -417,15 +418,25 @@ class ViewEditForm extends ViewFormBase {
// path.
elseif ($view->status() && $view->getExecutable()->displayHandlers->get($display['id'])->hasPath()) {
$path = $view->getExecutable()->displayHandlers->get($display['id'])->getPath();
+
if ($path && (strpos($path, '%') === FALSE)) {
- if (!parse_url($path, PHP_URL_SCHEME)) {
- // @todo Views should expect and store a leading /. See:
- // https://www.drupal.org/node/2423913
- $url = Url::fromUserInput('/' . ltrim($path, '/'));
+ // Wrap this in a try/catch as trying to generate links to some
+ // routes may throw a NotAcceptableHttpException if they do not
+ // respond to HTML, such as RESTExports.
+ try {
+ if (!parse_url($path, PHP_URL_SCHEME)) {
+ // @todo Views should expect and store a leading /. See:
+ // https://www.drupal.org/node/2423913
+ $url = Url::fromUserInput('/' . ltrim($path, '/'));
+ }
+ else {
+ $url = Url::fromUri("base:$path");
+ }
}
- else {
- $url = Url::fromUri("base:$path");
+ catch (NotAcceptableHttpException $e) {
+ $url = '/' . $path;
}
+
$build['top']['actions']['path'] = [
'#type' => 'link',
'#title' => $this->t('View @display_title', ['@display_title' => $display_title]),
diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php
index 42166be..628408e 100644
--- a/core/modules/views_ui/src/ViewListBuilder.php
+++ b/core/modules/views_ui/src/ViewListBuilder.php
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
/**
* Defines a class to build a listing of view entities.
@@ -255,9 +256,17 @@ class ViewListBuilder extends ConfigEntityListBuilder {
if ($display->hasPath()) {
$path = $display->getPath();
if ($view->status() && strpos($path, '%') === FALSE) {
- // @todo Views should expect and store a leading /. See:
- // https://www.drupal.org/node/2423913
- $rendered_path = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path));
+ // Wrap this in a try/catch as trying to generate links to some
+ // routes may throw a NotAcceptableHttpException if they do not
+ // respond to HTML, such as RESTExports.
+ try {
+ // @todo Views should expect and store a leading /. See:
+ // https://www.drupal.org/node/2423913
+ $rendered_path = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path));
+ }
+ catch (NotAcceptableHttpException $e) {
+ $rendered_path = '/' . $path;
+ }
}
else {
$rendered_path = '/' . $path;