Skip to content
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,
]);
}
}
1 change: 0 additions & 1 deletion src/translations/en/ckeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
'Raw content only' => 'Raw content only',
'Removes any potentially-malicious code on save, by running the submitted data through {link}.' => 'Removes any potentially-malicious code on save, by running the submitted data through {link}.',
'Show as a separate button' => 'Show as a separate button',
'Show as a separate button' => 'Show as a separate button',
'Show in a dropdown' => 'Show in a dropdown',
'Show word count' => 'Show word count',
'Site: {name}' => 'Site: {name}',
Expand Down
1 change: 0 additions & 1 deletion src/web/assets/ckeconfig/CkeConfigAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ public function registerAssetFiles($view): void
]);
}
}

}
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor.css

Large diffs are not rendered by default.

Loading
Loading