Skip to content

Commit 3c4e579

Browse files
authored
use getFields() instead of elements property (#876)
* use getFields() * Apply fixes from StyleCI * nicer * Apply fixes from StyleCI
1 parent c9e85c0 commit 3c4e579

35 files changed

+256
-253
lines changed

demos/card-action.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
$client = $stats->ref('client_country_iso')->loadAny();
2525
$notify = $client->addAction('Notify',
2626
['args' => [
27-
'note'=> ['type'=>'string', 'required'=>true],
27+
'note'=> ['type'=>'string', 'required'=>true],
2828
],
29-
'callback' => function ($m) {
30-
return 'Note to client is sent.';
31-
},
32-
]);
29+
'callback' => function ($m) {
30+
return 'Note to client is sent.';
31+
},
32+
]);
3333

3434
$c->addSection('Client Country:', $client, ['iso', 'numcode', 'phonecode'], true);
3535

demos/card-deck.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
'scope' => 'none',
3535
'ui' => ['button' => ['Request Info', 'ui' => 'button primary', 'icon' => 'mail']],
36-
]);
36+
]);
3737

3838
$info_action->args = [
3939
'email' => ['type'=>'email', 'required'=>true, 'caption' => 'Please let us know your email address:'],

demos/database.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
}
1010
} catch (PDOException $e) {
1111
throw new \atk4\ui\Exception([
12-
'This demo requires access to the database. See "demos/database.php"',
13-
], null, $e);
12+
'This demo requires access to the database. See "demos/database.php"',
13+
], null, $e);
1414
}
1515

1616
$app->db = $db;
@@ -159,10 +159,10 @@ public function importFromFilesystem($path)
159159
$this->unload();
160160

161161
$this->save([
162-
'name' => $fileinfo->getFilename(),
163-
'is_folder' => $fileinfo->isDir(),
164-
'type' => pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION),
165-
]);
162+
'name' => $fileinfo->getFilename(),
163+
'is_folder' => $fileinfo->isDir(),
164+
'type' => pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION),
165+
]);
166166

167167
if ($fileinfo->isDir()) {
168168
$this->ref('SubFolder')->importFromFilesystem($path.'/'.$fileinfo->getFilename());

demos/dropdown-plus.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
'model' => new Country($db),
2020
'renderRowFunction' => function ($row) {
2121
return [
22-
'value' => $row->id,
23-
'title' => $row->getTitle().' ('.$row->get('iso3').')',
22+
'value' => $row->id,
23+
'title' => $row->getTitle().' ('.$row->get('iso3').')',
2424
];
2525
},
2626
]);
@@ -32,9 +32,9 @@
3232
'model' => new File($db),
3333
'renderRowFunction' => function ($row) {
3434
return [
35-
'value' => $row->id,
36-
'title' => $row->getTitle(),
37-
'icon' => $row->get('is_folder') ? 'folder' : 'file',
35+
'value' => $row->id,
36+
'title' => $row->getTitle(),
37+
'icon' => $row->get('is_folder') ? 'folder' : 'file',
3838
];
3939
},
4040
]);

demos/field.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
])]));
8181

8282
$app->add(new \atk4\ui\FormField\Line(['action' => new \atk4\ui\Button([
83-
'icon' => 'search',
83+
'icon' => 'search',
8484
])]));
8585

8686
$app->add(new \atk4\ui\Header(['Modifiers', 'size' => 2]));

