Something went wrong. Try again.
standard.site integration for Craft CMS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869<?php
namespace studioespresso\standardsite\controllers;
use Craft;use craft\elements\Entry;use craft\web\Controller;use studioespresso\standardsite\StandardSite;use yii\web\Response;
class EntryController extends Controller{ public function actionPublish(): Response { $this->requireCpRequest();
$entryId = Craft::$app->getRequest()->getRequiredParam('entryId'); $siteId = Craft::$app->getRequest()->getRequiredParam('siteId');
$entry = Entry::find() ->id($entryId) ->siteId($siteId) ->status(null) ->one();
if (!$entry) { Craft::$app->getSession()->setError('Entry not found'); return $this->redirect(Craft::$app->getRequest()->getReferrer()); }
try { StandardSite::getInstance()->publisher->publishEntry($entry); Craft::$app->getSession()->setNotice('Published to AT Protocol'); } catch (\Throwable $e) { Craft::$app->getSession()->setError("Publish failed: {$e->getMessage()}"); }
return $this->redirect($entry->getCpEditUrl()); }
public function actionUnpublish(): Response { $this->requireCpRequest();
$entryId = Craft::$app->getRequest()->getRequiredParam('entryId'); $siteId = Craft::$app->getRequest()->getRequiredParam('siteId');
$entry = Entry::find() ->id($entryId) ->siteId($siteId) ->status(null) ->one();
if (!$entry) { Craft::$app->getSession()->setError('Entry not found'); return $this->redirect(Craft::$app->getRequest()->getReferrer()); }
try { StandardSite::getInstance()->publisher->unpublishEntry($entry); Craft::$app->getSession()->setNotice('Unpublished from AT Protocol'); } catch (\Throwable $e) { Craft::$app->getSession()->setError("Unpublish failed: {$e->getMessage()}"); }
return $this->redirect($entry->getCpEditUrl()); }}