You are here

public function DefaultCropHandler::getViewUrl in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 2.0.x src/Plugin/cms_content_sync/entity_handler/DefaultCropHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler\DefaultCropHandler::getViewUrl()

Parameters

\Drupal\cms_content_sync\PushIntent $intent:

Return value

string

Throws

\Drupal\cms_content_sync\Exception\SyncException

Overrides EntityHandlerBase::getViewUrl

File

src/Plugin/cms_content_sync/entity_handler/DefaultCropHandler.php, line 115

Class

DefaultCropHandler
Class DefaultCropHandler, providing a minimalistic implementation for the crop entity type.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\entity_handler

Code

public function getViewUrl(EntityInterface $entity) {
  $uri = $entity
    ->get('uri')
    ->getValue()[0]['value'];

  /** @var FileInterface[] $files */
  $files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'uri' => $uri,
  ]);
  if (empty($files)) {
    return \Drupal::urlGenerator()
      ->generateFromRoute('<front>', [], [
      'absolute' => true,
    ]);
  }
  $file = reset($files);
  $uri = $file
    ->getFileUri();
  return \Drupal\Core\Url::fromUri(file_create_url($uri))
    ->toString();
}