demos/field2.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
$g = $f->addGroup('DropDown');
2929
$values = [
30-
'tag' => ['Tag', 'icon' => 'tag icon'],
31-
'globe' => ['Globe', 'icon' => 'globe icon'],
32-
'registered' => ['Registered', 'icon' => 'registered icon'],
33-
'file' => ['File', 'icon' => 'file icon'],
34-
];
30+
'tag' => ['Tag', 'icon' => 'tag icon'],
31+
'globe' => ['Globe', 'icon' => 'globe icon'],
32+
'registered' => ['Registered', 'icon' => 'registered icon'],
33+
'file' => ['File', 'icon' => 'file icon'],
34+
];
3535
$g->addField('d_norm', [new \atk4\ui\FormField\DropDown(['values' => $values]), 'width'=>'three'])->set('globe');
3636
$g->addField('d_read', [new \atk4\ui\FormField\DropDown(['values' => $values]), 'readonly' => true, 'width'=>'three'])->set('globe'); // allows to change value
3737
$g->addField('d_disb', [new \atk4\ui\FormField\DropDown(['values' => $values]), 'disabled' => true, 'width'=>'three'])->set('globe'); // css disabled, but can focus with Tab and change value
@@ -172,21 +172,21 @@
172172

173173
$g = $form->addGroup('DropDown');
174174
$d1 = $g->addField('d1', new \atk4\ui\FormField\DropDown(['values' => [
175-
'tag' => ['Tag', 'icon' => 'tag icon'],
176-
'globe' => ['Globe', 'icon' => 'globe icon'],
177-
'registered' => ['Registered', 'icon' => 'registered icon'],
178-
'file' => ['File', 'icon' => 'file icon'],
179-
],
175+
'tag' => ['Tag', 'icon' => 'tag icon'],
176+
'globe' => ['Globe', 'icon' => 'globe icon'],
177+
'registered' => ['Registered', 'icon' => 'registered icon'],
178+
'file' => ['File', 'icon' => 'file icon'],
179+
],
180180
]));
181181
$d1->onChange('console.log("d1 changed")');
182182

183183
$g = $form->addGroup('Radio');
184184
$r1 = $g->addField('r1', new \atk4\ui\FormField\Radio(['values' => [
185-
'Tag',
186-
'Globe',
187-
'Registered',
188-
'File',
189-
],
185+
'Tag',
186+
'Globe',
187+
'Registered',
188+
'File',
189+
],
190190
]));
191191
$r1->onChange('console.log("r1 changed")');
192192

demos/form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
$f->onSubmit(function ($f) {
198198
$errors = [];
199199

200-
foreach ($f->model->elements as $name => $ff) {
200+
foreach ($f->model->getFields() as $name => $ff) {
201201
if ($name == 'id') {
202202
continue;
203203
}

demos/grid_action.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$g->table->jsRemoveRow($model->get('id')),
3333
];
3434
},
35-
]
35+
]
3636
);
3737

