Commit 994f683e authored by xjm's avatar xjm

Issue #2446783 by mpdonadio, dawehner, koence: Views preview not working without saving new display

parent e11f8458
......@@ -14,6 +14,7 @@
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Url;
use Drupal\views\ViewExecutable;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......
......@@ -21,6 +21,7 @@
use Drupal\Component\Utility\Tags;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Represents a view as a whole.
......@@ -1763,6 +1764,17 @@ public function hasUrl($args = NULL, $display_id = NULL) {
return FALSE;
}
// Look up the route name to make sure it exists. The name may exist, but
// not be available yet in some instances when editing a view and doing
// a live preview.
$provider = \Drupal::service('router.route_provider');
try {
$provider->getRouteByName($display_handler->getRouteName());
}
catch (RouteNotFoundException $e) {
return FALSE;
}
return TRUE;
}
......
<?php
/**
* @file
* Contains of \Drupal\views_ui\Tests\UnsavedPreviewTest.
*/
namespace Drupal\views_ui\Tests;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests covering Preview of unsaved Views.
*
* @group views_ui
*/
class UnsavedPreviewTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['content'];
/**
* An admin user with the 'administer views' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public static $modules = array('node', 'views_ui');
/**
* Sets up a Drupal site for running functional and integration tests.
*/
protected function setUp() {
parent::setUp(FALSE);
$this->adminUser = $this->drupalCreateUser(['administer views']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests previews of unsaved new page displays.
*/
public function testUnsavedPageDisplayPreview() {
$this->drupalCreateContentType(['type' => 'page']);
for ($i = 0; $i < 5; $i++) {
$this->drupalCreateNode();
}
$this->drupalGet('admin/structure/views/view/content');
$this->assertResponse(200);
$this->drupalPostForm(NULL, [], t('Add Page'));
$this->assertResponse(200);
$this->drupalGet('admin/structure/views/nojs/display/content/page_2/path');
$this->assertResponse(200);
$this->drupalPostForm(NULL, ['path' => 'foobarbaz'], t('Apply'));
$this->assertResponse(200);
$this->drupalPostForm(NULL, [], t('Update preview'));
$this->assertResponse(200);
$this->assertText(t('This display has no path'));
$this->drupalGet('admin/structure/views/view/content/edit/page_2');
$this->assertResponse(200);
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertResponse(200);
$this->drupalPostForm(NULL, [], t('Update preview'));
$this->assertResponse(200);
$this->assertLinkByHref('foobarbaz');
}
}
......@@ -598,7 +598,7 @@ public function renderPreview($display_id, $args = array()) {
$executable->setArguments($args);
// Store the current view URL for later use:
if ($executable->display_handler->getOption('path')) {
if ($executable->hasUrl() && $executable->display_handler->getOption('path')) {
$path = $executable->getUrl();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment