You are here

public function Flow::updateEntityTypeBundleVersion in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/Flow.php \Drupal\cms_content_sync\Entity\Flow::updateEntityTypeBundleVersion()

Update the version of an entity type bundle within a flow configuration.

Parameters

$entity_type:

$bundle:

Throws

\Exception

File

src/Entity/Flow.php, line 750

Class

Flow
Defines the "Content Sync - Flow" entity.

Namespace

Drupal\cms_content_sync\Entity

Code

public function updateEntityTypeBundleVersion($entity_type, $bundle) {

  // Get active version.
  $active_version = Flow::getEntityTypeVersion($entity_type, $bundle);

  // Get version from config.
  $config_key = $entity_type . '-' . $bundle;
  $flow_config = \Drupal::service('config.factory')
    ->getEditable('cms_content_sync.flow.' . $this
    ->id());
  $config_version = $flow_config
    ->get('sync_entities.' . $config_key . '.version');

  // Only update if required.
  if ($active_version != $config_version) {
    $default = self::getDefaultFieldConfigForEntityType($entity_type, $bundle, $this->sync_entities);
    foreach ($default as $id => $config) {
      $flow_config
        ->set('sync_entities.' . $id, $config);
    }
    $flow_config
      ->set('sync_entities.' . $config_key . '.version', $active_version);
    $flow_config
      ->save();
    \Drupal::messenger()
      ->addMessage('Content Sync - Flow: ' . $this
      ->label() . ' has been updated. Ensure to export the new configuration to the sync core.');
  }
}