You are here

protected function EntityHandlerBase::setPreviewHtml in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 2.1.x src/Plugin/EntityHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityHandlerBase::setPreviewHtml()
1 call to EntityHandlerBase::setPreviewHtml()
EntityHandlerBase::push in src/Plugin/EntityHandlerBase.php

File

src/Plugin/EntityHandlerBase.php, line 820

Class

EntityHandlerBase
Common base class for entity handler plugins.

Namespace

Drupal\cms_content_sync\Plugin

Code

protected function setPreviewHtml($html, PushIntent $intent) {
  try {
    $intent
      ->getOperation()
      ->setPreviewHtml($html, $intent
      ->getActiveLanguage());
  } catch (\Exception $error) {
    $entity = $intent
      ->getEntity();
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning(t('Failed to save preview for %label: %error', [
      '%error' => $error
        ->getMessage(),
      '%label' => $entity
        ->label(),
    ]));
    \Drupal::logger('cms_content_sync')
      ->error('Failed to save preview when pushing @type.@bundle @id @label: @error', [
      '@type' => $entity
        ->getEntityTypeId(),
      '@bundle' => $entity
        ->bundle(),
      '@id' => $entity
        ->id(),
      '@label' => $entity
        ->label(),
      '@error' => $error
        ->getMessage(),
    ]);
  }
}