Skip to content

Commit

Permalink
[TASK] Add English Short Name and Custom Format Option
Browse files Browse the repository at this point in the history
- Add TCA format options
- Update OptionValueFieldViewHelper
- Modify Country Template
- Update Readme.md
- Allow different length for AjaxController
  • Loading branch information
Andreas-Sommer committed Jul 1, 2024
1 parent 85bf24a commit 1183533
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
15 changes: 8 additions & 7 deletions Classes/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ class AjaxController extends ActionController
public function countyAction(string $isoCode): string
{
$strLength = strlen($isoCode);
if ($strLength < 2 || $strLength > 3)
{
$this->throwStatus(403, 'Country code does not match length specification');
}
$counties = $this->getCounties($isoCode, $strLength);

return json_encode([
'status' => 'ok',
'isoCode' => $isoCode,
'counties' => $counties
]);

}

protected function getCounties(string $isoCode, int $strLength): array
Expand All @@ -60,6 +55,13 @@ protected function getCounties(string $isoCode, int $strLength): array
return $counties;
}

if ($strLength < 2 || $strLength > 3)
{
// Country code does not match TypoScript mapping
// and length does not match country_zones specification
return [];
}

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('static_country_zones');
$statement = $queryBuilder
Expand All @@ -75,15 +77,14 @@ protected function getCounties(string $isoCode, int $strLength): array
->execute();
while ($row = $statement->fetchAssociative())
{
// Do something with that single row
$counties[$row['zn_code']] = $row['zn_name_local'];
}
return $counties;
}

