comparison core/modules/field_layout/field_layout.install @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
4 * @file 4 * @file
5 * Contains install and update functions for Field Layout. 5 * Contains install and update functions for Field Layout.
6 */ 6 */
7 7
8 use Drupal\Core\Cache\Cache; 8 use Drupal\Core\Cache\Cache;
9 use Drupal\Core\Entity\Display\EntityDisplayInterface;
9 use Drupal\Core\Entity\Entity\EntityFormDisplay; 10 use Drupal\Core\Entity\Entity\EntityFormDisplay;
10 use Drupal\Core\Entity\Entity\EntityViewDisplay; 11 use Drupal\Core\Entity\Entity\EntityViewDisplay;
11 use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface; 12 use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
12 13
13 /** 14 /**
14 * Implements hook_install(). 15 * Implements hook_install().
15 */ 16 */
16 function field_layout_install() { 17 function field_layout_install() {
17 // Ensure each entity display has a layout. 18 // Ensure each entity display has a layout.
18 $entity_save = function (EntityDisplayWithLayoutInterface $entity) { 19 $entity_save = function (EntityDisplayInterface $entity) {
19 $entity->ensureLayout()->save(); 20 if ($entity instanceof EntityDisplayWithLayoutInterface) {
21 $entity->ensureLayout()->save();
22 }
20 }; 23 };
21 array_map($entity_save, EntityViewDisplay::loadMultiple()); 24 array_map($entity_save, EntityViewDisplay::loadMultiple());
22 array_map($entity_save, EntityFormDisplay::loadMultiple()); 25 array_map($entity_save, EntityFormDisplay::loadMultiple());
23 26
24 // Invalidate the render cache since all content will now have a layout. 27 // Invalidate the render cache since all content will now have a layout.
29 * Implements hook_uninstall(). 32 * Implements hook_uninstall().
30 */ 33 */
31 function field_layout_uninstall() { 34 function field_layout_uninstall() {
32 // Reset each entity display to use the one-column layout to best approximate 35 // Reset each entity display to use the one-column layout to best approximate
33 // the absence of layouts. 36 // the absence of layouts.
34 $entity_save = function (EntityDisplayWithLayoutInterface $entity) { 37 $entity_save = function (EntityDisplayInterface $entity) {
35 $entity->setLayoutId('layout_onecol')->save(); 38 if ($entity instanceof EntityDisplayWithLayoutInterface) {
39 $entity->setLayoutId('layout_onecol')->save();
40 }
36 }; 41 };
37 array_map($entity_save, EntityViewDisplay::loadMultiple()); 42 array_map($entity_save, EntityViewDisplay::loadMultiple());
38 array_map($entity_save, EntityFormDisplay::loadMultiple()); 43 array_map($entity_save, EntityFormDisplay::loadMultiple());
39 44
40 // Invalidate the render cache since all content will no longer have a layout. 45 // Invalidate the render cache since all content will no longer have a layout.