Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
deck-web
Composite Form
Commits
2f0ce1e7
Commit
2f0ce1e7
authored
7 months ago
by
Ильнур Табулдин
☠
Browse files
Options
Download
Email Patches
Plain Diff
Скорректирован принцип сохранения очередности. Добавлен тип ответа в getErrors()
parent
ad36e832
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Form.php
+18
-10
src/Form.php
src/FormContainer.php
+3
-7
src/FormContainer.php
src/ResponseTypeEnum.php
+9
-0
src/ResponseTypeEnum.php
with
30 additions
and
17 deletions
+30
-17
src/Form.php
100644 → 100755
+
18
-
10
View file @
2f0ce1e7
...
...
@@ -2,19 +2,15 @@
namespace
deck\form
;
use
app\vendor\deck\form\src\ResponseTypeEnum
;
use
ReflectionProperty
;
use
yii\base\Model
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
abstract
class
Form
extends
Model
{
/**
* Для контейнера форм, необходимо ли оставить порядок для форм, которые пришли
* @var bool $keepOrder
*/
protected
$keepOrder
=
false
;
public
function
load
(
$data
,
$formName
=
null
):
bool
public
function
load
(
$data
,
$formName
=
null
,
bool
$keepOrder
=
false
):
bool
{
$formData
=
$data
;
foreach
(
$this
->
getInternalForms
()
as
$form
)
{
...
...
@@ -58,7 +54,7 @@ abstract class Form extends Model
if
(
count
(
array_filter
(
array_keys
(
$data
[
$name
]),
'is_string'
))
===
0
)
{
$this
->
$name
=
[];
foreach
(
$data
[
$name
]
as
$key
=>
$ignored
)
{
if
(
$
this
->
keepOrder
)
{
if
(
$keepOrder
)
{
$this
->
$name
[
$key
]
=
new
$form
->
className
();
}
else
{
$this
->
$name
[]
=
new
$form
->
className
();
...
...
@@ -141,7 +137,7 @@ abstract class Form extends Model
return
false
;
}
public
function
getErrors
(
$attribute
=
null
):
array
public
function
getErrors
(
$attribute
=
null
,
string
$responseType
=
ResponseTypeEnum
::
Rest
):
array
{
$result
=
parent
::
getErrors
(
$attribute
);
foreach
(
$this
->
getInternalForms
()
as
$form
)
{
...
...
@@ -159,7 +155,19 @@ abstract class Form extends Model
}
if
(
$attribute
===
null
)
{
foreach
(
$errors
as
$error
)
{
$result
[
$errorAttr
][]
=
$error
;
switch
(
$responseType
)
{
case
ResponseTypeEnum
::
Rest
:
{
$result
[
$errorAttr
][]
=
$error
;
break
;
}
case
ResponseTypeEnum
::
ActiveForm
:
{
$result
[
Html
::
getInputId
(
$item
,
"[
$i
]"
.
$attr
)][]
=
$error
;
break
;
}
}
}
}
elseif
(
$errorAttr
===
$attribute
)
{
foreach
(
$errors
as
$error
)
{
...
...
This diff is collapsed.
Click to expand it.
src/FormContainer.php
+
3
-
7
View file @
2f0ce1e7
...
...
@@ -4,18 +4,14 @@ namespace deck\form;
abstract
class
FormContainer
extends
Form
{
/** @var string $internalForms */
protected
$internalForms
;
public
$forms
=
[];
public
function
__construct
(
bool
$keepOrder
=
false
,
array
$config
=
[])
{
$this
->
keepOrder
=
$keepOrder
;
}
public
function
load
(
$data
,
$formName
=
null
):
bool
public
function
load
(
$data
,
$formName
=
null
,
bool
$keepOrder
=
false
):
bool
{
$data
=
[
'forms'
=>
$data
];
return
parent
::
load
(
$data
,
'forms'
);
return
parent
::
load
(
$data
,
'forms'
,
$keepOrder
);
}
protected
function
internalForms
():
array
...
...
This diff is collapsed.
Click to expand it.
src/ResponseTypeEnum.php
0 → 100644
+
9
-
0
View file @
2f0ce1e7
<?php
namespace
app\vendor\deck\form\src
;
class
ResponseTypeEnum
{
const
Rest
=
'rest'
;
const
ActiveForm
=
'activeForm'
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help