Skip to content

Commit 88b65ae

Browse files
authored
Merge pull request #24 from dusantasioso/master
Pimcore 11 update
2 parents 46c8baa + ee9a953 commit 88b65ae

13 files changed

Lines changed: 67 additions & 47 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ With DeepL the following languages can currently be translated:
2929
* Swedish
3030

3131
## Prerequisites
32-
* PHP 7.1 or higher (https://secure.php.net/)
32+
* PHP 8.1 or higher (https://secure.php.net/)
3333
* Composer (https://getcomposer.org/download/)
34-
* A Pimcore Installation (v5 or higher)
34+
* A Pimcore Installation (v11 or higher)
3535
* DeepL account
3636

3737

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
],
3030
"require": {
31-
"pimcore/pimcore": "^10.0"
31+
"pimcore/pimcore": "^11.0"
3232
},
3333
"autoload": {
3434
"psr-4": {

src/QuickTranslateBundle/Controller/DefaultController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function getAuthKeyAction()
2424
$authKey = WebsiteSetting::getByName("deepl_auth_key") ? WebsiteSetting::getByName("deepl_auth_key")->getData() : null;
2525
$type = WebsiteSetting::getByName("deepl_type") ? WebsiteSetting::getByName("deepl_type")->getData() : null;
2626

27-
return JsonResponse::create([
27+
return new JsonResponse([
2828
"authKey" => $authKey,
2929
"exists" => (($authKey == null || "") ? false : true),
3030
"type" => $type,
@@ -66,7 +66,7 @@ public function getGlossariesAction()
6666

6767
}
6868

69-
return JsonResponse::create([
69+
return new JsonResponse([
7070
"glossaries" => $glossaries
7171
]);
7272
}

src/QuickTranslateBundle/Controller/DocumentController.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function checkIfExistsAction(Request $request)
3636
$exists = false;
3737
}
3838

39-
return JsonResponse::create([
39+
return new JsonResponse([
4040
"exists" => $exists
4141
]);
4242

@@ -53,32 +53,32 @@ public function getDocumentElementsAction(Request $request)
5353
$document = Document::getById($request->get("id"));
5454

5555
if ($isBrick) {
56-
$id = $document->getContentMasterDocumentId() != null ? $document->getContentMasterDocumentId() : $document->getId();
56+
$id = $document->getContentMainDocumentId() != null ? $document->getContentMainDocumentId() : $document->getId();
5757

5858
$brickName = $request->get("brickName");
59-
$elems = $db->fetchAll("SELECT name, type, data
59+
$elems = $db->fetchAllAssociative("SELECT name, type, data
6060
FROM documents_editables
6161
WHERE documentId=" . $document->getId() . " AND (type='input' OR type='textarea' OR type='wysiwyg') AND name LIKE '" . $brickName . "%'");
6262

63-
if ($elems == null && $document->getContentMasterDocumentId() != null) {
64-
$elems = $db->fetchAll("SELECT name, type, data
63+
if ($elems == null && $document->getContentMainDocumentId() != null) {
64+
$elems = $db->fetchAllAssociative("SELECT name, type, data
6565
FROM documents_editables
66-
WHERE documentId=" . $document->getContentMasterDocumentId() . " AND (type='input' OR type='textarea' OR type='wysiwyg') AND name LIKE '" . $brickName . "%'");
66+
WHERE documentId=" . $document->getContentMainDocumentId() . " AND (type='input' OR type='textarea' OR type='wysiwyg') AND name LIKE '" . $brickName . "%'");
6767
}
6868

6969
$langTo = $document->getProperty("language");
7070
$type = $document->getType();
7171

7272
} else {
7373

74-
$elems = $db->fetchAll("SELECT name, type, data
74+
$elems = $db->fetchAllAssociative("SELECT name, type, data
7575
FROM documents_editables
7676
WHERE documentId=" . $request->get("id") . " AND (type='input' OR type='textarea' OR type='wysiwyg')");
7777

78-
if ($elems == null && $document->getContentMasterDocumentId() != null) {
79-
$elems = $db->fetchAll("SELECT name, type, data
78+
if ($elems == null && $document->getContentMainDocumentId() != null) {
79+
$elems = $db->fetchAllAssociative("SELECT name, type, data
8080
FROM documents_editables
81-
WHERE documentId=" . $document->getContentMasterDocumentId() . " AND (type='input' OR type='textarea' OR type='wysiwyg')");
81+
WHERE documentId=" . $document->getContentMainDocumentId() . " AND (type='input' OR type='textarea' OR type='wysiwyg')");
8282
}
8383
}
8484

@@ -91,14 +91,14 @@ public function getDocumentElementsAction(Request $request)
9191
}
9292

9393
if(isset($elements)){
94-
return JsonResponse::create([
94+
return new JsonResponse([
9595
"elements" => $elements,
9696
"langTo" => ($isBrick ? $langTo : null),
9797
"type" => ($isBrick ? $type : null)
9898
]);
9999
}
100100
else{
101-
return JsonResponse::create([
101+
return new JsonResponse([
102102
// "elements" => $elements[] = (object)[],
103103
// "langTo" => ($isBrick ? $langTo : null),
104104
// "type" => ($isBrick ? $type : null)
@@ -124,7 +124,7 @@ public function saveBrickAction(Request $request)
124124

125125
$document->save();
126126

127-
return JsonResponse::create([
127+
return new JsonResponse([
128128
"success" => true
129129
]);
130130

@@ -246,15 +246,15 @@ public function saveDocumentAction(Request $request)
246246
}
247247
}
248248

249-
return JsonResponse::create([
249+
return new JsonResponse([
250250
'success' => $success,
251251
'id' => $document->getId(),
252252
'type' => $document->getType(),
253253
'parentId' => $document->getParentId()
254254
]);
255255

256256
} else {
257-
return JsonResponse::create([
257+
return new JsonResponse([
258258
'success' => $success,
259259
'message' => $errorMessage
260260
]);

src/QuickTranslateBundle/Controller/ObjectController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public function translateObjectAction(Request $request)
6666

6767
$item->save();
6868

69-
return JsonResponse::create("true");
69+
return new JsonResponse("true");
7070

7171
} catch (\Exception $e) {
72-
return JsonResponse::create("false");
72+
return new JsonResponse("false");
7373
}
7474

7575
}

src/QuickTranslateBundle/DependencyInjection/QuickTranslateExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Config\FileLocator;
1515
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1616
use Symfony\Component\DependencyInjection\Loader;
17+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1718

1819
/**
1920
* This is the class that loads and manages your bundle configuration.
@@ -22,6 +23,17 @@
2223
*/
2324
class QuickTranslateExtension extends Extension
2425
{
26+
27+
public function prepend(ContainerBuilder $container): void
28+
{
29+
$security = $container->getExtensionConfig('pimcore_admin');
30+
$security[0]['admin_csp_header']['additional_urls']['connect-src'] = [
31+
0 => 'https://api-free.deepl.com/v2/translate',
32+
1 => 'https://api.deepl.com/v2/translate'
33+
];
34+
$container->loadFromExtension('pimcore_admin', $security[0]);
35+
}
36+
2537
/**
2638
* {@inheritdoc}
2739
*/

src/QuickTranslateBundle/QuickTranslateBundle.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212

1313
use PackageVersions\Versions;
1414
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
15-
use Pimcore\Extension\Bundle\PimcoreBundleInterface;
15+
use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface;
16+
use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait;
1617
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
1718

18-
class QuickTranslateBundle extends AbstractPimcoreBundle implements PimcoreBundleInterface
19+
class QuickTranslateBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface
1920
{
20-
21-
use PackageVersionTrait;
21+
use BundleAdminClassicTrait;
2222
const PACKAGE_NAME = 'asioso/pimcore-quicktranslate-module';
2323

24-
public function getJsPaths()
24+
public function getJsPaths() : array
2525
{
2626
return [
27-
'https://code.jquery.com/jquery-3.6.0.min.js',
27+
'/bundles/quicktranslate/js/pimcore/jquery-3.6.0.min.js',
2828
'/bundles/quicktranslate/js/pimcore/startup.js',
2929
'/bundles/quicktranslate/js/quick-translate-btn/quickTranslateObjectBtn.js',
3030
'/bundles/quicktranslate/js/quick-translate-btn/quickTranslateDocument.js',
@@ -39,7 +39,7 @@ public function getJsPaths()
3939
];
4040
}
4141

42-
public function getEditmodeJsPaths()
42+
public function getEditmodeJsPaths() : array
4343
{
4444

4545
return [
@@ -55,22 +55,22 @@ public function getEditmodeJsPaths()
5555

5656
}
5757

58-
public function getEditmodeCssPaths()
58+
public function getEditmodeCssPaths() : array
5959
{
6060
return [
6161
'/bundles/quicktranslate/css/quick-translate.css'
6262
];
6363
}
6464

65-
public function getCssPaths()
65+
public function getCssPaths() : array
6666
{
6767
return [
6868
'/bundles/quicktranslate/css/quick-translate.css'
6969
];
7070
}
7171

7272

73-
public function getNiceName()
73+
public function getNiceName() : string
7474
{
7575
return 'Asioso - QuickTranslate Bundle';
7676
}
@@ -80,7 +80,7 @@ public function getNiceName()
8080
*
8181
* @return string
8282
*/
83-
public function getDescription()
83+
public function getDescription() : string
8484
{
8585
return "";
8686
}

src/QuickTranslateBundle/Resources/public/js/pimcore/jquery-3.6.0.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QuickTranslateBundle/Resources/public/js/pimcore/startup.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99

1010
pimcore.registerNS("pimcore.plugin.asiosoQuickTranslateBundle");
1111

12-
pimcore.plugin.asiosoQuickTranslateBundle = Class.create(pimcore.plugin.admin, {
12+
pimcore.plugin.asiosoQuickTranslateBundle = Class.create({
1313
getClassName: function () {
1414
return "pimcore.plugin.asiosoQuickTranslateBundle";
1515
},
1616

1717
initialize: function () {
18-
pimcore.plugin.broker.registerPlugin(this);
18+
document.addEventListener(pimcore.events.postOpenObject, this.postOpenObject.bind(this));
19+
document.addEventListener(pimcore.events.postOpenDocument, this.postOpenDocument.bind(this));
1920
},
2021

2122
pimcoreReady: function (params, broker) {
2223

2324
},
2425

25-
postOpenObject: function (object, type) {
26+
postOpenObject: function (event) {
2627
/* add quickTranslate icon to objects with localizedfields */
28+
const { detail: { object, type } } = event;
2729
if (type === "object") {
2830
if (object.data.data.hasOwnProperty("localizedfields")) {
2931
object.tabbar.add(new pimcore.element.quickTranslateObjectBtn(object, "object").getLayout());
@@ -45,8 +47,9 @@ pimcore.plugin.asiosoQuickTranslateBundle = Class.create(pimcore.plugin.admin, {
4547
},
4648

4749

48-
postOpenDocument: function (document, type) {
50+
postOpenDocument: function (event) {
4951
/* add quicktranslate button to specific document type */
52+
const { detail: { document, type } } = event;
5053
if (type == "page" || type == "snippet" || type == "printpage") {
5154

5255
/* checks if document language is supported by deepl and ads the button if it is */
@@ -55,7 +58,7 @@ pimcore.plugin.asiosoQuickTranslateBundle = Class.create(pimcore.plugin.admin, {
5558
this.docBtn(document);
5659
}*/
5760
} else {
58-
if (isDeeplLanguage(document.data.properties["language"]["data"])) {
61+
if (document.data.properties["language"] && isDeeplLanguage(document.data.properties["language"]["data"])) {
5962
this.docBtn(document);
6063
}
6164
}

src/QuickTranslateBundle/Resources/public/js/quick-translate-btn/areablock.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ pimcore.document.editables.areablock = Class.create(pimcore.document.editables.a
206206
xml += '<' + key + ' quick-t-tag="' + key + '" quick-t-type="' + data.elements[key]["type"] + '">' + data.elements[key]["data"] + '</' + key + '>';
207207
});
208208

209-
210-
xml = xmlRegReplace(xml);
211-
212209
var tempWrapper = document.createElement("tempWrapper");
213210

214211
tempWrapper.innerHTML = xml;
@@ -230,6 +227,7 @@ pimcore.document.editables.areablock = Class.create(pimcore.document.editables.a
230227
};
231228

232229
xml = tempWrapper.innerHTML.toString();
230+
xml = xmlRegReplace(xml);
233231

234232
/* if request is to large, divides it into more requests */
235233
if (xml.length > 4500) {

0 commit comments

Comments
 (0)