From 466420be275aeb0af1abd34639e5a570db50313f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 21 Jun 2021 01:55:47 +0200 Subject: Add method getEntityURL to Application class This commit adds the method "getEntityURL" to the "Application" class. This method takes an instance of "Item" as parameter and then builds the absolute URL of the item from its attribute data. --- core/namespace/Application.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core/namespace/Application.php') diff --git a/core/namespace/Application.php b/core/namespace/Application.php index 6a77865..4414665 100644 --- a/core/namespace/Application.php +++ b/core/namespace/Application.php @@ -139,6 +139,26 @@ class Application { return self::getURL("theme/{$template}/{$more}"); } + #=============================================================================== + # Return absolute URL of a specifc entity + #=============================================================================== + public function getEntityURL(Item $Entity) { + switch($class = get_class($Entity)) { + case 'Page\Item': + $attr = self::get('PAGE.SLUG_URLS') ? 'slug' : 'id'; + return self::getPageURL($Entity->attr($attr).'/'); + case 'Post\Item': + $attr = self::get('POST.SLUG_URLS') ? 'slug' : 'id'; + return self::getPostURL($Entity->attr($attr).'/'); + case 'User\Item': + $attr = self::get('USER.SLUG_URLS') ? 'slug' : 'id'; + return self::getUserURL($Entity->attr($attr).'/'); + default: + $error = 'Unknown URL handler for %s entities.'; + throw new Exception(sprintf($error, $class)); + } + } + #=============================================================================== # Exit application with a custom message and status code #=============================================================================== -- cgit v1.2.3