Commit 76d7ca84 authored by tstruyk's avatar tstruyk

Invalidate entity list cache.

parent c33eef72
......@@ -10,8 +10,8 @@
*/
function draggableviews_views_data_alter(&$data) {
$data['draggableviews_structure']['weight'] = array(
'title' => t('Weight'),
'group' => t('Draggableviews'),
'title' => t('DraggableViews Weight'),
'group' => t('Global'),
'help' => t('Display the weight value.'),
'field' => array(
'id' => 'numeric',
......@@ -135,6 +135,7 @@ function draggableviews_form_alter(&$form, \Drupal\Core\Form\FormStateInterface
function draggableviews_views_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$input = $form_state->getUserInput();
/** @var \Drupal\views\ViewExecutable $view */
$view = $form_state->getBuildInfo()['args'][0];
$view_name = $view->id();
$view_display = $view->current_display;
......@@ -167,7 +168,16 @@ function draggableviews_views_submit(&$form, \Drupal\Core\Form\FormStateInterfac
$connection->insert('draggableviews_structure')->fields($record)->execute();
$weight++;
}
// We invalidate the entity list cache, so other views are also aware of the
// cache.
$views_entity_table_info = $view->query->getEntityTableInfo();
// Find the entity type used by the view.
$result = array_keys(array_filter($views_entity_table_info, function($info) {
return $info['relationship_id'] == 'none';
}));
$entity_type_id = reset($result);
$list_cache_tags = \Drupal::entityTypeManager()->getDefinition($entity_type_id)->getListCacheTags();
\Drupal\Core\Cache\Cache::invalidateTags($list_cache_tags);
}
catch (\Exception $e) {
$transaction->rollback();
......
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