-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#364 - Add article template method to easily retrieve a single articl…
…e by id, or alias
- Loading branch information
1 parent
cd2d47b
commit 415edf8
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Joomlatools Pages | ||
* | ||
* @copyright Copyright (C) 2018 Timble CVBA. (http://www.timble.net) | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
* @link https://github.com/joomlatools/joomlatools-pages for the canonical source repository | ||
*/ | ||
|
||
return function($id) | ||
{ | ||
static $entities; | ||
|
||
if(!isset($entities[$id])) | ||
{ | ||
//Check if an alias exists | ||
$id = $this->getObject('ext:k2.model.articles')->getAliases()->get($id, $id); | ||
|
||
if(is_numeric($id)) { | ||
$entities[$id] = $this->getObject('ext:k2.model.articles')->id($id)->fetch(); | ||
} else { | ||
$entities[$id] = $this->getObject('ext:k2.model.articles')->slug($id)->fetch(); | ||
} | ||
} | ||
|
||
return $entities[$id]; | ||
}; |