You are here

public function CKEditorEntityLinkDialog::getUrl in CKEditor Entity Link 8

Helper function to return entity url.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Entity.

Return value

string Entity url.

Throws

\Drupal\Core\Entity\EntityMalformedException

1 call to CKEditorEntityLinkDialog::getUrl()
CKEditorEntityLinkDialog::submitForm in src/Form/CKEditorEntityLinkDialog.php

File

src/Form/CKEditorEntityLinkDialog.php, line 203

Class

CKEditorEntityLinkDialog
Provides a link dialog for text editors.

Namespace

Drupal\ckeditor_entity_link\Form

Code

public function getUrl(EntityInterface $entity) {
  switch ($entity
    ->getEntityType()
    ->get('id')) {
    case 'menu_link_content':
      return $entity
        ->getUrlObject()
        ->toString();
    case 'shortcut':
      return $entity
        ->getUrl()
        ->toString();
    case 'file':

      // Method toUrl is not implemented for File Entity, use File::url() instead.
      // Do not confuse with deprecated EntityInterface::url().
      return $entity
        ->url();
    default:
      return $entity
        ->toUrl()
        ->toString();
  }
}