PushChanges.php in CMS Content Sync 8        
                          
                  
                        
  
  
  
  
File
  src/Controller/PushChanges.php
  
    View source  
  <?php
namespace Drupal\cms_content_sync\Controller;
use Drupal\cms_content_sync\Entity\Flow;
use Drupal\cms_content_sync\PushIntent;
use Drupal\cms_content_sync\SyncIntent;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
class PushChanges extends ControllerBase {
  
  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('/');
  }
  
  public function pushChangesEntitiesList() {
    return new Response('[]');
  }
}