You are here

public static function PushChanges::pushChanges in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Controller/PushChanges.php \Drupal\cms_content_sync\Controller\PushChanges::pushChanges()
  2. 2.0.x src/Controller/PushChanges.php \Drupal\cms_content_sync\Controller\PushChanges::pushChanges()

Published entity to Sync Core.

Parameters

string $flow_id:

\Drupal\Core\Entity\EntityInterface $entity:

string $entity_type:

Return value

\Symfony\Component\HttpFoundation\RedirectResponse

Throws

\Exception

1 call to PushChanges::pushChanges()
_cms_content_sync_add_save_push_action_submit in ./cms_content_sync.module
Save and push submit handler.
1 string reference to 'PushChanges::pushChanges'
cms_content_sync.routing.yml in ./cms_content_sync.routing.yml
cms_content_sync.routing.yml

File

src/Controller/PushChanges.php, line 29

Class

PushChanges
Push changes controller.

Namespace

Drupal\cms_content_sync\Controller

Code

public static function pushChanges($flow_id, $entity, $entity_type = '') {
  if (!$entity instanceof EntityInterface) {
    if ('' == $entity_type) {
      throw new \Exception(t('If no entity object is given, the entity_type is required.'));
    }
    $entity = \Drupal::entityTypeManager()
      ->getStorage($entity_type)
      ->load($entity);
    if (!$entity instanceof EntityInterface) {
      throw new \Exception(t('Entity could not be loaded.'));
    }
  }
  $flow = Flow::load($flow_id);
  if (!PushIntent::pushEntityFromUi($entity, PushIntent::PUSH_FORCED, SyncIntent::ACTION_UPDATE, $flow)) {
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning(t('%label has not been pushed to your @repository: @reason', [
      '%label' => $entity
        ->label(),
      '@repository' => _cms_content_sync_get_repository_name(),
      '@reason' => PushIntent::getNoPushReason($entity, true),
    ]));
  }
  return new RedirectResponse('/');
}