Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Contains install and update functions for Field Layout.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Cache\Cache;
|
Chris@0
|
9 use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
Chris@0
|
10 use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
Chris@0
|
11 use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Implements hook_install().
|
Chris@0
|
15 */
|
Chris@0
|
16 function field_layout_install() {
|
Chris@0
|
17 // Ensure each entity display has a layout.
|
Chris@0
|
18 $entity_save = function (EntityDisplayWithLayoutInterface $entity) {
|
Chris@0
|
19 $entity->ensureLayout()->save();
|
Chris@0
|
20 };
|
Chris@0
|
21 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
22 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
23
|
Chris@0
|
24 // Invalidate the render cache since all content will now have a layout.
|
Chris@0
|
25 Cache::invalidateTags(['rendered']);
|
Chris@0
|
26 }
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * Implements hook_uninstall().
|
Chris@0
|
30 */
|
Chris@0
|
31 function field_layout_uninstall() {
|
Chris@0
|
32 // Reset each entity display to use the one-column layout to best approximate
|
Chris@0
|
33 // the absence of layouts.
|
Chris@0
|
34 $entity_save = function (EntityDisplayWithLayoutInterface $entity) {
|
Chris@0
|
35 $entity->setLayoutId('layout_onecol')->save();
|
Chris@0
|
36 };
|
Chris@0
|
37 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
38 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
39
|
Chris@0
|
40 // Invalidate the render cache since all content will no longer have a layout.
|
Chris@0
|
41 Cache::invalidateTags(['rendered']);
|
Chris@0
|
42 }
|