Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: category draft non localised blocks issue and code refactor #375

Merged
merged 1 commit into from
Aug 1, 2022
Merged
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
5 changes: 5 additions & 0 deletions src/controllers/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/services/repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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' %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "_layouts/element" %}
{% import "_includes/forms" as forms %}

{% set saveShortcutRedirect = continueEditingUrl %}
{% set saveSourceAction = 'translations/category/save-draft' %}
Expand Down Expand Up @@ -33,7 +32,7 @@
{% endblock %}

{% block actionButton %}
<div class="btngroup">
<div class="btngroup {{ canEdit ? '' : 'disabled noClick' }}">
<input type="submit" class="btn submit" value="{{ 'Save'|t('app') }}">
<div class="btn submit menubtn"></div>
<div class="menu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<div class="select" style="margin-left:0.75em;">
<select onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="{{ url('globals/'~craft.app.sites.getSiteById(draft.site).handle~'/'~globalSetHandle) }}"{>{{ 'Current'|t }}</option>
<option value="{{ url('globals/'~craft.app.sites.getSiteById(draft.site).handle~'/'~globalSetHandle) }}">{{ 'Current'|t }}</option>
{% for d in drafts %}
<option value="{{ d.cpEditUrl }}"{% if draftId == d.draftId %} selected{% endif %}>{{ d.name }}</option>
{% endfor %}
Expand Down