Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
app
Commits
3476cc5c
Commit
3476cc5c
authored
Mar 05, 2020
by
Bertrand Gauthier
Browse files
Formulaire multipage : améliorations et refactorisations
parent
576dc5db
Pipeline
#6911
passed with stage
in 21 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/UnicaenApp/Controller/Plugin/MultipageFormPlugin.php
View file @
3476cc5c
...
...
@@ -214,9 +214,10 @@ class MultipageFormPlugin extends AbstractPlugin
$postData
=
$this
->
getPostDataForCurrentFieldset
();
$submitAction
=
$this
->
getSubmitAction
(
$postData
);
$currentFieldset
=
$this
->
getCurrentFieldset
();
$currentFieldset
->
populateValues
(
$this
->
getSessionValues
(
$currentFieldset
->
getName
()));
if
(
$submitAction
===
false
)
{
$currentFieldset
->
populateValues
(
$this
->
getSessionValues
(
$currentFieldset
->
getName
()));
return
[
'fieldset'
=>
$currentFieldset
,
'stepIndex'
=>
$this
->
getCurrentStepIndex
(),
...
...
@@ -651,8 +652,8 @@ class MultipageFormPlugin extends AbstractPlugin
{
$formData
=
[];
foreach
(
$this
->
fieldsetActions
as
$f
orm
Name
=>
$action
)
{
$formData
[
$f
orm
Name
]
=
$this
->
getSessionValues
(
$f
orm
Name
);
foreach
(
$this
->
fieldsetActions
as
$f
ieldset
Name
=>
$action
)
{
$formData
[
$f
ieldset
Name
]
=
$this
->
getSessionValues
(
$f
ieldset
Name
);
}
return
$formData
;
...
...
src/UnicaenApp/Form/MultipageForm.php
View file @
3476cc5c
...
...
@@ -478,7 +478,7 @@ abstract class MultipageForm extends Form
$valueToString
=
$value
;
if
(
$element
instanceof
SearchAndSelect
)
{
$valueToString
=
$value
[
'label'
]
??
$value
[
'id'
]
??
implode
(
' - '
,
$value
);
$valueToString
=
$value
[
'label'
]
??
$value
[
'id'
]
??
implode
(
' - '
,
(
array
)
$value
);
}
elseif
(
$element
instanceof
DoctrineObjectSelect
)
{
foreach
(
$element
->
getValueOptions
()
as
$key
=>
$optionArray
)
{
...
...
src/UnicaenApp/Form/View/Helper/MultipageFormFieldset.php
View file @
3476cc5c
...
...
@@ -84,29 +84,24 @@ class MultipageFormFieldset extends AbstractHelper
}
/**
* Génère le code HTML.
* Génère le code HTML
du fieldset à l'intérieur d'une balise "form"
.
*
* @return string
* @return string
*/
public
function
render
()
{
$fieldset
=
$this
->
fieldset
;
$template
=
'<form method="POST"><fieldset><legend>%s</legend>%s</fieldset></form>'
;
$template
=
<<<EOS
<form method="POST">
%s
</form>
EOS;
$label
=
$fieldset
->
getLabel
();
$step
=
"Étape"
;
$on
=
"sur"
;
if
((
$translator
=
$this
->
getTranslator
())
!==
null
)
{
$label
=
$translator
->
translate
(
$label
,
$this
->
getTranslatorTextDomain
());
$step
=
$translator
->
translate
(
$step
,
$this
->
getTranslatorTextDomain
());
$on
=
$translator
->
translate
(
$on
,
$this
->
getTranslatorTextDomain
());
}
$html
=
sprintf
(
$template
,
$label
,
$this
->
renderFieldset
(
$fieldset
));
$step
=
$this
->
translate
(
"Étape"
);
$on
=
$this
->
translate
(
"sur"
);
$html
=
sprintf
(
$template
,
$this
->
renderFieldset
(
$fieldset
));
if
(
$stepIndex
=
$this
->
view
->
get
(
'stepIndex'
))
{
$step
.
=
" "
.
$stepIndex
;
...
...
@@ -120,26 +115,50 @@ class MultipageFormFieldset extends AbstractHelper
}
/**
* Génère le code HTML du fieldset seul.
* Si un partial est fourni, il est utilisé.
*
* @param Fieldset $fieldset
* @return string
*/
private
function
renderFieldset
(
Fieldset
$fieldset
)
{
$html
=
''
;
if
(
$this
->
partial
)
{
// fieldset
$html
.
=
$this
->
view
->
partial
(
$this
->
partial
);
// navigation
$navElement
=
$this
->
getNavigationElement
();
$html
.
=
$this
->
view
->
multipageFormNav
(
$navElement
);
}
else
{
/** @var Element $element */
foreach
(
$fieldset
->
getIterator
()
as
$element
)
{
$html
.
=
$this
->
view
->
multipageFormRow
(
$element
);
}
return
$this
->
renderFieldsetPartial
();
}
$template
=
<<<EOS
<fieldset>
<legend>%s</legend>
%s
</fieldset>
EOS;
/** @var Element $element */
$html
=
''
;
foreach
(
$fieldset
->
getIterator
()
as
$element
)
{
$html
.
=
$this
->
view
->
multipageFormRow
(
$element
);
}
$legend
=
$this
->
translate
(
$fieldset
->
getLabel
());
return
sprintf
(
$template
,
$legend
,
$html
);
}
/**
* Génère le code HTML du fieldset à l'aide du partial fourni.
*
* @return string
*/
protected
function
renderFieldsetPartial
()
{
// fieldset
$html
=
$this
->
view
->
partial
(
$this
->
partial
);
// navigation
$navElement
=
$this
->
getNavigationElement
();
$html
.
=
$this
->
view
->
multipageFormNav
(
$navElement
);
return
$html
;
}
...
...
@@ -155,4 +174,17 @@ class MultipageFormFieldset extends AbstractHelper
return
$element
;
}
/**
* @param string $text
* @return string
*/
protected
function
translate
(
string
$text
)
{
if
((
$translator
=
$this
->
getTranslator
())
!==
null
)
{
return
$translator
->
translate
(
$text
,
$this
->
getTranslatorTextDomain
());
}
return
$text
;
}
}
\ No newline at end of file
src/UnicaenApp/Form/View/Helper/MultipageFormRow.php
View file @
3476cc5c
...
...
@@ -53,8 +53,11 @@ class MultipageFormRow extends FormRow
elseif
(
$element
instanceof
\
UnicaenApp\Form\Element\DateInfSup
)
{
return
$this
->
view
->
formRowDateInfSup
(
$element
);
}
return
parent
::
render
(
$element
);
return
'<div class="form-group">'
.
PHP_EOL
.
parent
::
render
(
$element
)
.
PHP_EOL
.
'</div>'
.
PHP_EOL
;
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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