Commit 8b386d9a authored by alexpott's avatar alexpott

Issue #1930048 by damiankloip, dawehner: Use reflection for ViewExectuable::destroy().

parent 31618908
......@@ -315,23 +315,31 @@ public function testDestroy() {
* @param \Drupal\views\ViewExecutable $view
*/
protected function assertViewDestroy($view) {
$this->assertFalse(isset($view->displayHandlers), 'Make sure all displays are destroyed');
$this->assertFalse(isset($view->filter), 'Make sure all filter handlers are destroyed');
$this->assertFalse(isset($view->field), 'Make sure all field handlers are destroyed');
$this->assertFalse(isset($view->argument), 'Make sure all argument handlers are destroyed');
$this->assertFalse(isset($view->relationship), 'Make sure all relationship handlers are destroyed');
$this->assertFalse(isset($view->sort), 'Make sure all sort handlers are destroyed');
$this->assertFalse(isset($view->area), 'Make sure all area handlers are destroyed');
$keys = array('current_display', 'display_handler', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
foreach ($keys as $key) {
$this->assertFalse(isset($view->{$key}), $key);
$reflection = new \ReflectionClass($view);
$defaults = $reflection->getDefaultProperties();
// The storage should remain.
unset($defaults['storage']);
foreach ($defaults as $property => $default) {
$this->assertIdentical($this->getProtectedProperty($view, $property), $default);
}
$this->assertEqual($view->built, FALSE);
$this->assertEqual($view->executed, FALSE);
$this->assertEqual($view->build_info, array());
$this->assertEqual($view->attachment_before, '');
$this->assertEqual($view->attachment_after, '');
}
/**
* Returns a protected property from a class instance.
*
* @param object $instance
* The class instance to return the property from.
* @param string $property
* The name of the property to return.
*
* @return mixed
* The instance property value.
*/
protected function getProtectedProperty($instance, $property) {
$reflection = new \ReflectionProperty($instance, $property);
$reflection->setAccessible(TRUE);
return $reflection->getValue($instance);
}
/**
......
......@@ -1709,15 +1709,11 @@ public function createDuplicate() {
* collected.
*/
public function destroy() {
unset($this->displayHandlers);
foreach ($this::viewsHandlerTypes() as $type => $info) {
if (isset($this->$type)) {
$handlers = &$this->$type;
foreach ($handlers as $id => $item) {
$handlers[$id]->destroy();
foreach ($this->{$type} as $handler) {
$handler->destroy();
}
unset($handlers);
}
}
......@@ -1725,24 +1721,14 @@ public function destroy() {
$this->style_plugin->destroy();
}
$keys = array('current_display', 'display_handler', 'displayHandlers', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'rowPlugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
foreach ($keys as $key) {
unset($this->$key);
$reflection = new \ReflectionClass($this);
$defaults = $reflection->getDefaultProperties();
// The storage should not be reset. This is not generated by the execution
// of a view.
unset($defaults['storage']);
foreach ($defaults as $property => $default) {
$this->{$property} = $default;
}
// These keys are checked by the next init, so instead of unsetting them,
// just set the default values.
$keys = array('items_per_page', 'offset', 'current_page');
foreach ($keys as $key) {
if (isset($this->$key)) {
$this->$key = NULL;
}
}
$this->built = $this->executed = FALSE;
$this->build_info = array();
$this->attachment_before = '';
$this->attachment_after = '';
}
/**
......
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