Commit e43e77b7 authored by Dries's avatar Dries
Browse files

Issue #1867310 by damiankloip: ViewExecutable::createDuplicate() is weird.

parent 2aa87d39
......@@ -52,7 +52,7 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
*
* @var string
*/
public $name = '';
public $name = NULL;
/**
* The description of the view, which is used only in the interface.
......@@ -168,6 +168,15 @@ public function id() {
return $this->get('name');
}
/**
* Overrides Drupal\Core\Config\Entity\ConfigEntityBase::createDuplicate().
*/
public function createDuplicate() {
$duplicate = parent::createDuplicate();
unset($duplicate->executable);
return $duplicate;
}
/**
* Implements Drupal\views\ViewStorageInterface::enable().
*/
......
......@@ -384,16 +384,16 @@ protected function displayMethodTests() {
*/
public function testCreateDuplicate() {
$view = views_get_view('archive');
$copy = $view->createDuplicate();
$copy = $view->storage->createDuplicate();
$this->assertTrue($copy instanceof View, 'The copied object is a View.');
// Check that the original view and the copy have different UUIDs.
$this->assertNotIdentical($view->storage->uuid(), $copy->uuid(), 'The copied view has a new UUID.');
// Check the 'name' (ID) is using the View objects default value ('') as it
// Check the 'name' (ID) is using the View objects default value (NULL) as it
// gets unset.
$this->assertIdentical($copy->id(), '', 'The ID has been reset.');
$this->assertIdentical($copy->id(), NULL, 'The ID has been reset.');
// Check the other properties.
// @todo Create a reusable property on the base test class for these?
......
......@@ -1818,19 +1818,13 @@ public function endQueryCapture() {
}
/**
* Overrides Drupal\entity\Entity::createDuplicate().
* Creates a duplicate ViewExecutable object.
*
* Makes a copy of this view that has been sanitized of handlers, any runtime
* data, ID, and UUID.
*/
public function createDuplicate() {
$data = config('views.view.' . $this->storage->id())->get();
// Reset the name and UUID.
unset($data['name']);
unset($data['uuid']);
return entity_create('view', $data);
return $this->storage->createDuplicate()->get('executable');
}
/**
......
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