Mercurial > hg > isophonics-drupal-site
comparison core/modules/layout_builder/layout_builder.post_update.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
2 | 2 |
3 /** | 3 /** |
4 * @file | 4 * @file |
5 * Post update functions for Layout Builder. | 5 * Post update functions for Layout Builder. |
6 */ | 6 */ |
7 | |
8 use Drupal\Core\Config\Entity\ConfigEntityUpdater; | |
9 use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface; | |
7 | 10 |
8 /** | 11 /** |
9 * Rebuild plugin dependencies for all entity view displays. | 12 * Rebuild plugin dependencies for all entity view displays. |
10 */ | 13 */ |
11 function layout_builder_post_update_rebuild_plugin_dependencies(&$sandbox = NULL) { | 14 function layout_builder_post_update_rebuild_plugin_dependencies(&$sandbox = NULL) { |
22 } | 25 } |
23 } | 26 } |
24 | 27 |
25 $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count']; | 28 $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count']; |
26 } | 29 } |
30 | |
31 /** | |
32 * Ensure all extra fields are properly stored on entity view displays. | |
33 * | |
34 * Previously | |
35 * \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::setComponent() | |
36 * was not correctly setting the configuration for extra fields. This function | |
37 * calls setComponent() for all extra field components to ensure the updated | |
38 * logic is invoked on all extra fields to correct the settings. | |
39 */ | |
40 function layout_builder_post_update_add_extra_fields(&$sandbox = NULL) { | |
41 $entity_field_manager = \Drupal::service('entity_field.manager'); | |
42 \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'entity_view_display', function (LayoutEntityDisplayInterface $display) use ($entity_field_manager) { | |
43 if (!$display->isLayoutBuilderEnabled()) { | |
44 return FALSE; | |
45 } | |
46 | |
47 $extra_fields = $entity_field_manager->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle()); | |
48 $components = $display->getComponents(); | |
49 // Sort the components to avoid them being reordered by setComponent(). | |
50 uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); | |
51 $result = FALSE; | |
52 foreach ($components as $name => $component) { | |
53 if (isset($extra_fields['display'][$name])) { | |
54 $display->setComponent($name, $component); | |
55 $result = TRUE; | |
56 } | |
57 } | |
58 return $result; | |
59 }); | |
60 } |