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@17
|
9 use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
Chris@0
|
10 use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
Chris@0
|
11 use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
Chris@0
|
12 use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Implements hook_install().
|
Chris@0
|
16 */
|
Chris@0
|
17 function field_layout_install() {
|
Chris@0
|
18 // Ensure each entity display has a layout.
|
Chris@17
|
19 $entity_save = function (EntityDisplayInterface $entity) {
|
Chris@17
|
20 if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
Chris@17
|
21 $entity->ensureLayout()->save();
|
Chris@17
|
22 }
|
Chris@0
|
23 };
|
Chris@0
|
24 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
25 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
26
|
Chris@0
|
27 // Invalidate the render cache since all content will now have a layout.
|
Chris@0
|
28 Cache::invalidateTags(['rendered']);
|
Chris@0
|
29 }
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * Implements hook_uninstall().
|
Chris@0
|
33 */
|
Chris@0
|
34 function field_layout_uninstall() {
|
Chris@0
|
35 // Reset each entity display to use the one-column layout to best approximate
|
Chris@0
|
36 // the absence of layouts.
|
Chris@17
|
37 $entity_save = function (EntityDisplayInterface $entity) {
|
Chris@17
|
38 if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
Chris@17
|
39 $entity->setLayoutId('layout_onecol')->save();
|
Chris@17
|
40 }
|
Chris@0
|
41 };
|
Chris@0
|
42 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
43 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
44
|
Chris@0
|
45 // Invalidate the render cache since all content will no longer have a layout.
|
Chris@0
|
46 Cache::invalidateTags(['rendered']);
|
Chris@0
|
47 }
|