You are here

public function SchedulerManager::entityUpdate in Scheduler 2.x

Updates db tables for entities that should have the Scheduler fields.

This is called from scheduler_modules_installed and scheduler_update_8201. It can also be called manually via drush command scheduler-entity-update.

Return value

array Labels of the entity types updated.

File

src/SchedulerManager.php, line 1080

Class

SchedulerManager
Defines a scheduler manager.

Namespace

Drupal\scheduler

Code

public function entityUpdate() {
  $entityUpdateManager = \Drupal::entityDefinitionUpdateManager();
  $updated = [];
  $list = $entityUpdateManager
    ->getChangeList();
  foreach ($list as $entity_type_id => $definitions) {
    if ($definitions['field_storage_definitions']['publish_on'] ?? 0) {
      $entity_type = $entityUpdateManager
        ->getEntityType($entity_type_id);
      $fields = scheduler_entity_base_field_info($entity_type);
      foreach ($fields as $field_name => $field_definition) {
        $entityUpdateManager
          ->installFieldStorageDefinition($field_name, $entity_type_id, $entity_type_id, $field_definition);
      }
      $this->logger
        ->notice('%entity updated with Scheduler publish_on and unpublish_on fields.', [
        '%entity' => $entity_type
          ->getLabel(),
      ]);
      $updated[] = (string) $entity_type
        ->getLabel();
    }
  }
  return $updated;
}