Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into new-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 16, 2023
2 parents 26ca751 + e6861fd commit f0fb4be
Show file tree
Hide file tree
Showing 35 changed files with 646 additions and 987 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ij_php_space_after_type_cast = true
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
indent_size = 2
1 change: 0 additions & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ enabled:
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
"yiisoft/friendly-exception": "^1.0",
"yiisoft/html": "^3.0",
"yiisoft/http": "^1.2",
"yiisoft/hydrator": "dev-master",
"yiisoft/hydrator-validator": "dev-master",
"yiisoft/strings": "^2.0",
"yiisoft/validator": "^1.0",
"yiisoft/widget": "^2.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.15.7",
"rector/rector": "^0.18.3",
"roave/infection-static-analysis-plugin": "^1.18",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.6",
Expand All @@ -56,7 +58,8 @@
},
"config-plugin": {
"params": "params.php",
"bootstrap": "bootstrap.php"
"bootstrap": "bootstrap.php",
"di": "di.php"
}
},
"config": {
Expand Down
15 changes: 15 additions & 0 deletions config/di.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Yiisoft\Definitions\Reference;
use Yiisoft\Form\FormHydrator;
use Yiisoft\Hydrator\Validator\ValidatingHydrator;

return [
FormHydrator::class => [
'__construct()' => [
'hydrator' => Reference::to(ValidatingHydrator::class),
],
],
];
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
4 changes: 2 additions & 2 deletions src/Field/Base/FormAttributeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final protected function getFirstError(): ?string
{
return $this
->getFormModel()
->getFormErrors()
->getFirstError($this->getFormAttributeName());
->getValidationResult()
?->getAttributeErrorMessages($this->getFormAttributeName())[0] ?? null;
}
}
7 changes: 3 additions & 4 deletions src/Field/Base/ValidationClass/ValidationClassTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ private function addClassesToAttributes(
?string $invalidClass,
?string $validClass,
): void {
if (!$formModel->isValidated()) {
$validationResult = $formModel->getValidationResult();
if ($validationResult === null) {
return;
}

$hasErrors = $formModel
->getFormErrors()
->hasErrors($attributeName);
$hasErrors = !$validationResult->isAttributeValid($attributeName);

if ($hasErrors && $invalidClass !== null) {
Html::addCssClass($attributes, $invalidClass);
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected function beforeRender(): void
}

if ($rule instanceof Regex) {
if (!($rule->isNot())) {
if (!$rule->isNot()) {
$this->inputAttributes['pattern'] = Html::normalizeRegexpPattern(
$rule->getPattern()
);
Expand Down
30 changes: 28 additions & 2 deletions src/Field/ErrorSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class ErrorSummary extends BaseField
private array $footerAttributes = [];
private string $header = 'Please fix the following errors:';
private array $headerAttributes = [];
private array $listAttributes = [];

public function formModel(FormModelInterface $formModel): self
{
Expand Down Expand Up @@ -65,6 +66,16 @@ public function onlyAttributes(string ...$names): self
return $new;
}

/**
* Use only common errors when rendering the error summary.
*/
public function onlyCommonErrors(): self
{
$new = clone $this;
$new->onlyAttributes = [''];
return $new;
}

/**
* Set the footer text for the error summary
*/
Expand All @@ -80,7 +91,7 @@ public function footer(string $value): self
*
* @param array $values Attribute values indexed by attribute names.
*
* See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
* See {@see Html::renderTagAttributes} for details on how attributes are being rendered.
*/
public function footerAttributes(array $values): self
{
Expand All @@ -104,7 +115,7 @@ public function header(string $value): self
*
* @param array $values Attribute values indexed by attribute names.
*
* See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
* See {@see Html::renderTagAttributes} for details on how attributes are being rendered.
*/
public function headerAttributes(array $values): self
{
Expand All @@ -113,6 +124,20 @@ public function headerAttributes(array $values): self
return $new;
}

/**
* Set errors list container attributes.
*
* @param array $attributes Attribute values indexed by attribute names.
*
* See {@see Html::renderTagAttributes} for details on how attributes are being rendered.
*/
public function listAttributes(array $attributes): self
{
$new = clone $this;
$new->listAttributes = $attributes;
return $new;
}

protected function generateContent(): ?string
{
$messages = $this->collectErrors();
Expand All @@ -127,6 +152,7 @@ protected function generateContent(): ?string
}

$content[] = Html::ul()
->attributes($this->listAttributes)
->strings($messages, [], $this->encode)
->render();

Expand Down
2 changes: 1 addition & 1 deletion src/Field/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected function beforeRender(): void
}

if ($rule instanceof Regex) {
if (!($rule->isNot())) {
if (!$rule->isNot()) {
$this->inputAttributes['pattern'] = Html::normalizeRegexpPattern(
$rule->getPattern()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Telephone.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function beforeRender(): void
}

if ($rule instanceof Regex) {
if (!($rule->isNot())) {
if (!$rule->isNot()) {
$this->inputAttributes['pattern'] = Html::normalizeRegexpPattern(
$rule->getPattern()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected function beforeRender(): void
}

if ($rule instanceof Regex) {
if (!($rule->isNot())) {
if (!$rule->isNot()) {
$this->inputAttributes['pattern'] = Html::normalizeRegexpPattern(
$rule->getPattern()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function beforeRender(): void
if ($rule instanceof UrlRule) {
$pattern = $rule->getPattern();
} elseif ($rule instanceof Regex) {
if (!($rule->isNot())) {
if (!$rule->isNot()) {
$pattern = $rule->getPattern();
}
}
Expand Down
107 changes: 0 additions & 107 deletions src/FormErrors.php

This file was deleted.

Loading

0 comments on commit f0fb4be

Please sign in to comment.