From a2c1cef3531228566b195eafd2a9783a4c74a198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 27 Jan 2024 23:47:22 +0100 Subject: [PATCH 1/5] change Form\Layout\Section*::$formLayout(Class) to formLayoutSeed --- phpstan.neon.dist | 18 ++++++------------ src/Form/Layout/Section.php | 9 ++++++--- src/Form/Layout/Section/Accordion.php | 10 +++++++--- src/Form/Layout/Section/Columns.php | 10 +++++++--- src/Form/Layout/Section/Tabs.php | 10 +++++++--- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 99797be35f..0509d05fa4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -313,16 +313,19 @@ parameters: message: '~^Method Atk4\\Ui\\Form\\Layout\\Custom::addButton\(\) should return Atk4\\Ui\\Button but returns Atk4\\Ui\\AbstractView\.$~' - path: 'src/Form/Layout/Section.php' - message: '~^Method Atk4\\Ui\\Form\\Layout\\Section::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~' + message: '~^Method Atk4\\Ui\\Form\\Layout\\Section::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\)\.$~' - path: 'src/Form/Layout/Section/Accordion.php' message: '~^Return type \(Atk4\\Ui\\Form\\Layout\) of method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should be compatible with return type \(Atk4\\Ui\\AccordionSection\) of method Atk4\\Ui\\Accordion::addSection\(\)$~' - path: 'src/Form/Layout/Section/Accordion.php' - message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~' + message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Accordion\)\.$~' + - + path: 'src/Form/Layout/Section/Columns.php' + message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Columns::addColumn\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Columns\)\.$~' - path: 'src/Form/Layout/Section/Tabs.php' - message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Tabs::addTab\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~' + message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Tabs::addTab\(\) should return Atk4\\Ui\\Form\\Layout but returns static\(Atk4\\Ui\\Form\\Layout\\Section\\Tabs\)\.$~' - path: 'src/Grid.php' message: '~^Property Atk4\\Ui\\Grid::\$menu \(array\|Atk4\\Ui\\Menu\|false\) does not accept Atk4\\Ui\\AbstractView\.$~' @@ -377,15 +380,6 @@ parameters: # TODO these rules are generated, this ignores should be fixed in the code # for level = 5 - - - path: 'src/Form/Layout/Section.php' - message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array> given\.$~' - - - path: 'src/Form/Layout/Section/Accordion.php' - message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array> given\.$~' - - - path: 'src/Form/Layout/Section/Tabs.php' - message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array> given\.$~' - path: 'src/Grid.php' message: '~^Parameter #1 \$view of method Atk4\\Ui\\Grid::addActionMenuItem\(\) expects Atk4\\Ui\\View\|string, Atk4\\Data\\Model\\UserAction given\.$~' diff --git a/src/Form/Layout/Section.php b/src/Form/Layout/Section.php index 84441c82b1..139af75e64 100644 --- a/src/Form/Layout/Section.php +++ b/src/Form/Layout/Section.php @@ -12,8 +12,8 @@ */ class Section extends View { - /** @var class-string */ - public $formLayout = Form\Layout::class; + /** @var array */ + public $formLayoutSeed = [Form\Layout::class]; public Form $form; @@ -24,6 +24,9 @@ class Section extends View */ public function addSection() { - return $this->add([$this->formLayout, 'form' => $this->form]); + $res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]); + $this->add($res); + + return $res; } } diff --git a/src/Form/Layout/Section/Accordion.php b/src/Form/Layout/Section/Accordion.php index b04926537e..75c3d6afe1 100644 --- a/src/Form/Layout/Section/Accordion.php +++ b/src/Form/Layout/Section/Accordion.php @@ -8,14 +8,15 @@ use Atk4\Ui\AccordionSection; use Atk4\Ui\Form; use Atk4\Ui\Js\JsBlock; +use Atk4\Ui\View; /** * Represents form controls in accordion. */ class Accordion extends UiAccordion { - /** @var class-string */ - public $formLayout = Form\Layout::class; + /** @var array */ + public $formLayoutSeed = [Form\Layout::class]; public Form $form; @@ -49,7 +50,10 @@ public function addSection($title, \Closure $callback = null, $icon = 'dropdown' { $section = parent::addSection($title, $callback, $icon); - return $section->add([$this->formLayout, 'form' => $this->form]); + $res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]); + $section->add($res); + + return $res; } /** diff --git a/src/Form/Layout/Section/Columns.php b/src/Form/Layout/Section/Columns.php index 0a01e9c5d0..0fe17af223 100644 --- a/src/Form/Layout/Section/Columns.php +++ b/src/Form/Layout/Section/Columns.php @@ -6,14 +6,15 @@ use Atk4\Ui\Columns as UiColumns; use Atk4\Ui\Form; +use Atk4\Ui\View; /** * Represents form controls in columns. */ class Columns extends UiColumns { - /** @var class-string */ - public $formLayout = Form\Layout::class; + /** @var array */ + public $formLayoutSeed = [Form\Layout::class]; public Form $form; @@ -25,6 +26,9 @@ public function addColumn($defaults = []) { $column = parent::addColumn($defaults); - return $column->add([$this->formLayout, 'form' => $this->form]); // @phpstan-ignore-line + $res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]); + $column->add($res); + + return $res; } } diff --git a/src/Form/Layout/Section/Tabs.php b/src/Form/Layout/Section/Tabs.php index c1d4fd3eed..919ce45a5d 100644 --- a/src/Form/Layout/Section/Tabs.php +++ b/src/Form/Layout/Section/Tabs.php @@ -6,14 +6,15 @@ use Atk4\Ui\Form; use Atk4\Ui\Tabs as UiTabs; +use Atk4\Ui\View; /** * Represents form controls in tabs. */ class Tabs extends UiTabs { - /** @var class-string */ - public $formLayout = Form\Layout::class; + /** @var array */ + public $formLayoutSeed = [Form\Layout::class]; public Form $form; @@ -25,6 +26,9 @@ public function addTab($name, \Closure $callback = null, array $settings = []) { $tab = parent::addTab($name, $callback, $settings); - return $tab->add([$this->formLayout, 'form' => $this->form]); + $res = View::fromSeed($this->formLayoutSeed, ['form' => $this->form]); + $tab->add($res); + + return $res; } } From ab02427020d5efa8f981ad767374f197356921fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 27 Jan 2024 23:47:33 +0100 Subject: [PATCH 2/5] rename Form\Layout::$defaultHint --- demos/form/html-layout.php | 2 +- src/Form/Layout.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/form/html-layout.php b/demos/form/html-layout.php index 36afd4c3d3..779f125a1b 100644 --- a/demos/form/html-layout.php +++ b/demos/form/html-layout.php @@ -48,7 +48,7 @@ Form\Layout::class, [ 'defaultInputTemplate' => __DIR__ . '/templates/input.html', - 'defaultHint' => [Label::class, 'class' => ['pointing', 'below']], + 'defaultHintSeed' => [Label::class, 'class' => ['pointing', 'below']], ], ], ]); diff --git a/src/Form/Layout.php b/src/Form/Layout.php index 5aebc49709..f92e1b9a18 100644 --- a/src/Form/Layout.php +++ b/src/Form/Layout.php @@ -40,7 +40,7 @@ class Layout extends AbstractLayout public $inputTemplate; /** @var array Seed for creating input hint View used in this layout. */ - public $defaultHint = [Label::class, 'class' => ['pointing']]; + public $defaultHintSeed = [Label::class, 'class' => ['pointing']]; #[\Override] protected function _addControl(Control $control, Field $field): Control @@ -205,7 +205,7 @@ protected function recursiveRender(): void } if ($element->hint && $template->hasTag('Hint')) { - $hint = Factory::factory($this->defaultHint); + $hint = Factory::factory($this->defaultHintSeed); $hint->name = $element->name . '_hint'; if (is_object($element->hint) || is_array($element->hint)) { $hint->add($element->hint); From bb5d0ffa9b609bf03ecc4118b15dddb6fe2b551c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 27 Jan 2024 23:52:30 +0100 Subject: [PATCH 3/5] change CardDeck::$card(Class) to cardSeed --- src/CardDeck.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CardDeck.php b/src/CardDeck.php index d7beb83dfc..e472e0ef1a 100644 --- a/src/CardDeck.php +++ b/src/CardDeck.php @@ -22,8 +22,8 @@ class CardDeck extends View public $defaultTemplate = 'card-deck.html'; - /** @var class-string Card type inside this deck. */ - public $card = Card::class; + /** @var array Seed of Card inside this deck. */ + public $cardSeed = [Card::class]; /** @var bool Whether card should use table display or not. */ public $useTable = false; @@ -146,7 +146,7 @@ public function setModel(Model $model, array $fields = null, array $extra = null if ($count) { foreach ($this->model as $m) { /** @var Card */ - $c = $this->cardHolder->add(Factory::factory([$this->card], ['useLabel' => $this->useLabel, 'useTable' => $this->useTable])); + $c = $this->cardHolder->add(Factory::factory($this->cardSeed, ['useLabel' => $this->useLabel, 'useTable' => $this->useTable])); $c->setModel($m, $fields); if ($extra) { $c->addExtraFields($m, $extra, $this->extraGlue); From f8e9c4fd3fff1ac6c0bd85efb3d81fcacc1efaf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 27 Jan 2024 23:55:16 +0100 Subject: [PATCH 4/5] remove unused Card::$executor --- src/Card.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Card.php b/src/Card.php index 280bd74044..1bd3c5421d 100644 --- a/src/Card.php +++ b/src/Card.php @@ -70,9 +70,6 @@ class Card extends View /** @var bool Use Field label with value data. */ public $useLabel = false; - /** @var string Default executor class. */ - public $executor = UserAction\ModalExecutor::class; - #[\Override] protected function init(): void { From a277ecaeb0d0864aff902419f27b1bc17a0c4a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 27 Jan 2024 23:59:44 +0100 Subject: [PATCH 5/5] change Card::$cardSection(Class) to cardSectionSeed --- src/Card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Card.php b/src/Card.php index 1bd3c5421d..52833856d7 100644 --- a/src/Card.php +++ b/src/Card.php @@ -46,8 +46,8 @@ class Card extends View /** @var CardSection|null The main card section of this card */ public $section; - /** @var string The CardSection default class name. */ - public $cardSection = CardSection::class; + /** @var array The CardSection default seed. */ + public $cardSectionSeed = [CardSection::class]; /** @var View|null The extra content view container for the card. */ public $extraContainer; @@ -101,7 +101,7 @@ protected function init(): void public function getSection() { if (!$this->section) { - $this->section = CardSection::addToWithCl($this, [$this->cardSection, 'card' => $this]); + $this->section = CardSection::addToWithCl($this, array_merge($this->cardSectionSeed, ['card' => $this])); } return $this->section; @@ -190,7 +190,7 @@ public function setModel(Model $entity, array $fields = null): void */ public function addSection(string $title = null, Model $model = null, array $fields = null, bool $useTable = false, bool $useLabel = false) { - $section = CardSection::addToWithCl($this, [$this->cardSection, 'card' => $this], ['Section']); + $section = CardSection::addToWithCl($this, array_merge($this->cardSectionSeed, ['card' => $this]), ['Section']); if ($title) { View::addTo($section, [$title, 'class.header' => true]); }