3838
$del_action = $country->addAction('delete', [

demos/jsactionsgrid.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@
8383
$g->addActionMenuItem($model_header);
8484
$g->addActionMenuItems(
8585
[
86-
'callback',
87-
'preview',
88-
'disabled_action',
89-
'edit_argument',
90-
'edit_argument_prev',
91-
'edit_iso',
92-
'Ouch',
93-
'confirm',
94-
]
86+
'callback',
87+
'preview',
88+
'disabled_action',
89+
'edit_argument',
90+
'edit_argument_prev',
91+
'edit_iso',
92+
'Ouch',
93+
'confirm',
94+
]
9595
);
9696

9797
$special_item = $app->factory('View', ['id' => false, 'class' => ['item'], 'content' => 'Multi Step'], 'atk4\ui');

demos/tablecolumns.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function init()
6767
$this->addField('interests', [
6868
'type' => 'string',
6969
'ui' => [
70-
'table' => [
71-
'Labels',
72-
],
70+
'table' => [
71+
'Labels',
72+
],
7373
],
7474
]);
7575

demos/toast.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
$btn = $app->add('Button')->set('With progress bar');
8282
$btn->on('click', new \atk4\ui\jsToast([
83-
'title' => 'Awesome',
84-
'message' => 'See how long I will last',
85-
'showProgress' => 'bottom',
83+
'title' => 'Awesome',
84+
'message' => 'See how long I will last',
85+
'showProgress' => 'bottom',
8686
]));

src/ActionExecutor/Basic.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Basic extends \atk4\ui\View implements Interface_
6262
*
6363
* @param \atk4\data\UserAction\Generic $action
6464
*/
65-
public function setAction(\atk4\data\UserAction\Generic $action) : void
65+
public function setAction(\atk4\data\UserAction\Generic $action): void
6666
{
6767
$this->action = $action;
6868
}

src/ActionExecutor/Form.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ public function initPreview()
5454
protected function getModelFields(Model $model)
5555
{
5656
$fields = [];
57-
foreach ($model->elements as $f) {
58-
if (!$f instanceof Field) {
59-
continue;
60-
}
61-
57+
foreach ($model->getFields() as $f) {
6258
if ($f->isEditable() || $f->isVisible()) {
6359
$fields[] = $f->short_name;
6460
}

src/ActionExecutor/UserAction.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function init()
112112
*
113113
* @return UserAction
114114
*/
115-
public function setAction(Generic $action) :View
115+
public function setAction(Generic $action): View
116116
{
117117
$this->action = $action;
118118

@@ -317,9 +317,9 @@ protected function doPreview(View $modal)
317317

318318
if ($prev = $this->getPreviousStep($this->step)) {
319319
$chain = $this->loader->jsload([
320-
'step' => $prev,
321-
$this->name => $this->action->owner->get('id'),
322-
], ['method' => 'post'], $this->loader->name);
320+
'step' => $prev,
321+
$this->name => $this->action->owner->get('id'),
322+
], ['method' => 'post'], $this->loader->name);
323323

324324
$modal->js(true, $this->prevStepBtn->js()->on('click', new jsFunction([$chain])));
325325
}
@@ -409,7 +409,7 @@ protected function jsGetExecute($obj, $id)
409409
*
410410
* @return array|null
411411
*/
412-
protected function getSteps(Generic $action) :?array
412+
protected function getSteps(Generic $action): ?array
413413
{
414414
$steps = null;
415415
if ($action->args) {
@@ -432,7 +432,7 @@ protected function getSteps(Generic $action) :?array
432432
*
433433
* @return string|null
434434
*/
435-
protected function getNextStep(string $step) :?string
435+
protected function getNextStep(string $step): ?string
436436
{
437437
$next = null;
438438
if (!$this->isLastStep($step)) {
@@ -454,7 +454,7 @@ protected function getNextStep(string $step) :?string
454454
*
455455
* @return string|null
456456
*/
457-
protected function getPreviousStep(string $step) :?string
457+
protected function getPreviousStep(string $step): ?string
458458
{
459459
$prev = null;
460460

@@ -477,7 +477,7 @@ protected function getPreviousStep(string $step) :?string
477477
*
478478
* @return bool
479479
*/
480-
protected function isLastStep(string $step) :bool
480+
protected function isLastStep(string $step): bool
481481
{
482482
$isLast = false;
483483
$step_count = count($this->steps);
@@ -498,7 +498,7 @@ protected function isLastStep(string $step) :bool
498498
*
499499
* @return bool
500500
*/
501-
protected function isFirstStep(string $step) :bool
501+
protected function isFirstStep(string $step): bool
502502
{
503503
return $step === $this->steps[0];
504504
}
@@ -514,7 +514,7 @@ protected function isFirstStep(string $step) :bool
514514
*
515515
* @return Form
516516
*/
517-
protected function setFormField(Form $form, array $fields, string $step) :Form
517+
protected function setFormField(Form $form, array $fields, string $step): Form
518518
{
519519
foreach ($fields as $k => $val) {
520520
$form->getField($k)->set($val);
@@ -545,9 +545,9 @@ protected function jsStepSubmit(string $step)
545545
$js = [
546546
$this->loader->jsAddStoreData($this->actionData, true),
547547
$this->loader->jsload([
548-
'step' => $this->getNextStep($step),
549-
$this->name => $this->action->owner->get('id'),
550-
], ['method' => 'post'], $this->loader->name),
548+
'step' => $this->getNextStep($step),
549+
$this->name => $this->action->owner->get('id'),
550+
], ['method' => 'post'], $this->loader->name),
551551
];
552552
}
553553

@@ -595,7 +595,7 @@ protected function jsSetBtnState(View $view, string $step)
595595
*
596596
* @return jsExpressionable
597597
*/
598-
protected function jsSetNextState(string $step) :jsExpressionable
598+
protected function jsSetNextState(string $step): jsExpressionable
599599
{
600600
if ($this->isLastStep($step)) {
601601
return $this->nextStepBtn->js(true)->hide();
@@ -611,7 +611,7 @@ protected function jsSetNextState(string $step) :jsExpressionable
611611
*
612612
* @return jsExpressionable
613613
*/
614-
protected function jsSetPrevState(string $step) :jsExpressionable
614+
protected function jsSetPrevState(string $step): jsExpressionable
615615
{
616616
if ($this->isFirstStep($step)) {
617617
return $this->prevStepBtn->js(true)->hide();
@@ -627,7 +627,7 @@ protected function jsSetPrevState(string $step) :jsExpressionable
627627
*
628628
* @return jsExpressionable
629629
*/
630-
protected function jsSetExecState(string $step) :jsExpressionable
630+
protected function jsSetExecState(string $step): jsExpressionable
631631
{
632632
if ($this->isLastStep($step)) {
633633
return $this->execActionBtn->js(true)->show();
@@ -669,9 +669,9 @@ protected function jsSetPrevHandler(View $view, string $step)
669669
{
670670
if ($prev = $this->getPreviousStep($step)) {
671671
$chain = $this->loader->jsload([
672-
'step' => $prev,
673-
$this->name => $this->action->owner->get('id'),
674-
], ['method' => 'post'], $this->loader->name);
672+
'step' => $prev,
673+
$this->name => $this->action->owner->get('id'),
674+
], ['method' => 'post'], $this->loader->name);
675675

676676
$view->js(true, $this->prevStepBtn->js()->on('click', new jsFunction([$chain])));
677677
}
@@ -686,7 +686,7 @@ protected function jsSetPrevHandler(View $view, string $step)
686686
*
687687
* @return Form |null
688688
*/
689-
protected function addFormTo(View $view) :Form
689+
protected function addFormTo(View $view): Form
690690
{
691691
$f = $view->add($this->form);
692692
$f->buttonSave->destroy();
@@ -732,7 +732,7 @@ protected function getActionPreview()
732732
*
733733
* @return array
734734
*/
735-
private function _getActionArgs(array $data) :array
735+
private function _getActionArgs(array $data): array
736736
{
737737
$args = [];
738738

src/ActionExecutor/jsEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function jsRender()
152152
'uri' => $this->cb->getJSURL(),
153153
'uri_options' => array_merge(['atk_event_id' => $this->modelId], $this->args),
154154
'apiConfig' => ['stateContext' => $this->stateContext],
155-
]);
155+
]);
156156

157157
return $final->jsRender();
158158
}

src/App.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public function addStyle($style)
428428
*
429429
* @return string|null
430430
*/
431-
public function normalizeClassNameApp($name, $prefix = '') : ?string
431+
public function normalizeClassNameApp($name, $prefix = ''): ?string
432432
{
433433
//return '\\'.__NAMESPACE__.'\\'.$name;
434434
return null;
@@ -678,7 +678,7 @@ public function url($page = [], $needRequestUri = false, $extra_args = [])
678678
*
679679
* @return string|null
680680
*/
681-
public function stickyGet($name) :?string
681+
public function stickyGet($name): ?string
682682
{
683683
if (isset($_GET[$name])) {
684684
$this->sticky_get_arguments[$name] = $_GET[$name];

0 commit comments

Comments
 (0)