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