node.post_update.php 828 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for Node.
  5. */
  6. use Drupal\Core\Entity\Entity\EntityFormDisplay;
  7. /**
  8. * Load all form displays for nodes, add status with these settings, save.
  9. */
  10. function node_post_update_configure_status_field_widget() {
  11. $query = \Drupal::entityQuery('entity_form_display')->condition('targetEntityType', 'node');
  12. $ids = $query->execute();
  13. $form_displays = EntityFormDisplay::loadMultiple($ids);
  14. // Assign status settings for each 'node' target entity types with 'default'
  15. // form mode.
  16. foreach ($form_displays as $id => $form_display) {
  17. /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $form_display */
  18. $form_display->setComponent('status', [
  19. 'type' => 'boolean_checkbox',
  20. 'settings' => [
  21. 'display_label' => TRUE,
  22. ],
  23. ])->save();
  24. }
  25. }