function SqlContentEntityStorageSchema::hasColumnChanges

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::hasColumnChanges()
  2. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::hasColumnChanges()
  3. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::hasColumnChanges()
  4. 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::hasColumnChanges()

Compares schemas to check for changes in the column definitions.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: Current field storage definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface $original: The original field storage definition.

Return value

bool Returns TRUE if there are schema changes in the column definitions.

2 calls to SqlContentEntityStorageSchema::hasColumnChanges()
SqlContentEntityStorageSchema::updateDedicatedTableSchema in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Updates the schema for a field stored in a shared table.
SqlContentEntityStorageSchema::updateSharedTableSchema in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Updates the schema for a field stored in a shared table.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 2477

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

protected function hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
  if ($storage_definition->getColumns() != $original->getColumns()) {
    // Base field definitions have schema data stored in the original
    // definition.
    return TRUE;
  }
  if (!$storage_definition->hasCustomStorage()) {
    // Compare storage requirements of current and original field definitions.
    // This checks whether the field requires dedicated table storage and
    // identifies schema changes related to table mapping.
    $table_mapping = $this->getTableMapping($this->entityType, [
      $storage_definition,
    ]);
    $table_mapping_original = $this->getTableMapping($this->entityType, [
      $original,
    ]);
    if ($table_mapping->requiresDedicatedTableStorage($storage_definition) !== $table_mapping_original->requiresDedicatedTableStorage($original)) {
      return TRUE;
    }
    $keys = array_flip($this->getColumnSchemaRelevantKeys());
    $definition_schema = $this->getSchemaFromStorageDefinition($storage_definition);
    foreach ($this->loadFieldSchemaData($original) as $table => $table_schema) {
      foreach ($table_schema['fields'] as $name => $spec) {
        $definition_spec = array_intersect_key($definition_schema[$table]['fields'][$name], $keys);
        $stored_spec = array_intersect_key($spec, $keys);
        if ($definition_spec != $stored_spec) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.