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

IBX-8525: Added language code validation #1356

Merged
merged 4 commits into from
Oct 10, 2024
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
10 changes: 10 additions & 0 deletions phpstan-baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,13 @@ parameters:
message: "#^Parameter \\#2 \\$size of function array_chunk expects int\\<1, max\\>, int given\\.$#"
count: 1
path: src/lib/UI/Module/ContentTree/NodeFactory.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\> given\\.$#"
count: 1
path: src/lib/Siteaccess/SiteaccessResolver.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<string, Ibexa\\\\AdminUi\\\\Form\\\\Data\\\\FieldDefinitionData\\> given\\.$#"
count: 1
path: tests/lib/Form/Data/ContentTypeDataTest.php
10 changes: 10 additions & 0 deletions phpstan-baseline-8.0.neon
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,13 @@ parameters:
message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$twig follows optional parameter \\$name\\.$#"
count: 1
path: tests/lib/Tab/TabRegistryTest.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\> given\\.$#"
count: 1
path: src/lib/Siteaccess/SiteaccessResolver.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<string, Ibexa\\\\AdminUi\\\\Form\\\\Data\\\\FieldDefinitionData\\> given\\.$#"
count: 1
path: tests/lib/Form/Data/ContentTypeDataTest.php
201 changes: 201 additions & 0 deletions phpstan-baseline-8.3.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$array of function array_shift expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\> given\\.$#"
count: 1
path: src/bundle/Controller/Content/VersionDraftConflictController.php

-
message: "#^Parameter \\#1 \\$array of function array_keys expects array, array\\|null given\\.$#"
count: 1
path: src/bundle/Controller/ContentDraftController.php

-
message: "#^Parameter \\#1 \\$array of function usort expects TArray of array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\>, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\> given\\.$#"
count: 1
path: src/bundle/Controller/ContentTypeController.php

-
message: "#^Parameter \\#1 \\$string1 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/bundle/Controller/ContentTypeController.php

-
message: "#^Parameter \\#2 \\$string2 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/bundle/Controller/ContentTypeController.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\> given\\.$#"
count: 1
path: src/bundle/Controller/ContentTypeGroupController.php

-
message: "#^Parameter \\#1 \\$array of function array_shift expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/bundle/Controller/ContentViewController.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/bundle/Controller/ContentViewController.php

-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
count: 1
path: src/bundle/Templating/Twig/UniversalDiscoveryExtension.php

-
message: "#^Parameter \\#1 \\$object of function date_format expects DateTimeInterface, DateTime\\|false given\\.$#"
count: 4
path: src/lib/Behat/Component/Fields/DateAndTime.php

-
message: "#^Parameter \\#1 \\$object of function date_format expects DateTimeInterface, DateTime\\|false given\\.$#"
count: 4
path: src/lib/Behat/Component/Fields/Time.php

-
message: "#^Parameter \\#2 \\$offset of function substr expects int, int\\<0, max\\>\\|false given\\.$#"
count: 1
path: src/lib/Behat/Page/RolePage.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\> given\\.$#"
count: 1
path: src/lib/EventListener/ContentProxyCreateDraftListener.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\|null given\\.$#"
count: 1
path: src/lib/Form/DataTransformer/FieldType/BinaryFileValueTransformer.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\|null given\\.$#"
count: 1
path: src/lib/Form/DataTransformer/FieldType/ImageAssetValueTransformer.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\|null given\\.$#"
count: 1
path: src/lib/Form/DataTransformer/FieldType/ImageValueTransformer.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\|null given\\.$#"
count: 1
path: src/lib/Form/DataTransformer/FieldType/MediaValueTransformer.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Form/EventListener/AddLanguageFieldBasedOnContentListener.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Form/Type/ChoiceList/Loader/AvailableTranslationLanguageChoiceLoader.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Form/Type/ChoiceList/Loader/BaseTranslationLanguageChoiceLoader.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 2
path: src/lib/Form/Type/ChoiceList/Loader/ContentEditTranslationChoiceLoader.php

-
message: "#^Parameter \\#1 \\$array of function usort expects TArray of array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\>, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\> given\\.$#"
count: 1
path: src/lib/Form/Type/ChoiceList/Loader/ContentTypeChoiceLoader.php

-
message: "#^Parameter \\#1 \\$string1 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Form/Type/ChoiceList/Loader/ContentTypeChoiceLoader.php

-
message: "#^Parameter \\#2 \\$string2 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Form/Type/ChoiceList/Loader/ContentTypeChoiceLoader.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Form/Type/Content/Translation/TranslationAddType.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Form/Type/ContentType/Translation/TranslationAddType.php

-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Form/Type/FieldDefinition/User/PasswordConstraintCheckboxType.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ObjectState\\\\ObjectState\\> given\\.$#"
count: 1
path: src/lib/Form/Type/ObjectState/ContentObjectStateUpdateType.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Pagination/Mapper/AbstractPagerContentToDataMapper.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserGroup\\> given\\.$#"
count: 1
path: src/lib/Permission/PermissionChecker.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Tab/Dashboard/PagerLocationToDataMapper.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Language\\> given\\.$#"
count: 1
path: src/lib/Tab/LocationView/ContentTab.php

