You are here

public function FieldBaseConfigurationHandler::writeToDatabase in Configuration Management 7.3

Saves the given configuration into the database.

Parameters

\Configuration\Configuration $configuration: The configuration to be saved.

Overrides ConfigurationHandler::writeToDatabase

File

src/Handlers/FieldBaseConfigurationHandler.php, line 50

Class

FieldBaseConfigurationHandler

Namespace

Configuration\Handlers

Code

public function writeToDatabase(Configuration $configuration) {
  $this->configuration_manager
    ->drupal()
    ->field_info_cache_clear();

  // Load all the existing field bases up-front so that we don't
  // have to rebuild the cache all the time.
  $existing_fields = $this->configuration_manager
    ->drupal()
    ->field_info_fields();
  $event = $this
    ->triggerEvent('write_to_database', $configuration);
  $field = $event->configuration
    ->getData();
  if (empty($field)) {
    return;
  }

  // Create or update field.
  if (isset($existing_fields[$field['field_name']])) {
    $existing_field = $existing_fields[$field['field_name']];
    if ($field + $existing_field !== $existing_field) {
      field_update_field($field);
    }
  }
  else {
    $this->configuration_manager
      ->drupal()
      ->field_create_field($field);
    $existing_fields[$field['field_name']] = $field;
  }
  $this->configuration_manager
    ->drupal()
    ->variable_set('menu_rebuild_needed', TRUE);
}