Skip to content

Commit baac351

Browse files
committed
add internationalization choice
1 parent 55f21c5 commit baac351

11 files changed

Lines changed: 92 additions & 6 deletions

File tree

Config/TheliaMain.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CREATE TABLE `custom_field`
2727
`id` INTEGER NOT NULL AUTO_INCREMENT,
2828
`code` VARCHAR(100) NOT NULL,
2929
`title` VARCHAR(255) NOT NULL,
30+
`is_international` TINYINT(1) DEFAULT 1 NOT NULL,
3031
`type` TINYINT DEFAULT 0 NOT NULL,
3132
`custom_field_parent_id` INTEGER,
3233
PRIMARY KEY (`id`),

Config/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<language>en_US</language>
2222
<language>fr_FR</language>
2323
</languages>
24-
<version>1.0.3</version>
24+
<version>1.0.4</version>
2525
<authors>
2626
<author>
2727
<name>Openstudio</name>

Config/schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true"/>
3939
<column name="code" type="VARCHAR" size="100" required="true"/>
4040
<column name="title" type="VARCHAR" size="255" required="true"/>
41+
<column name="is_international" type="BOOLEAN" required="true" default="true"/>
4142
<column name="type" type="ENUM" valueSet="text,textarea, wysiwyg, content, category, folder, product, image" required="true" default="text"/>
4243
<column name="custom_field_parent_id" type="INTEGER" required="false"/>
4344

Config/update/1.0.4.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This is a fix for InnoDB in MySQL >= 4.1.x
2+
# It "suspends judgement" for fkey relationships until are tables are set.
3+
SET FOREIGN_KEY_CHECKS = 0;
4+
5+
ALTER TABLE custom_field ADD COLUMN `is_international` TINYINT(1) DEFAULT 1 NOT NULL;
6+
7+
SET FOREIGN_KEY_CHECKS = 1;

Controller/Admin/CustomFieldController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function listCustomFields(): Response
7575
->filterBySource('general')
7676
->findOne();
7777

78-
if ($value && in_array($customField->getType(), CustomFieldValueController::CUSTOM_FIELD_SIMPLE_VALUES)) {
78+
if (
79+
$value &&
80+
(in_array($customField->getType(), CustomFieldValueController::CUSTOM_FIELD_SIMPLE_VALUES)
81+
|| !$customField->getIsInternational())
82+
) {
7983
$generalValues[$customField->getId()] = $value->getSimpleValue() ?? '';
8084
$generalValueIds[$customField->getId()] = $value->getId();
8185
} elseif ($value) {
@@ -112,7 +116,9 @@ public function createCustomField(): Response
112116
// Get all parents for the dropdown
113117
$parents = CustomFieldParentQuery::create()->find();
114118

115-
$form = $this->createForm(CustomFieldForm::getName());
119+
$form = $this->createForm(CustomFieldForm::getName(), FormType::class, [
120+
'is_international' => true,
121+
]);
116122
$this->getParserContext()->addForm($form);
117123
$error = null;
118124

@@ -176,6 +182,7 @@ public function updateCustomField(int $id): Response
176182
'title' => $customField->getTitle(),
177183
'code' => $customField->getCode(),
178184
'type' => $customField->getType(),
185+
'is_international' => $customField->getIsInternational(),
179186
'sources' => $sourcesArray,
180187
'custom_field_parent_id' => $customField->getCustomFieldParentId(),
181188
]);
@@ -228,6 +235,7 @@ private function handleSave(Form $validatedForm, ?CustomField $customField = nul
228235
->setTitle($validatedForm->get('title')->getData())
229236
->setCode($validatedForm->get('code')->getData())
230237
->setType($validatedForm->get('type')->getData())
238+
->setIsInternational($validatedForm->get('is_international')->getData())
231239
->setCustomFieldParentId($parentId ?: null)
232240
->save();
233241

Controller/Admin/CustomFieldValueController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ public function saveCustomFieldValues(): Response
131131
->filterBySourceId($sourceId)
132132
->findOneOrCreate();
133133

134-
if (in_array($customField->getType(), self::CUSTOM_FIELD_SIMPLE_VALUES)) {
134+
if (
135+
in_array($customField->getType(), self::CUSTOM_FIELD_SIMPLE_VALUES) ||
136+
!$customField->isInternational()
137+
) {
135138
$customFieldValue
136139
->setSimpleValue($value)
137140
->save();

Form/CustomFieldForm.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Form\Extension\Core\Type\TextType;
1111
use Symfony\Component\Validator\Constraints\Length;
1212
use Symfony\Component\Validator\Constraints\NotBlank;
13+
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
1314
use Thelia\Core\Translation\Translator;
1415
use Thelia\Form\BaseForm;
1516

@@ -84,6 +85,15 @@ protected function buildForm(): void
8485
'required' => true,
8586
]
8687
)
88+
->add(
89+
'is_international',
90+
CheckboxType::class,
91+
[
92+
'label' => Translator::getInstance()->trans('International', [], 'customfields'),
93+
'label_attr' => ['for' => 'custom_field_is_international'],
94+
'required' => false,
95+
]
96+
)
8797
->add(
8898
'sources',
8999
ChoiceType::class,

I18n/en_US.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,6 @@
8383
'Select a parent group to organize this field' => 'Select a parent group to organize this field',
8484
'Or create new parent' => 'Or create new parent',
8585
'Enter a new parent group name' => 'Enter a new parent group name',
86+
'International' => 'International',
87+
'Check to allow translation of the field' => 'Check to allow translation of the field'
8688
];

I18n/fr_FR.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@
8484
'Select a parent group to organize this field' => 'Sélectionnez un groupe parent pour organiser ce champ',
8585
'Or create new parent' => 'Ou créer un nouveau parent',
8686
'Enter a new parent group name' => 'Entrez un nom de groupe parent',
87+
'International' => 'International',
88+
'Check to allow translation of the field' => 'Cochez pour permettre la traduction du champ'
8789
];

Service/CustomFieldService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public function getCustomFieldValue(string $code, ?string $source = 'general', ?
6060
return null;
6161
}
6262

63-
if (in_array($customField->getType(), CustomFieldValueController::CUSTOM_FIELD_SIMPLE_VALUES)) {
63+
if (
64+
in_array($customField->getType(), CustomFieldValueController::CUSTOM_FIELD_SIMPLE_VALUES)
65+
|| !$customField->isInternational()
66+
) {
6467
return $customFieldValue->getSimpleValue();
6568
}
6669
if ($customField->getType() === CustomFieldTableMap::COL_TYPE_IMAGE) {

0 commit comments

Comments
 (0)