-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#"
count: 1
path: src/lib/Translation/Extractor/PolicyTranslationExtractor.php

-
message: "#^Parameter \\#1 \\$array of function usort expects TArray of array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\>, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\ContentType\\> given\\.$#"
count: 1
path: src/lib/UI/Config/Provider/ContentTypes.php

-
message: "#^Parameter \\#1 \\$string1 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/lib/UI/Config/Provider/ContentTypes.php

-
message: "#^Parameter \\#2 \\$string2 of function strnatcasecmp expects string, string\\|null given\\.$#"
count: 1
path: src/lib/UI/Config/Provider/ContentTypes.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\VersionInfo\\> given\\.$#"
count: 1
path: src/lib/UI/Dataset/ContentDraftsDataset.php

-
message: "#^Parameter \\#2 \\$length of function array_chunk expects int\\<1, max\\>, int given\\.$#"
count: 1
path: src/lib/UI/Module/ContentTree/NodeFactory.php

-
message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$translator follows optional parameter \\$name\\.$#"
count: 1
path: tests/lib/Tab/TabRegistryTest.php

-
message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$twig follows optional parameter \\$name\\.$#"
count: 1
path: tests/lib/Tab/TabRegistryTest.php
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8615,11 +8615,6 @@ parameters:
count: 1
path: src/lib/Siteaccess/SiteaccessResolver.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\SiteAccess\\> given\\.$#"
count: 1
path: src/lib/Siteaccess/SiteaccessResolver.php

-
message: "#^Property Ibexa\\\\AdminUi\\\\Siteaccess\\\\SiteaccessResolver\\:\\:\\$siteAccessPreviewVoters \\(array\\<Ibexa\\\\AdminUi\\\\Siteaccess\\\\SiteaccessPreviewVoterInterface\\>\\) does not accept iterable\\.$#"
count: 1
Expand Down Expand Up @@ -10906,11 +10901,6 @@ parameters:
count: 1
path: tests/lib/Form/Data/ContentTranslationDataTest.php

-
message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable\\<string, Ibexa\\\\AdminUi\\\\Form\\\\Data\\\\FieldDefinitionData\\> given\\.$#"
count: 1
path: tests/lib/Form/Data/ContentTypeDataTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\Form\\\\Data\\\\FieldDefinitionDataTest\\:\\:testFieldDefinition\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
4 changes: 3 additions & 1 deletion phpstan-baseline.neon.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
$includes = [];
if (PHP_VERSION_ID < 80000) {
$includes[] = __DIR__ . '/phpstan-baseline-7.4.neon';
} else {
} elseif (PHP_VERSION_ID < 80300) {
$includes[] = __DIR__ . '/phpstan-baseline-8.0.neon';
} else {
$includes[] = __DIR__ . '/phpstan-baseline-8.3.neon';
}

$config = [];
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/public/scss/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ form:not(.form-inline) {
&__icon {
fill: $ibexa-color-danger;
margin-right: calculateRem(4px);
flex-shrink: 0;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/validators.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<target state="new">Selected Location has no children.</target>
<note>key: ezplatform.trash.location_has_no_children</note>
</trans-unit>
<trans-unit id="ea852842b560d609441b8470b79735f2dc91698f" resname="ibexa.language.language_code.format">
<source>The Language code {{ value }} contains illegal characters. Language code should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores, hyphens and colons.</source>
<target state="new">The Language code {{ value }} contains illegal characters. Language code should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores, hyphens and colons.</target>
<note>key: ibexa.language.language_code.format</note>
</trans-unit>
<trans-unit id="cf558f546b83d94f1272929f81c64bd33d2997bc" resname="js.error.address_not_found">
<source>Provided address does not exist</source>
<target state="new">Provided address does not exist</target>
Expand Down
33 changes: 30 additions & 3 deletions src/lib/Form/Data/Language/LanguageCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@

namespace Ibexa\AdminUi\Form\Data\Language;

class LanguageCreateData
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Symfony\Component\Validator\Constraints as Assert;

class LanguageCreateData implements TranslationContainerInterface
{
/** @var string */
/**
* @var string
*
* @Assert\NotBlank()
*/
private $name;

/** @var string */
/**
* @var string
*
* @Assert\NotBlank()
*
* @Assert\Regex(
* pattern="/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/",
* message="ibexa.language.language_code.format"
* )
*/
private $languageCode;

/** @var bool */
Expand Down Expand Up @@ -77,6 +94,16 @@ public function setEnabled(bool $enabled): self

return $this;
}

public static function getTranslationMessages(): array
{
return [
Message::create('ibexa.language.language_code.format', 'validators')
->setDesc(
'The Language code {{ value }} contains illegal characters. Language code should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores, hyphens and colons.'
),
];
}
}

class_alias(LanguageCreateData::class, 'EzSystems\EzPlatformAdminUi\Form\Data\Language\LanguageCreateData');
7 changes: 6 additions & 1 deletion src/lib/Form/Data/Language/LanguageUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
namespace Ibexa\AdminUi\Form\Data\Language;

use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Symfony\Component\Validator\Constraints as Assert;

class LanguageUpdateData
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Language */
private $language;

/** @var string */
/**
* @var string
*
* @Assert\NotBlank()
*/
private $name;

/** @var bool */
Expand Down
Loading