You are here

public static function PushIntent::pushEntityFromUi in CMS Content Sync 8

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

Helper function to push an entity and display the user the results. If you want to make changes programmatically, use ::pushEntity() instead.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to push

string $reason: {@see Flow::PUSH_*}

string $action: {@see ::ACTION_*}

\Drupal\cms_content_sync\Entity\Flow $flow: The flow to be used. If none is given, all flows that may push this entity will be asked to do so for all relevant pools.

\Drupal\cms_content_sync\Entity\Pool $pool: The pool to be used. If not set, all relevant pools for the flow will be used one after another.

Return value

bool whether the entity is configured to be pushed or not

8 calls to PushIntent::pushEntityFromUi()
cms_content_sync_entity_delete in ./cms_content_sync.module
Push the entity deletion automatically if configured to do so.
cms_content_sync_entity_insert in ./cms_content_sync.module
Push the entity automatically if configured to do so.
cms_content_sync_entity_translation_delete in ./cms_content_sync.module
Implements hook_entity_translation_delete().
cms_content_sync_entity_update in ./cms_content_sync.module
Push the entity automatically if configured to do so.
cms_content_sync_update_taxonomy_tree_submit in ./cms_content_sync.module
React on changes within taxonomy trees.

... See full list

File

src/PushIntent.php, line 736

Class

PushIntent
Class PushIntent.

Namespace

Drupal\cms_content_sync

Code

public static function pushEntityFromUi(EntityInterface $entity, $reason, $action, Flow $flow = null, Pool $pool = null) {
  $messenger = \Drupal::messenger();
  try {
    $status = self::pushEntity($entity, $reason, $action, $flow, $pool);
    if ($status) {
      if (SyncIntent::ACTION_DELETE == $action) {
        $messenger
          ->addMessage(t('%label has been pushed to your @repository.', [
          '@repository' => _cms_content_sync_get_repository_name(),
          '%label' => $entity
            ->getEntityTypeId(),
        ]));
      }
      else {
        $messenger
          ->addMessage(t('%label has been pushed to your @repository.', [
          '@repository' => _cms_content_sync_get_repository_name(),
          '%label' => $entity
            ->label(),
        ]));
      }
      return true;
    }
    return false;
  } catch (SyncException $e) {
    $root_exception = $e
      ->getRootException();
    $message = $root_exception ? $root_exception
      ->getMessage() : ($e->errorCode == $e
      ->getMessage() ? '' : $e
      ->getMessage());
    if ($message) {
      $messenger
        ->addWarning(t('Failed to push %label to your @repository (%code). Message: %message', [
        '@repository' => _cms_content_sync_get_repository_name(),
        '%label' => $entity
          ->label(),
        '%code' => $e->errorCode,
        '%message' => $message,
      ]));
      \Drupal::logger('cms_content_sync')
        ->error('Failed to push %label to your @repository (%code). Message: %message<br>Error stack: %error_stack', [
        '@repository' => _cms_content_sync_get_repository_name(),
        '%label' => $entity
          ->label(),
        '%code' => $e->errorCode,
        '%message' => $message,
        '%error_stack' => $root_exception ? $root_exception
          ->getTraceAsString() : '',
      ]);
    }
    else {
      $messenger
        ->addWarning(t('Failed to push %label to your @repository (%code).', [
        '@repository' => _cms_content_sync_get_repository_name(),
        '%label' => $entity
          ->label(),
        '%code' => $e->errorCode,
      ]));
      \Drupal::logger('cms_content_sync')
        ->error('Failed to push %label to your @repository (%code).', [
        '@repository' => _cms_content_sync_get_repository_name(),
        '%label' => $entity
          ->label(),
        '%code' => $e->errorCode,
      ]);
    }
    self::$noPushReasons[$entity
      ->getEntityTypeId()][$entity
      ->uuid()] = $e;
    return true;
  }
}