diff --git a/src/controllers/AssetController.php b/src/controllers/AssetController.php index 50ce0943..55225473 100644 --- a/src/controllers/AssetController.php +++ b/src/controllers/AssetController.php @@ -19,6 +19,11 @@ public function actionEditDraft(array $variables = array()) $data = Craft::$app->getRequest()->resolve()[1]; $siteService = Craft::$app->getSites(); + /** @var craft\elements\User $currentUser */ + $currentUser = Craft::$app->getUser()->getIdentity(); + + $variables['canEdit'] = $currentUser->can('translations:orders:create'); + $site = $siteService->getSiteByHandle($data['site'] ?? $siteService->getCurrentSite()->handle); if (empty($data['elementId'])) { diff --git a/src/controllers/CategoryController.php b/src/controllers/CategoryController.php index a77f4daa..0fefeb30 100644 --- a/src/controllers/CategoryController.php +++ b/src/controllers/CategoryController.php @@ -29,6 +29,11 @@ public function actionEditDraft(array $variables = array()) { $variables = Craft::$app->getRequest()->resolve()[1]; + /** @var craft\elements\User $currentUser */ + $currentUser = Craft::$app->getUser()->getIdentity(); + + $variables['canEdit'] = $currentUser->can('translations:orders:create'); + if (empty($variables['slug'])) { Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'Param “{name}” doesn’t exist.', array('name' => 'categoryGroup'))); return; @@ -91,14 +96,15 @@ public function actionSaveDraft() Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'No draft exists with the ID “{id}”.', array('id' => $draftId))); return; } + + $draft->title = $this->request->getParam('title') ?? $draft->title; + $draft->slug = $this->request->getParam('slug') ?? $draft->slug; } else { $draft = Translations::$plugin->categoryDraftRepository->makeNewDraft(); $draft->id = $category->id; $draft->site = $site; } - $fieldsLocation = Craft::$app->getRequest()->getParam('fieldsLocation', 'fields'); - $fields = $this->request->getParam('fields') ?? []; if ($fields) { @@ -133,7 +139,7 @@ public function actionPublishDraft() $category = Translations::$plugin->categoryRepository->getCategoryById($categoryId, $siteId); if (!$category) { - Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'No category exists with the ID “{id}”.', array('id' => $draft->id))); + Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'No category exists with the ID “{id}”.', array('id' => $categoryId))); return; } diff --git a/src/services/repository/FileRepository.php b/src/services/repository/FileRepository.php index d969114f..f7eefe13 100644 --- a/src/services/repository/FileRepository.php +++ b/src/services/repository/FileRepository.php @@ -13,6 +13,9 @@ use Craft; use Exception; use yii\db\Query; +use craft\elements\Asset; +use craft\elements\Category; +use craft\elements\GlobalSet; use acclaro\translations\Constants; use acclaro\translations\Translations; use acclaro\translations\models\FileModel; diff --git a/src/templates/assets/_editDraft.html b/src/templates/assets/_editDraft.twig similarity index 99% rename from src/templates/assets/_editDraft.html rename to src/templates/assets/_editDraft.twig index 76eeffff..138645e3 100644 --- a/src/templates/assets/_editDraft.html +++ b/src/templates/assets/_editDraft.twig @@ -1,7 +1,6 @@ {% extends "_layouts/element" %} {% import "_includes/forms" as forms %} -{% set canEdit = true %} {% set canUpdateSource = canEdit %} {% set saveSourceAction = 'translations/asset/save-draft' %} {% set deleteSourceAction = 'translations/asset/delete-draft' %} diff --git a/src/templates/categories/_editDraft.html b/src/templates/categories/_editDraft.twig similarity index 97% rename from src/templates/categories/_editDraft.html rename to src/templates/categories/_editDraft.twig index 205563ca..a5b7d990 100644 --- a/src/templates/categories/_editDraft.html +++ b/src/templates/categories/_editDraft.twig @@ -1,5 +1,4 @@ {% extends "_layouts/element" %} -{% import "_includes/forms" as forms %} {% set saveShortcutRedirect = continueEditingUrl %} {% set saveSourceAction = 'translations/category/save-draft' %} @@ -33,7 +32,7 @@ {% endblock %} {% block actionButton %} -