Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/controllers/CkeditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
namespace craft\ckeditor\controllers;

use Craft;
use craft\base\ElementInterface;
use craft\ckeditor\Field;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\fieldlayoutelements\CustomField;
use craft\helpers\ElementHelper;
use craft\web\Controller;
use Throwable;
use yii\web\BadRequestHttpException;
Expand Down Expand Up @@ -209,4 +211,41 @@ public function actionImagePermissions(): Response
'editable' => $editable,
]);
}

/**
* Return element rendered for the control panel and the IDs of the sites it supports.
*
* @return Response
* @throws BadRequestHttpException
* @throws \yii\base\Exception
* @since 5.0.0
*/
public function actionRenderElementWithSupportedSites(): Response
{
$renderResponse = $this->run('/app/render-elements');
$siteIds = [];

$elementParam = $this->request->getRequiredBodyParam('elements')[0];

/** @var ElementInterface|null $element */
$element = $elementParam['type']::find()
->id($elementParam['id'])
->drafts(null)
->revisions(null)
->siteId($elementParam['siteId'])
->status(null)
->one();

if ($element) {
$sites = ElementHelper::supportedSitesForElement($element);
$siteIds = array_map(fn($site) => $site['siteId'], $sites);
}

return $this->asJson([
'elements' => $renderResponse->data['elements'],
'headHtml' => $renderResponse->data['headHtml'],
'bodyHtml' => $renderResponse->data['bodyHtml'],
'siteIds' => $siteIds,
]);
}
}
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor.css

Large diffs are not rendered by default.

Loading
Loading