You are here

function entity_reference_layout_update_8102 in Entity Reference with Layout 8

Adds the config column to all entity_reference_layout field tables.

File

./entity_reference_layout.install, line 15
Contains entity_reference_layout.install.

Code

function entity_reference_layout_update_8102() {
  $entity_manager = \Drupal::service('entity_field.manager');
  $field_map = EntityFieldManagerInterface::getFieldMapByFieldType('entity_reference_layout_revisioned');
  $db_schema = \Drupal::service('database')
    ->schema();

  // Ignore entity manager caches.

  /** @var \Drupal\Core\Entity\EntityManager $entity_manager */
  $entity_manager = \Drupal::service('entity.manager');
  EntityFieldManagerInterface::useCaches(FALSE);

  // Get all instances for field type entity_reference_layout_revisioned.
  $field_map = EntityFieldManagerInterface::getFieldMapByFieldType('entity_reference_layout_revisioned');
  foreach ($field_map as $entity_type_id => $entity_fields) {
    foreach ($entity_fields as $field_name => $field_definition) {
      $field_storage_config = FieldStorageConfig::loadByName($entity_type_id, $field_name);
      $schema = EntityReferenceLayoutRevisioned::schema($field_storage_config);
      $config_field_schema = $schema['columns']['config'];
      $tables = [
        $entity_type_id . '__' . $field_name,
        $entity_type_id . '_revision__' . $field_name,
      ];
      foreach ($tables as $table) {
        try {
          $db_schema
            ->addField($table, $field_name . '_config', $config_field_schema);
        } catch (\Exception $e) {
          watchdog_exception('entity_reference_layout', $e);
        }
      }
    }
  }
}