8000 Rename `Form::setModel()` method to `Form::setEntity()` by mvorisek · Pull Request #2239 · atk4/ui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rename Form::setModel() method to Form::setEntity() #2239

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

Merged
merged 28 commits into from
Jan 6, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $tabs->addTab('Settings', function (\Atk4\Ui\VirtualPage $p) use ($app) {
$m = new Settings($app->db);
$m = $m->load(2);
\Atk4\Ui\Form::addTo($p)
->setModel($m);
->setEntity($m);
});
```

Expand Down
4 changes: 2 additions & 2 deletions demos/_unit-test/callback-nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
$loaderSubSub->set(static function (Loader $p) use ($m) {
Header::addTo($p, ['Loader-3', 'size' => 4]);

$c = Crud::addTo($p, ['ipp' => 4]);
$c->setModel($m, [$m->fieldName()->name]);
$crud = Crud::addTo($p, ['ipp' => 4]);
$crud->setModel($m, [$m->fieldName()->name]);
});
});
Button::addTo($p, ['Load2'])
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$vp->cb->triggerOnReload = false;

$form = Form::addTo($vp);
$form->setModel($m->loadAny(), [$m->fieldName()->name]);
$form->setEntity($m->loadAny(), [$m->fieldName()->name]);
$form->getControl($m->fieldName()->name)->caption = 'TestName';

$table = Table::addTo($app);
Expand Down
3 changes: 2 additions & 1 deletion demos/_unit-test/lookup-virtual-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
$form = Form::addTo($vp);
$form->addControl('category', [Form\Control\Lookup::class, 'model' => new Category($vp->getApp()->db)]);
$form->onSubmit(static function (Form $form) {
$category = $form->getControl('category')->model->load($form->entity->get('category'));
$category = Form\Control\Lookup::assertInstanceOf($form->getControl('category'))
->model->load($form->entity->get('category'));

return new JsToast($category->getTitle());
});
Expand Down
2 changes: 1 addition & 1 deletion demos/_unit-test/scroll.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
$grid->addActionButton(['icon' => 'bell'], $makeClickJsToastFx('action'));
$grid->table->onRowClick($makeClickJsToastFx('row'));

// TODO JsPaginator should be possible to be added no later than setModel call
// TODO JsPaginator should be possible to be added no later than Grid::setModel() call
// https://github.com/atk4/ui/issues/1934
$grid->addJsPaginator(30);
3 changes: 2 additions & 1 deletion 3 demos/_unit-test/virtual-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
$form = Form::addTo($thirdPage);
$form->addControl('category', [Form\Control\Lookup::class, 'model' => new Category($thirdPage->getApp()->db)]);
$form->onSubmit(static function (Form $form) {
$category = $form->getControl('category')->model->load($form->entity->get('category'));
$category = Form\Control\Lookup::assertInstanceOf($form->getControl('category'))
->model->load($form->entity->get('category'));

return new JsToast($category->getTitle());
});
Expand Down
2 changes: 1 addition & 1 deletion demos/basic/breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// here we can check for additional criteria and display a deeper level on the crumb

$form = Form::addTo($app);
$form->setModel($model);
$form->setEntity($model);
$form->onSubmit(static function (Form $form) {
return new JsToast('Form Submitted! Data saving is not possible in demo!');
});
Expand Down
4 changes: 2 additions & 2 deletions demos/collection/crud3.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ protected function init(): void

// add Crud
Header::addTo($app, ['Crud with Array Persistence']);
$c = Crud::addTo($app, ['ipp' => 5]);
$c->setModel($model);
$crud = Crud::addTo($app, ['ipp' => 5]);
$crud->setModel($model);
8 changes: 6 additions & 2 deletions demos/collection/multitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Atk4\Ui\Js\JsModal;
use Atk4\Ui\Js\JsReload;
use Atk4\Ui\Table;
use Atk4\Ui\View\ModelTrait;
use Atk4\Ui\VirtualPage;

/** @var App $app */
Expand All @@ -21,6 +22,10 @@
// re-usable component implementing counter

$finderClass = AnonymousClassNameCache::get_class(fn () => new class extends Columns {
use ModelTrait {
setModel as private _setModel;
}

/**
* @return list<mixed>
*/
Expand All @@ -37,10 +42,9 @@ private function explodeSelectionValue(string $value): array
/**
* @param list<string> $route
*/
#[\Override]
public function setModel(Model $model, array $route = []): void
{
parent::setModel($model);
$this->_setModel($model);

$this->addClass('internally celled');

Expand Down
4 changes: 2 additions & 2 deletions demos/data-action/factory-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getCardButton(Model\UserAction $action)
unset($country->getDirtyRef()[$country->fieldName()->name]);

$cardActions = Card::addTo($app, ['useLabel' => true, 'executorFactory' => new $myFactory()]);
$cardActions->setModel($country);
$cardActions->setEntity($country);
foreach ($country->getModel()->getUserActions() as $action) {
$showActions = ['callback', 'preview', 'edit_argument', 'edit_argument_preview', 'edit_iso', 'confirm', 'multi_step'];
if (in_array($action->shortName, $showActions, true)) {
Expand All @@ -80,6 +80,6 @@ protected function getCardButton(Model\UserAction $action)
$country->name .= ' NO RELOAD';

$card = Card::addTo($app, ['useLabel' => true]);
$card->setModel($country);
$card->setEntity($country);
$card->addClickAction($country->getUserAction('edit'));
$card->addClickAction($country->getUserAction('delete'));
2 changes: 1 addition & 1 deletion demos/data-action/jsactions2.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$gl = GridLayout::addTo($app, ['rows' => 1, 'columns' => 2]);
$c = Card::addTo($gl, ['useLabel' => true], ['r1c1']);
$c->addContent(new Header(['Using country:']));
$c->setModel($entity, [$country->fieldName()->iso, $country->fieldName()->iso3, $country->fieldName()->phonecode]);
$c->setEntity($entity, [$country->fieldName()->iso, $country->fieldName()->iso3, $country->fieldName()->phonecode]);

$buttons = View::addTo($gl, ['ui' => 'vertical basic buttons'], ['r1c2']);

Expand Down
6 changes: 3 additions & 3 deletions demos/form-control/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// lookup with plus button
$model->hasOne('country2', ['model' => [Country::class], 'ui' => ['form' => ['plus' => true]]]);

$form->setModel($model->createEntity());
$form->setEntity($model->createEntity());

$form->addControl('country3', [
Form\Control\Lookup::class,
Expand Down Expand Up @@ -89,8 +89,8 @@
Header::addTo($app, ['Lookup input inside modal']);

$modal = Modal::addTo($app)->set(static function (View $p) {
$a = Form\Control\Lookup::addTo($p, ['placeholder' => 'Search country', 'label' => 'Country:']);
$a->setModel(new Country($p->getApp()->db));
$c = Form\Control\Lookup::addTo($p, ['placeholder' => 'Search country', 'label' => 'Country:']);
$c->setModel(new Country($p->getApp()->db));
});
Button::addTo($app, ['Open Lookup on a Modal window'])
->on('click', $modal->jsShow());
32 changes: 16 additions & 16 deletions demos/form/form-section.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
// -----------------------------------------------------------------------------

10000 $form = Form::addTo($app);
$form->setModel($model, []);
$form->setEntity($model, []);

$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);

Header::addTo($sublayout, ['Column Section in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$sublayout->setEntity($model, [$model->fieldName()->name]);

$colsLayout = $form->layout->addSubLayout([Form\Layout\Section\Columns::class]);

$c1 = $colsLayout->addColumn();
$c1->setModel($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);
$c1->setEntity($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);

$c2 = $colsLayout->addColumn();
$c2->setModel($model, [$model->fieldName()->numcode/* , $model->fieldName()->phonecode */]);
$c2->setEntity($model, [$model->fieldName()->numcode/* , $model->fieldName()->phonecode */]);

$form->addControl($model->fieldName()->phonecode);

Expand All @@ -59,20 +59,20 @@
// -----------------------------------------------------------------------------

$form = Form::addTo($app);
$form->setModel($model, []);
$form->setEntity($model, []);

$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);

Header::addTo($sublayout, ['Accordion Section in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$sublayout->setEntity($model, [$model->fieldName()->name]);

$accordionLayout = $form->layout->addSubLayout([Form\Layout\Section\Accordion::class]);

$a1 = $accordionLayout->addSection('Section 1');
$a1->setModel($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);
$a1->setEntity($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);

$a2 = $accordionLayout->addSection('Section 2');
$a2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);
$a2->setEntity($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($saveAndDumpValues);

Expand All @@ -81,20 +81,20 @@
// -----------------------------------------------------------------------------

$form = Form::addTo($app);
$form->setModel($model, []);
$form->setEntity($model, []);

$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);

Header::addTo($sublayout, ['Tabs in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$sublayout->setEntity($model, [$model->fieldName()->name]);

$tabsLayout = $form->layout->addSubLayout([Form\Layout\Section\Tabs::class]);

$tab1 = $tabsLayout->addTab('Tab 1');
$tab1->addGroup('In Group')->setModel($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);
$tab1->addGroup('In Group')->setEntity($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);

$tab2 = $tabsLayout->addTab('Tab 2');
$tab2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);
$tab2->setEntity($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($saveAndDumpValues);

Expand All @@ -105,21 +105,21 @@
Header::addTo($app, ['Color in form']);

$form = Form::addTo($app);
$form->setModel($model, []);
$form->setEntity($model, []);

$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class, 'ui' => 'segment red inverted'], false);

Header::addTo($sublayout, ['This section in Red', 'ui' => 'dividing header', 'element' => 'h2']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$sublayout->setEntity($model, [$model->fieldName()->name]);

$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class, 'ui' => 'segment teal inverted']);
$colsLayout = $sublayout->addSubLayout([Form\Layout\Section\Columns::class]);

$c1 = $colsLayout->addColumn();
$c1->setModel($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);
$c1->setEntity($model, [$model->fieldName()->iso, $model->fieldName()->iso3]);

$c2 = $colsLayout->addColumn();
$c2->setModel($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);
$c2->setEntity($model, [$model->fieldName()->numcode, $model->fieldName()->phonecode]);

$form->onSubmit($saveAndDumpValues);

Expand Down
4 changes: 2 additions & 2 deletions demos/form/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
$modelRegister = $modelRegister->createEntity();

$form = Form::addTo($tab, ['class.segment' => true]);
$form->setModel($modelRegister);
$form->setEntity($modelRegister);

$form->onSubmit(static function (Form $form) {
if ($form->entity->get('name') !== 'John') {
Expand All @@ -211,7 +211,7 @@
Header::addTo($tab, ['Shows example of grouping and multiple errors']);

$form = Form::addTo($tab, ['class.segment' => true]);
$form->setModel((new Model())->createEntity());
$form->setEntity((new Model())->createEntity());

$form->addHeader('Example fields added one-by-one');
$form->addControl('name');
Expand Down
4 changes: 2 additions & 2 deletions demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// $form = Form::addTo($app, ['class.segment' => true, 'buttonSave' => [null, 'Import', 'class.secondary' => true, 'iconRight' => 'list']]);
Label::addTo($form, ['Input new country information here', 'class.top attached' => true], ['AboveControls']);

$form->setModel((new Country($app->db))->createEntity(), []);
$form->setEntity((new Country($app->db))->createEntity(), []);

// form basic field group
$formAddress = $form->addGroup('Basic Country Information');
Expand Down Expand Up @@ -114,7 +114,7 @@ public function validate(?string $intent = null): array
});

$form = Form::addTo($app)->addClass('segment');
$form->setModel((new $personClass($app->db))->createEntity());
$form->setEntity((new $personClass($app->db))->createEntity());

$form->onSubmit(static function (Form $form) {
return new JsToast('Form saved!');
Expand Down
2 changes: 1 addition & 1 deletion demos/form/form3.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

$form = Form::addTo($seg, ['layout' => [Form\Layout\Columns::class]]);
$modelClass = ['country' => Country::class, 'file' => File::class][$app->tryGetRequestQueryParam('m')] ?? Stat::class;
$form->setModel((new $modelClass($app->db))->loadAny());
$form->setEntity((new $modelClass($app->db))->loadAny());

$form->onSubmit(static function (Form $form) {
$errors = [];
Expand Down
4 changes: 2 additions & 2 deletions demos/form/form5.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
$model = $model->createEntity();

$form = Form::addTo($cc->addColumn());
$form->setModel($model);
$form->setEntity($model);
$form->onSubmit($formSubmit);

// next form won't initialize default fields, but we'll add them individually
$form = Form::addTo($cc->addColumn());
$form->setModel($model, []);
$form->setEntity($model, []);

// adding that same field but with custom form control seed
$form->addControl('one', ['caption' => 'Caption0']);
Expand Down
6 changes: 3 additions & 3 deletions demos/form/html-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Header::addTo($right, ['Button on right']);

$form = Form::addTo($right, ['layout' => [Form\Layout::class, 'defaultTemplate' => __DIR__ . '/templates/form-button-right.html']]);
$form->setModel((new Flyers(new Persistence\Array_()))->createEntity());
$form->setEntity((new Flyers(new Persistence\Array_()))->createEntity());
$form->getControl('last_name')->hint = 'Please enter your last name.';

$left = View::addTo($gridLayout, [], ['r1c2']);
Expand All @@ -52,15 +52,15 @@
],
],
]);
$form->setModel((new Flyers(new Persistence\Array_()))->createEntity());
$form->setEntity((new Flyers(new Persistence\Array_()))->createEntity());
$form->getControl('last_name')->hint = 'Please enter your last name.';

// -----------------------------------------------------------------------------

$tab = $tabs->addTab('Custom layout class');

$form = Form::addTo($tab, ['layout' => [Form\Layout\Custom::class, 'defaultTemplate' => __DIR__ . '/templates/form-custom-layout.html']]);
$form->setModel((new Country($app->db))->loadAny());
$form->setEntity((new Country($app->db))->loadAny());

$form->onSubmit(static function (Form $form) {
return new JsToast('Saving is disabled');
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/card-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$stat = $stat->loadAny();

$c = Card::addTo($app);
$c->setModel($stat, [$stat->fieldName()->client_name, $stat->fieldName()->description]);
$c->setEntity($stat, [$stat->fieldName()->client_name, $stat->fieldName()->description]);

$c->addSection('Project: ', $stat, [$stat->fieldName()->start_date, $stat->fieldName()->finish_date], true);

Expand Down
4 changes: 2 additions & 2 deletions demos/interactive/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
$cardStat = Card::addTo($deck, ['useTable' => true]);
$cardStat->addContent(new Header(['Project Info']));
$stat = (new Stat($app->db))->loadAny();
$cardStat->setModel($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);
$cardStat->setEntity($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);

$button = $cardStat->addButton(new Button(['Email Client']));

$cardStat = Card::addTo($deck, ['useLabel' => true]);
$cardStat->addContent(new Header(['Project Info']));
$stat = (new Stat($app->db))->loadAny();
$cardStat->setModel($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);
$cardStat->setEntity($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);

$cardStat->addButton(new Button(['Email Client']));

Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/cardtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

Header::addTo($app, ['Card displays read-only data of a single record']);

CardTable::addTo($app)->setModel((new Stat($app->db))->loadAny());
CardTable::addTo($app)->setEntity((new Stat($app->db))->loadAny());
2 changes: 1 addition & 1 deletion demos/interactive/loader2.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
$countryLoader->set(static function (Loader $p) {
$country = new Country($p->getApp()->db);
$id = $p->getApp()->uiPersistence->typecastAttributeLoadField($country->getIdField(), $p->getApp()->getRequestQueryParam('id'));
Form::addTo($p)->setModel($country->load($id));
Form::addTo($p)->setEntity($country->load($id));
});
2 changes: 1 addition & 1 deletion demos/interactive/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
$modelRegister->addField('name', ['caption' => 'Please enter your name (John)']);

$form = Form::addTo($p, ['class.segment' => true]);
$form->setModel($modelRegister->createEntity());
$form->setEntity($modelRegister->createEntity());

$form->onSubmit(static function (Form $form) use ($nextAction, $session) {
if ($form->entity->get('name') !== 'John') {
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/scroll-grid-container.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

// demo for additional action buttons in Crud + JsPaginator
$g1->addModalAction(['icon' => 'cogs'], 'Details', static function (View $p, WrappedId $id) use ($g1) {
Card::addTo($p)->setModel($g1->model->load($id));
Card::addTo($p)->setEntity($g1->model->load($id));
});
$g1->addActionButton('red', static function (Jquery $js, WrappedId $id) use ($app, $m1) {
return $js->find('tr[data-id=' . $app->uiPersistence->typecastAttributeSaveField($m1->getIdField(), $id) . ']')->css('color', 'red');
Expand Down
Loading
Loading
0