You are here

public function FieldInstanceConfigurationHandler::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/FieldInstanceConfigurationHandler.php, line 60

Class

FieldInstanceConfigurationHandler

Namespace

Configuration\Handlers

Code

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

  // Load all the existing fields and instance up-front so that we don't
  // have to rebuild the cache all the time.
  $existing_instances = $this->configuration_manager
    ->drupal()
    ->field_info_instances();
  $field_instance = $configuration
    ->getData();
  if (empty($field_instance)) {
    return;
  }
  if (isset($existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']])) {
    $existing_instance = $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']];
    if ($field_instance + $existing_instance != $existing_instance) {
      $this->configuration_manager
        ->drupal()
        ->field_update_instance($field_instance);
    }
  }
  else {
    $this->configuration_manager
      ->drupal()
      ->field_create_instance($field_instance);
  }
  $this->configuration_manager
    ->drupal()
    ->variable_set('menu_rebuild_needed', TRUE);
}