protected function getCountriesByTypoScriptMapping(string $isoCode): array
{
$isoCode = str_replace(' ', '-', $isoCode);
return $this->settings['mapping']['country_zones'][strtoupper($isoCode)] ?? [];
}

}
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/OptionValueFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class OptionValueFieldViewHelper extends AbstractViewHelper
{
protected const FORMAT_FIELD_NAMES = [
0 => 'isoCodeA2',
1 => 'isoCodeA3'
1 => 'isoCodeA3',
2 => 'shortNameEn'
];


Expand Down
11 changes: 9 additions & 2 deletions Configuration/TCA/Overrides/tx_powermail_domain_model_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
$tmp_powermail_country = [
'tx_powermailcountry_format' => [
'label' => 'LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.format',
'onChange' => 'reload',
'config' => [
'type' => 'radio',
'default' => '0',
'items' => [
['LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.country_code.a2', '0'],
['LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.country_code.a3', '1'],
['LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.country_code.cn_short_en', '2'],
['LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.country_code.custom', '3'],
]
]
],
'tx_powermailcountry_limit' => [
'label' => 'LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.limitation',
'onChange' => 'reload',
'displayCond' => 'FIELD:tx_powermailcountry_format:<:3',
'config' => [
'type' => 'radio',
'default' => '0',
Expand Down Expand Up @@ -79,12 +83,15 @@
'--palette--;LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:' .
Field::TABLE_NAME . '.prefill_title;31, ' .
'--palette--;Layout;43, ' .
'description, ' .
'--palette--;LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.config;country_configuration, ' .
'description,' .
'--palette--;LLL:EXT:powermail_country/Resources/Private/Language/locallang_db.xlf:' . Field::TABLE_NAME . '.config;country_configuration, settings, ' .
'--palette--;LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:' .
Field::TABLE_NAME . '.marker_title;5, ' .
'--div--;LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:tabs.access, ' .
'sys_language_uid, l10n_parent, l10n_diffsource, hidden, starttime, endtime';


$GLOBALS['TCA'][Field::TABLE_NAME]['types']['country']['showitem'] = $typeCountry;


#$GLOBALS['TCA'][Field::TABLE_NAME]['columns']['settings']['displayCond'] = 'FIELD:tx_powermailcountry_format:=:3';
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Belsignum/Powermail-Country
Improve the Powermail select option list
- Option value: Choose between ISO 3166-1 A2/A3 country code
- Option value: Choose between
- ISO 3166-1 A2/A3 country code
- English Short Name
- Custom List
- Limitation
- All static_countries
- European Union (EU)
- United Nations (UN)
- Territories Select List
- Label value respect current language and static_info_tables_* modifications
- Available Hook to post modify option list
- Dynamic add of available County list
- Dynamic add of available State list for Format Options ISO 3166-1 A2/A3
- Custom mapping possible by TypoScript

## Requirements
Expand Down Expand Up @@ -43,6 +46,7 @@ plugin.tx_powermailcountry.settings.mapping {
```

## Changelog
- 11.2.0 - Add English Short Name and Custom Format Option
- 11.1.0 - Add corresponding County Select
- 11.0.0 - Support for TYPO3 v11 (thanks to Frank Gerards)

10 changes: 8 additions & 2 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
<source>Format</source>
</trans-unit>
<trans-unit id="tx_powermail_domain_model_field.country_code.a2">
<source>ISO 3166-1 A2 Country code</source>
<source>ISO 3166-1 A2 Country Code</source>
</trans-unit>
<trans-unit id="tx_powermail_domain_model_field.country_code.a3">
<source>ISO 3166-1 A3 Country code</source>
<source>ISO 3166-1 A3 Country Code</source>
</trans-unit>
<trans-unit id="tx_powermail_domain_model_field.country_code.cn_short_en">
<source>English Country Short Name</source>
</trans-unit>
<trans-unit id="tx_powermail_domain_model_field.country_code.custom">
<source>Custom Names - Use Options Field</source>
</trans-unit>
<trans-unit id="tx_powermail_domain_model_field.limitation">
<source>Limitation</source>
Expand Down
43 changes: 30 additions & 13 deletions Resources/Private/Partials/Form/Field/Country.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@

<div class="powermail_fieldwrap powermail_fieldwrap_type_country powermail_fieldwrap_{field.marker} {field.css} {settings.styles.framework.fieldAndLabelWrappingClasses}">
<f:render partial="Form/FieldLabel" arguments="{_all}" />

<div class="{settings.styles.framework.fieldWrappingClasses}">
<f:form.select
property="{field.marker}"
options="{pc:countries(field: field)}"
optionValueField="{pc:optionValueField(format: field.format)}"
optionLabelField="{pc:optionLabelField()}"
sortByOptionLabel="true"
prependOptionLabel="{f:translate(key:'pleaseChoose')}"
class="powermail_country {settings.styles.framework.fieldClasses} {vh:Validation.ErrorClass(field:field, class:'powermail_field_error')}{f:if(condition: field.showCounty, then: 'connected-county')}"
value="{vh:Misc.PrefillField(field:field, mail:mail)}"
additionalAttributes="{vh:Validation.ValidationDataAttribute(field:field)}"
id="powermail_field_{field.marker}"
/>
<f:if condition="{field.format} == 3">
<f:then>
<vh:form.selectField
property="{field.marker}"
options="{field.modifiedSettings}"
sortByOptionLabel="true"
prependOptionLabel="{f:translate(key:'pleaseChoose')}"
class="powermail_country {settings.styles.framework.fieldClasses} {vh:Validation.ErrorClass(field:field, class:'powermail_field_error')}{f:if(condition: field.showCounty, then: 'connected-county')}"
value="{vh:Misc.PrefillField(field:field, mail:mail)}"
additionalAttributes="{vh:Validation.ValidationDataAttribute(field:field)}"
id="powermail_field_{field.marker}"
/>
</f:then>
<f:else>
<f:form.select
property="{field.marker}"
options="{pc:countries(field: field)}"
optionValueField="{pc:optionValueField(format: field.format)}"
optionLabelField="{pc:optionLabelField()}"
sortByOptionLabel="true"
prependOptionLabel="{f:translate(key:'pleaseChoose')}"
class="powermail_country {settings.styles.framework.fieldClasses} {vh:Validation.ErrorClass(field:field, class:'powermail_field_error')}{f:if(condition: field.showCounty, then: 'connected-county')}"
value="{vh:Misc.PrefillField(field:field, mail:mail)}"
additionalAttributes="{vh:Validation.ValidationDataAttribute(field:field)}"
id="powermail_field_{field.marker}"
/>
</f:else>
</f:if>


</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'author' => 'Andreas Sommer',
'author_email' => 'sommer@belsignum.com',
'state' => 'stable',
'version' => '11.1.2',
'version' => '11.2.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-11.5.99',
Expand Down

0 comments on commit 1183533

Please sign in to comment.