Skip to content

Commit

Permalink
Add support of CraftCMS v5
Browse files Browse the repository at this point in the history
ENG-14422
  • Loading branch information
hadomskyi committed Mar 24, 2024
1 parent 5302daa commit 6c803dd
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 5.0.0 - 2024-02-09
### Added
- Support of CraftCMS v5

## 4.4.5 - 2024-02-09
### Fixed
- Translation of nested link field
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lilt/craft-lilt-plugin",
"description": "The Lilt plugin makes it easy for you to send content to Lilt for translation right from within Craft CMS.",
"type": "craft-plugin",
"version": "4.4.5",
"version": "5.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,22 +22,22 @@
}
],
"require": {
"craftcms/cms": "^4.0.0",
"craftcms/cms": "5.0.0-beta.11",
"lilt/lilt-connector-sdk-php": "0.1.0",
"ext-json": "*",
"php": "^8.0"
},
"require-dev": {
"codeception/codeception": "^3.0 | ^4.0",
"vlucas/phpdotenv": "^3.0",
"squizlabs/php_codesniffer": "^3.6",
"codeception/codeception": "^5.1",
"vlucas/phpdotenv": "^3.6",
"squizlabs/php_codesniffer": "^3.9",
"codeception/module-yii2": "^1.1",
"codeception/module-asserts": "^1.3",
"craftcms/redactor": "^2.0 || ^3.0",
"percipioglobal/craft-colour-swatches": "^1.0 || ^4.0",
"spicyweb/craft-neo": "3.1.5",
"verbb/super-table": "^3.0",
"wiremock-php/wiremock-php": "^2.33"
"codeception/module-asserts": "^3.0.0",
"craftcms/redactor": "4.0.x-dev",
"verbb/super-table": "4.0.0-beta.1",
"spicyweb/craft-neo": "5.x-dev",
"wiremock-php/wiremock-php": "^2.35",
"verbb/base": "^3.0.0-beta.1"
},
"autoload": {
"psr-4": {
Expand Down
115 changes: 56 additions & 59 deletions src/assets/resources/elements/LiltElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,6 @@ Craft.LiltElementIndex = Craft.BaseElementIndex.extend({

return true;
},
//TODO: we need to find better way for it
getViewParams: function() {
var criteria = {
siteId: this.siteId,
search: this.searchText,
offset: this.settings.batchSize * (this.page - 1),
limit: this.settings.batchSize,
};

// Only set drafts/draftOf/trashed params when needed, so we don't potentially override a source's criteria
if (
this.settings.canHaveDrafts &&
(this.drafts || (this.settings.context === 'index' && !this.status))
) {
criteria.drafts = this.drafts || null;
criteria.savedDraftsOnly = true;
if (!this.drafts) {
criteria.draftOf = false;
}
}
if (this.trashed) {
criteria.trashed = true;
}

if (!Garnish.hasAttr(this.$source, 'data-override-status')) {
criteria.status = this.status;
}

$.extend(criteria, this.settings.criteria);

var params = {
context: this.settings.context,
elementType: this.elementType,
source: this.instanceState.selectedSource,
criteria: criteria,
disabledElementIds: this.settings.disabledElementIds,
viewState: $.extend({}, this.getSelectedSourceState()),
paginated: this._isViewPaginated() ? 1 : 0,
showEntryVersions: this.settings.showEntryVersions
};

// Possible that the order/sort isn't entirely accurate if we're sorting by Score
params.viewState.order = this.getSelectedSortAttribute();
params.viewState.sort = this.getSelectedSortDirection();

if (this.getSelectedSortAttribute() === 'structure') {
if (typeof this.instanceState.collapsedElementIds === 'undefined') {
this.instanceState.collapsedElementIds = [];
}
params.collapsedElementIds = this.instanceState.collapsedElementIds;
}

// Give plugins a chance to hook in here
this.trigger('registerViewParams', {
params: params,
});

return params;
},
getDefaultSort: function() {
return ['elements.dateCreated', 'desc'];
},
Expand Down Expand Up @@ -272,5 +213,61 @@ Craft.LiltElementIndex = Craft.BaseElementIndex.extend({
getSortDirectionOption: function(dir) {
return [];
},
getSourceLabel: function () {
// CraftCMS v5 required change to check for empty sources
if(this.$sources === undefined) {
return
}
return this.$source.data('label');
},
updateSourceVisibility: function () {
this.$visibleSources = $();

// CraftCMS v5 required change to check for empty sources
if(this.$sources === undefined) {
return
}

for (let i = 0; i < this.$sources.length; i++) {
const $source = this.$sources.eq(i);

if (
!Garnish.hasAttr($source, 'data-disabled') &&
(typeof $source.data('sites') === 'undefined' ||
$source
.data('sites')
.toString()
.split(',')
.some((siteId) => {
if (siteId == this.siteId) {
return true;
}
// maybe UUIDs were used
if (siteId != parseInt(siteId)) {
const site = Craft.sites.find(
(site) => site.id == this.siteId
);
if (site && siteId == site.uid) {
return true;
}
}

return false;
}))
) {
$source.parent().removeClass('hidden');
this.$visibleSources = this.$visibleSources.add($source);
} else {
$source.parent().addClass('hidden');

// Is this the currently selected source?
if (this.$source && this.$source.get(0) === $source.get(0)) {
this.$source = null;
this.$rootSource = null;
this.sourceKey = null;
this.rootSourceKey = null;
}
}
}
},
});
6 changes: 4 additions & 2 deletions src/assets/resources/job-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ CraftliltPlugin.JobForm = Garnish.Base.extend({
});

} catch (e) {
console.log(e);
console.log("Can't preloadElementIndex due to error:",e);
}

},
createElementIndex: function(settings) {
Craft.elementIndex = new Craft.LiltElementIndex(
'lilthq\\craftliltplugin\\elements\\TranslateEntry',
$('#entries-to-translate'), settings);
$('#entries-to-translate'),
settings
);
},
preloadVersions: function() {
if (!this.$selectedVersions || !this.$selectedVersions.length > 0) {
Expand Down
11 changes: 5 additions & 6 deletions src/elements/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,23 @@ public function getTargetSiteIdsHtml(): string
return $html;
}

protected function tableAttributeHtml(string $attribute): string
protected function attributeHtml(string $attribute): string
{
switch ($attribute) {
case 'sourceSiteId':
return $this->getSourceSiteIdHtml();

case 'status':
return $this->getStatusHtml();
case 'targetSiteIds':
return $this->getTargetSiteIdsHtml();
//TODO: due date not in use at the moment
//case 'dueDate':
// return $this->dueDate->format(
// Craft::$app->locale->getDateFormat('short', 'php')
// );
case 'targetSiteIds':
return $this->getTargetSiteIdsHtml();
}

return parent::tableAttributeHtml($attribute);
return parent::attributeHtml($attribute);
}

public function getStatus(): ?string
Expand All @@ -466,7 +465,7 @@ public function isEditable(): bool

public function getUrl(): string
{
return CraftliltpluginParameters::JOB_EDIT_PATH . '/' . $this->id;
return CraftliltpluginParameters::JOB_EDIT_PATH . '/getUrl/' . $this->id;
}

public function getTranslationWorkflowLabel(): string
Expand Down
6 changes: 4 additions & 2 deletions src/elements/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Translation extends Element
{
use TranslationModelTrait;

public $actions = null;

public ?int $id = null;
public ?string $uid = null;
public ?string $title = null;
Expand Down Expand Up @@ -270,7 +272,7 @@ public function getSourceSiteIdHtml(): string
. "</span>";
}

protected function tableAttributeHtml(string $attribute): string
protected function attributeHtml(string $attribute): string
{
switch ($attribute) {
case 'sourceSiteId':
Expand All @@ -285,7 +287,7 @@ protected function tableAttributeHtml(string $attribute): string
return $this->getTargetSiteNameHtml();
}

return parent::tableAttributeHtml($attribute);
return parent::attributeHtml($attribute);
}

public static function sources(string $context = null): array
Expand Down
2 changes: 1 addition & 1 deletion src/elements/db/JobQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class JobQuery extends ElementQuery
public mixed $dateCreated = null;
public mixed $dateUpdated = null;

public function status($value): self
public function status($value): static
{
$this->status = $value;

Expand Down
4 changes: 2 additions & 2 deletions src/elements/db/TranslationQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TranslationQuery extends ElementQuery

public $jobId;

public function status($value): self
public function status($value): static
{
$this->status = $value;

Expand Down Expand Up @@ -86,7 +86,7 @@ protected function beforePrepare(): bool
$this->joinElementTable('lilt_translations');

/** GET TITLE */
$this->query->innerJoin(Table::CONTENT . ' content', [
$this->query->innerJoin(Table::ELEMENTS_SITES . ' content', [
'and',
'[[content.elementId]] = [[lilt_translations.elementId]]',
'[[content.siteId]] = [[lilt_translations.sourceSiteId]]'
Expand Down
1 change: 1 addition & 0 deletions src/parameters/CraftliltpluginParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class CraftliltpluginParameters
{
public const PLUGIN_PATH = 'craft-lilt-plugin';
public const REPORT_DATA = 'craft-lilt-plugin/get-report-data/invoke';
public const TRANSLATION_REVIEW_ACTION = 'craft-lilt-plugin/translation/post-translation-review/invoke';
public const TRANSLATION_PUBLISH_ACTION = 'craft-lilt-plugin/translation/post-translation-publish/invoke';
Expand Down
7 changes: 7 additions & 0 deletions src/services/providers/field/ContentProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

namespace lilthq\craftliltplugin\services\providers\field;

use craft\errors\InvalidFieldException;
use lilthq\craftliltplugin\services\providers\command\ProvideContentCommand;

interface ContentProviderInterface
{
/**
* @param ProvideContentCommand $provideContentCommand
* @return mixed
*
* @throws InvalidFieldException
*/
public function provide(ProvideContentCommand $provideContentCommand);
public function support(ProvideContentCommand $command): bool;
}
16 changes: 15 additions & 1 deletion src/services/providers/field/FieldContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace lilthq\craftliltplugin\services\providers\field;

use craft\errors\InvalidFieldException;
use lilthq\craftliltplugin\services\providers\command\ProvideContentCommand;

class FieldContentProvider
Expand Down Expand Up @@ -33,6 +34,19 @@ public function provide(ProvideContentCommand $provideContentCommand)
return null;
}

return $this->providersMap[$fieldClass]->provide($provideContentCommand);
try {
return $this->providersMap[$fieldClass]->provide($provideContentCommand);
} catch (InvalidFieldException $ex) {
\Craft::error(
sprintf(
"Can't get field value %s for element %s: %s",
$ex->getMessage(),
$provideContentCommand->getField()->handle,
$provideContentCommand->getElement()->getId()
)
);

return null;
}
}
}

0 comments on commit 6c803dd

Please sign in to comment.