Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/datetime_range/datetime_range.post_update.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
3 /** | 3 /** |
4 * @file | 4 * @file |
5 * Post-update functions for Datetime Range module. | 5 * Post-update functions for Datetime Range module. |
6 */ | 6 */ |
7 | 7 |
8 use Drupal\views\Views; | |
9 | |
8 /** | 10 /** |
9 * Clear caches to ensure schema changes are read. | 11 * Clear caches to ensure schema changes are read. |
10 */ | 12 */ |
11 function datetime_range_post_update_translatable_separator() { | 13 function datetime_range_post_update_translatable_separator() { |
12 // Empty post-update hook to cause a cache rebuild. | 14 // Empty post-update hook to cause a cache rebuild. |
13 } | 15 } |
16 | |
17 /** | |
18 * Update existing views using datetime_range fields. | |
19 */ | |
20 function datetime_range_post_update_views_string_plugin_id() { | |
21 | |
22 /* @var \Drupal\views\Entity\View[] $views */ | |
23 $views = \Drupal::entityTypeManager()->getStorage('view')->loadMultiple(); | |
24 $config_factory = \Drupal::configFactory(); | |
25 $message = NULL; | |
26 $ids = []; | |
27 | |
28 foreach ($views as $view) { | |
29 $displays = $view->get('display'); | |
30 $needs_bc_layer_update = FALSE; | |
31 | |
32 foreach ($displays as $display_name => $display) { | |
33 | |
34 // Check if datetime_range filters need updates. | |
35 if (!$needs_bc_layer_update && isset($display['display_options']['filters'])) { | |
36 foreach ($display['display_options']['filters'] as $field_name => $filter) { | |
37 if ($filter['plugin_id'] == 'string') { | |
38 | |
39 // Get field config. | |
40 $filter_views_data = Views::viewsData()->get($filter['table'])[$filter['field']]['filter']; | |
41 if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) { | |
42 continue; | |
43 } | |
44 $field_storage_name = 'field.storage.' . $filter_views_data['entity_type'] . '.' . $filter_views_data['field_name']; | |
45 $field_configuration = $config_factory->get($field_storage_name); | |
46 | |
47 if ($field_configuration->get('type') == 'daterange') { | |
48 // Trigger the BC layer control. | |
49 $needs_bc_layer_update = TRUE; | |
50 continue 2; | |
51 } | |
52 } | |
53 } | |
54 } | |
55 | |
56 // Check if datetime_range sort handlers need updates. | |
57 if (!$needs_bc_layer_update && isset($display['display_options']['sorts'])) { | |
58 foreach ($display['display_options']['sorts'] as $field_name => $sort) { | |
59 if ($sort['plugin_id'] == 'standard') { | |
60 | |
61 // Get field config. | |
62 $sort_views_data = Views::viewsData()->get($sort['table'])[$sort['field']]['sort']; | |
63 if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) { | |
64 continue; | |
65 } | |
66 $field_storage_name = 'field.storage.' . $sort_views_data['entity_type'] . '.' . $sort_views_data['field_name']; | |
67 $field_configuration = $config_factory->get($field_storage_name); | |
68 | |
69 if ($field_configuration->get('type') == 'daterange') { | |
70 // Trigger the BC layer control. | |
71 $needs_bc_layer_update = TRUE; | |
72 continue 2; | |
73 } | |
74 } | |
75 } | |
76 } | |
77 } | |
78 | |
79 // If current view needs BC layer updates save it and the hook view_presave | |
80 // will do the rest. | |
81 if ($needs_bc_layer_update) { | |
82 $view->save(); | |
83 $ids[] = $view->id(); | |
84 } | |
85 } | |
86 | |
87 if (!empty($ids)) { | |
88 $message = \Drupal::translation()->translate('Updated datetime_range filter/sort plugins for views: @ids', ['@ids' => implode(', ', array_unique($ids))]); | |
89 } | |
90 | |
91 return $message; | |
92 } |