You are here

function office_hours_update_8003 in Office Hours 8

Add 'comment' column.

Parameters

mixed $sandbox:

File

./office_hours.install, line 26
Install, update and uninstall functions for the Office hours module.

Code

function office_hours_update_8003(&$sandbox) {
  $spec = [
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
    'description' => "Stores the comment",
  ];
  $schema = Database::getConnection()
    ->schema();
  $fields = \Drupal::service('entity_field.manager')
    ->getFieldMapByFieldType('office_hours');
  foreach ($fields as $entity_type => $entity_fields) {
    foreach ($entity_fields as $field_name => $field_properties) {
      \Drupal::entityDefinitionUpdateManager()
        ->getFieldStorageDefinition($field_name, $entity_type);
      $table_names = $schema
        ->findTables("%{$field_name}%");
      foreach ($table_names as $table_name) {
        $schema
          ->addField($table_name, $field_name . '_comment', $spec);
      }
    }
  }
}