Skip to content

Commit

Permalink
Add compiled HTML to each content element
Browse files Browse the repository at this point in the history
  • Loading branch information
saibotd authored Jun 25, 2019
1 parent a472a10 commit 435827b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Resources/contao/ContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ class ApiContentElement extends AugmentedContaoModel
public function __construct($id, $inColumn = 'main')
{
$this->model = ContentModel::findById($id, ['published'], ['1']);
if (!Controller::isVisibleElement($this->model)) {
if (!$this->model || !Controller::isVisibleElement($this->model)) {
return $this->model = null;
}
$this->compiledHtml = null;
$ceClass = 'Contao\Content'.ucfirst($this->model->type);
if (class_exists($ceClass)) {
try {
$compiled = new $ceClass($this->model, $inColumn);
$this->compiledHtml = $compiled->generate();
} catch (\Exception $e) {
}
}
if ($this->type === 'module') {
$contentModuleClass = ContentElement::findClass($this->type);
$element = new $contentModuleClass($this->model, $inColumn);
Expand All @@ -46,7 +55,11 @@ public function __construct($id, $inColumn = 'main')
public static function findByPidAndTable($pid, $table = 'tl_article', $inColumn = 'main')
{
$contents = [];
foreach (ContentModel::findPublishedByPidAndTable($pid, $table, ['order' => 'sorting ASC']) as $content) {
$contentModels = ContentModel::findPublishedByPidAndTable($pid, $table, ['order' => 'sorting ASC']);
if (!$contentModels) {
return $contents;
}
foreach ($contentModels as $content) {
if (!Controller::isVisibleElement($content)) {
continue;
}
Expand Down

0 comments on commit 435827b

Please sign in to comment.