diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index 1eba5a9..dc7604a 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteProviderInterface; +use Drupal\views\Plugin\views\display\DisplayPluginInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\PathPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -281,6 +282,19 @@ public function render() { /** * {@inheritdoc} + */ + public function postSaveView(DisplayPluginInterface $original_display = NULL) { + parent::postSaveView($original_display); + + $style_plugin = $this->getPlugin('style'); + if (method_exists($style_plugin, 'postSaveView')) { + $style_plugin->postSaveView($original_display); + } + } + + + /** + * {@inheritdoc} * * The DisplayPluginBase preview method assumes we will be returning a render * array. The data plugin will already return the serialized string. diff --git a/core/modules/rest/src/Plugin/views/style/Serializer.php b/core/modules/rest/src/Plugin/views/style/Serializer.php index 09e94e6..4196669 100644 --- a/core/modules/rest/src/Plugin/views/style/Serializer.php +++ b/core/modules/rest/src/Plugin/views/style/Serializer.php @@ -8,9 +8,11 @@ namespace Drupal\rest\Plugin\views\style; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\Plugin\views\display\DisplayPluginInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\style\StylePluginBase; +use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -134,6 +136,27 @@ public function render() { } /** + * Act on saving a view. + * + * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $original_display + * (optional) The original display. + */ + public function postSaveView(DisplayPluginInterface $original_display = NULL) { + $original_style = $original_display ? $original_display->getOption('style') : []; + $original_style += ['options' => []]; + $original_style['options'] += ['formats' => []]; + + $this->options += ['formats' => []]; + + $original_formats = $original_style['options']['formats']; + $new_formats = $this->options['formats']; + + if ($original_formats != $new_formats) { + Views::routeRebuildNeeded(); + } + } + + /** * Gets a list of all available formats that can be requested. * * This will return the configured formats, or all formats if none have been diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 40b14c3..41fb1c1 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -346,6 +346,9 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { $original_executable = $this->original->getExecutable(); $original_executable->initDisplay(); } + else { + $original_executable->initDisplay(); + } foreach ($executable->displayHandlers as $display_id => $display_handler) { // Note: The original might have not had the new display, so let's cast it // to an array so postSaveView can deal with it diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php index 2c99787..0800ab9 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginInterface.php @@ -574,8 +574,7 @@ public function getExtenders(); * Act on saving a view. * * @param \Drupal\views\Plugin\views\display\DisplayPluginInterface $original_display - * @return - * @internal param \Drupal\views\Plugin\views\display\DisplayPluginInterface $orginal_display (optional) The display settings, of the original entity empty in case of a new view.* (optional) The display settings, of the original entity empty in case of a new view. + * (optional) The original display. */ public function postSaveView(DisplayPluginInterface $original_display = NULL); diff --git a/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php b/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php index 6b12287..5abc661 100644 --- a/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php +++ b/core/modules/views/src/Tests/Entity/BaseFieldAccessTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Entity; +use Drupal\Core\Cache\Cache; use Drupal\entity_test\Entity\EntityTest; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; @@ -44,15 +45,6 @@ protected function setUp() { \Drupal::entityManager()->clearCachedDefinitions(); $update_manager->applyUpdates(); ViewTestData::createTestViews(get_class($this), array('comment_test_views')); - \Drupal::state()->set('entity_test.views_data', [ - 'entity_test' => [ - 'test_text_access' => [ - 'field' => [ - 'id' => 'standard', - ], - ], - ], - ]); $entity_1 = EntityTest::create([ 'test_text_access' => 'no access value', ]); diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php index 81bb1c2..096f325 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php @@ -268,13 +268,7 @@ public function testInvalidDisplayPlugins() { $config->set('display.page_1.display_plugin', 'invalid'); $config->save(); - $this->drupalGet('test_display_invalid'); - $this->assertResponse(200); - $this->assertText('The "invalid" plugin does not exist.'); - - // Rebuild the router, and ensure that the path is not accessible anymore. - views_invalidate_cache(); - \Drupal::service('router.builder')->rebuildIfNeeded(); + \Drupal::service('router.builder')->rebuild(); $this->drupalGet('test_display_invalid'); $this->assertResponse(404);