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

Adapt to new widgets feature "theme config" #244

Merged
merged 23 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Yiisoft\Form\Field;
use Yiisoft\Form\ThemeDispatcher;

/**
* @var array $params
*/

return [
static function (ContainerInterface $container) use ($params) {
Field::initialize(
$params['yiisoft/form']['configs'],
$params['yiisoft/form']['defaultConfig'],
ThemeDispatcher::initialize(
$params['yiisoft/form']['themeConfigs'],
$params['yiisoft/form']['defaultThemeName'],
);
},
];
4 changes: 2 additions & 2 deletions config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

return [
'yiisoft/form' => [
'configs' => [
'themeConfigs' => [
vjik marked this conversation as resolved.
Show resolved Hide resolved
'default' => [],
],
'defaultConfig' => 'default',
'defaultThemeName' => 'default',
],
];
2 changes: 1 addition & 1 deletion docs/creating-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ final class SuffixInput extends InputField
Usage is the following:

```php
echo \Yiisoft\Form\Field::input(SuffixInput::class, $procentForm, 'value')->suffix('%');
echo \Yiisoft\Form\ThemeDispatcher::input(SuffixInput::class, $procentForm, 'value')->suffix('%');
```

Result will be:
Expand Down
10 changes: 5 additions & 5 deletions docs/creating-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ In the controller, we will pass an instance of that `formModel` to the `view`:
declare(strict_types=1);

use Yiisoft\Form\FormModel;
use Yiisoft\Form\Field;
use Yiisoft\Form\ThemeDispatcher;
use Yiisoft\Html\Html;
use Yiisoft\Router\UrlGeneratorInterface;
use Yiisoft\Translator\Translator;
Expand Down Expand Up @@ -111,12 +111,12 @@ $this->setTitle($title);
->csrf($csrf)
->id('form-auth-login')
->open() ?>
<?= Field::text($formModel, 'login')
<?= ThemeDispatcher::text($formModel, 'login')
vjik marked this conversation as resolved.
Show resolved Hide resolved
->autofocus()
->tabindex(1) ?>
<?= Field::password($formModel, 'password')
<?= ThemeDispatcher::password($formModel, 'password')
->tabindex(2) ?>
<?= Field::submitButton()
<?= ThemeDispatcher::submitButton()
->containerClass('d-grid gap-2 form-floating')
->buttonClass('btn btn-primary btn-lg mt-3')
->buttonId('login-button')
Expand All @@ -132,4 +132,4 @@ $this->setTitle($title);
There is a way to declare validation rules using attributes.
For detailed information of using attributes see [Yiisoft Validator](https://github.com/yiisoft/validator).

> If you are using attributes then there is no need to declare the `getRules` method.
> If you are using attributes then there is no need to declare the `getRules` method.
270 changes: 0 additions & 270 deletions src/Field.php

This file was deleted.

6 changes: 6 additions & 0 deletions src/Field/Base/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Form\Field\Base;

use InvalidArgumentException;
use Yiisoft\Form\ThemeDispatcher;
use Yiisoft\Html\Html;
use Yiisoft\Html\Tag\CustomTag;
use Yiisoft\Widget\Widget;
Expand Down Expand Up @@ -146,6 +147,11 @@ protected function prepareContainerAttributes(array &$attributes): void
{
}

final protected static function getDefaultConfig(): array
{
return ThemeDispatcher::getTheme()->getFieldConfig(static::class);
}

private function renderEnd(): string
{
$content = $this->generateEndContent();
Expand Down
6 changes: 6 additions & 0 deletions src/Field/Part/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use Yiisoft\Form\Field\Base\FormAttributeTrait;
use Yiisoft\Form\ThemeDispatcher;
use Yiisoft\Html\Html;
use Yiisoft\Html\Tag\CustomTag;
use Yiisoft\Widget\Widget;
Expand Down Expand Up @@ -167,4 +168,9 @@ public function render(): string
->encode($this->encode)
->render();
}

protected static function getDefaultConfig(): array
{
return ThemeDispatcher::getTheme()->getErrorConfig();
}
}
Loading