Last active
April 4, 2020 06:41
-
-
Save CodeCurosity/490f9e8eeeb500ff82bbe5ddc3e6a970 to your computer and use it in GitHub Desktop.
Element Api
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
<?php | |
use craft\elements\Entry; | |
use craft\helpers\UrlHelper; | |
return [ | |
'endpoints' => [ | |
'news.json' => function() { | |
return [ | |
'elementType' => Entry::class, | |
'criteria' => ['section' => 'news'], | |
'transformer' => function(Entry $entry) { | |
$photos = []; | |
foreach ($entry->mainImage as $photo) { | |
$photos[] = $photo->getUrl(); | |
} | |
$siteId = null; | |
$htmlcontent = $entry->htmlContent; | |
$SuperTableRows = []; | |
foreach ($entry->repeater as $row){ | |
$SuperTableRows[] = [ | |
'lastName' => $row->lastName, | |
'email' => $row->email | |
]; | |
} | |
$content = Craft::$app->getElements()->parseRefs((string)$htmlcontent, $siteId); | |
return [ | |
'title' => $entry->title, | |
'dateCreated' => $entry->dateCreated, | |
'content' => $content, | |
'url' => $photos, | |
'repeater' => $SuperTableRows, | |
]; | |
}, | |
]; | |
}, | |
] | |
]; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment