You are here

public function EntityHandlerBase::getViewUrl 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::getViewUrl()

Parameters

\Drupal\cms_content_sync\PushIntent $intent:

Return value

string

Throws

\Drupal\cms_content_sync\Exception\SyncException

Overrides EntityHandlerInterface::getViewUrl

2 calls to EntityHandlerBase::getViewUrl()
DefaultContentEntityHandler::getViewUrl in src/Plugin/cms_content_sync/entity_handler/DefaultContentEntityHandler.php
EntityHandlerBase::push in src/Plugin/EntityHandlerBase.php
2 methods override EntityHandlerBase::getViewUrl()
DefaultContentEntityHandler::getViewUrl in src/Plugin/cms_content_sync/entity_handler/DefaultContentEntityHandler.php
DefaultCropHandler::getViewUrl in src/Plugin/cms_content_sync/entity_handler/DefaultCropHandler.php

File

src/Plugin/EntityHandlerBase.php, line 229

Class

EntityHandlerBase
Common base class for entity handler plugins.

Namespace

Drupal\cms_content_sync\Plugin

Code

public function getViewUrl(EntityInterface $entity) {
  if (!$entity
    ->hasLinkTemplate('canonical')) {
    throw new SyncException('No canonical link template found for entity ' . $entity
      ->getEntityTypeId() . '.' . $entity
      ->bundle() . ' ' . $entity
      ->id() . '. Please overwrite the handler to provide a URL.');
  }
  try {
    return $entity
      ->toUrl('canonical', [
      'absolute' => true,
    ])
      ->toString(true)
      ->getGeneratedUrl();
  } catch (\Exception $e) {
    throw new SyncException(SyncException::CODE_UNEXPECTED_EXCEPTION, $e);
  }
}