Issue #2446783 by mpdonadio, dawehner, koence: Views preview not working without saving new display
parent
e11f8458ae
commit
994f683eea
|
@ -14,6 +14,7 @@ use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||||
use Drupal\Core\Form\FormInterface;
|
use Drupal\Core\Form\FormInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
use Drupal\Core\Routing\UrlGeneratorInterface;
|
use Drupal\Core\Routing\UrlGeneratorInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
use Drupal\views\ViewExecutable;
|
use Drupal\views\ViewExecutable;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
|
@ -21,6 +21,7 @@ use Drupal\views\ViewEntityInterface;
|
||||||
use Drupal\Component\Utility\Tags;
|
use Drupal\Component\Utility\Tags;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a view as a whole.
|
* Represents a view as a whole.
|
||||||
|
@ -1763,6 +1764,17 @@ class ViewExecutable implements \Serializable {
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?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 @@ class ViewUI implements ViewEntityInterface {
|
||||||
$executable->setArguments($args);
|
$executable->setArguments($args);
|
||||||
|
|
||||||
// Store the current view URL for later use:
|
// 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();
|
$path = $executable->getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue