You are here

function layout_builder_update_8601 in Drupal 8

Enable Layout Builder for existing entity displays.

File

core/modules/layout_builder/layout_builder.install, line 47
Contains install and update functions for Layout Builder.

Code

function layout_builder_update_8601(&$sandbox) {
  $config_factory = \Drupal::configFactory();
  if (!isset($sandbox['count'])) {
    $sandbox['ids'] = $config_factory
      ->listAll('core.entity_view_display.');
    $sandbox['count'] = count($sandbox['ids']);
  }
  $ids = array_splice($sandbox['ids'], 0, 50);
  foreach ($ids as $id) {
    $display = $config_factory
      ->getEditable($id);
    if ($display
      ->get('third_party_settings.layout_builder')) {
      $display
        ->set('third_party_settings.layout_builder.enabled', TRUE)
        ->save();
    }
  }
  $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count'];
}