Skip to content
Snippets Groups Projects
Commit 5d6cd82c authored by catch's avatar catch
Browse files

Issue #1942660 by larowlan, damiankloip, dawehner: Add a method to allow...

Issue #1942660 by larowlan, damiankloip, dawehner: Add a method to allow modules to clear the \Drupal\views\ViewsDataCache->storage during run-time.
parent e6f953db
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -53,6 +53,24 @@ public function testViewsFetchData() {
$data = $this->viewsDataCache->get();
$this->assertTrue(isset($data[$table_name]), 'Make sure the views_test_data info appears in the total views data.');
$this->assertEqual($data[$table_name], $expected_data[$table_name], 'Make sure the views_test_data has the expected values.');
// Verify that views_test_data_views_data() has only been called once.
$state = \Drupal::service('state');
$count = $state->get('views_test_data_views_data_count');
// Clear the storage/cache.
$this->viewsDataCache->clear();
// Get the data again.
$this->viewsDataCache->get($table_name);
// Verify that view_test_data_views_data() has run again.
$this->assertEqual($count + 1, $state->get('views_test_data_views_data_count'));
// Get the data again.
$this->viewsDataCache->get($table_name);
// Also request all table data.
$this->viewsDataCache->get();
// Verify that view_test_data_views_data() has not run again.
$this->assertEqual($count + 1, $state->get('views_test_data_views_data_count'));
}
/**
......
......@@ -256,4 +256,11 @@ public function destruct() {
}
}
/**
* Clears the class storage and cache.
*/
public function clear() {
$this->storage = array();
$this->cacheBackend->deleteAll();
}
}
......@@ -25,7 +25,17 @@ function views_test_data_views_analyze(ViewExecutable $view) {
* Implements hook_views_data().
*/
function views_test_data_views_data() {
return state()->get('views_test_data_views_data');
$state = Drupal::service('state');
// We use a state variable to keep track of how many times this function is
// called so we can assert that calls to
// \Drupal\views\ViewsDataCache::delete() trigger a rebuild of views data.
if (!($count = $state->get('views_test_data_views_data_count'))) {
$count = 0;
}
$count++;
$state->set('views_test_data_views_data_count', $count);
return $state->get('views_test_data_views_data');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment