entity_reference_layout.install in Entity Reference with Layout 8
Contains entity_reference_layout.install.
File
entity_reference_layout.installView source
<?php
/**
* @file
* Contains entity_reference_layout.install.
*/
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\entity_reference_layout\Plugin\Field\FieldType\EntityReferenceLayoutRevisioned;
use Drupal\Core\Entity\EntityFieldManagerInterface;
/**
* Adds the config column to all entity_reference_layout field tables.
*/
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);
}
}
}
}
}
Functions
Name | Description |
---|---|
entity_reference_layout_update_8102 | Adds the config column to all entity_reference_layout field tables. |