Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fsnet
form-processor
Commits
63e452b0
Commit
63e452b0
authored
Aug 08, 2018
by
jaapjansma
Browse files
improved option group type.
parent
969589e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Civi/FormProcessor/Type/OptionGroupType.php
View file @
63e452b0
...
...
@@ -16,6 +16,14 @@ use \CRM_FormProcessor_ExtensionUtil as E;
class
OptionGroupType
extends
AbstractType
implements
OptionListInterface
{
private
$options
;
private
$normalizedOptions
;
private
$denormalizedOptions
;
private
$optionsLoaded
=
false
;
/**
* Get the configuration specification
*
...
...
@@ -28,6 +36,7 @@ class OptionGroupType extends AbstractType implements OptionListInterface {
$optionsGroups
[
$optionGroup
[
'name'
]]
=
$optionGroup
[
'title'
];
}
return
new
SpecificationBag
(
array
(
new
Specification
(
'use_label_as_value'
,
'Boolean'
,
E
::
ts
(
'Use label as value'
),
true
,
0
,
null
,
array
(
0
=>
E
::
ts
(
'No'
),
1
=>
E
::
ts
(
'Yes'
))),
new
Specification
(
'option_group_name'
,
'Integer'
,
E
::
ts
(
'Option group'
),
true
,
null
,
null
,
$optionsGroups
,
false
),
));
}
...
...
@@ -37,8 +46,8 @@ class OptionGroupType extends AbstractType implements OptionListInterface {
return
false
;
}
$
countrie
s
=
$this
->
getOptions
();
if
(
!
isset
(
$
countrie
s
[
$value
]))
{
$
option
s
=
$this
->
getOptions
();
if
(
!
isset
(
$
option
s
[
$value
]))
{
return
false
;
}
...
...
@@ -53,19 +62,66 @@ class OptionGroupType extends AbstractType implements OptionListInterface {
}
public
function
getOptions
(
$params
)
{
$this
->
loadOptions
();
return
$this
->
options
;
}
/**
* Normalize the input value.
*
* @param $value
*
* @return mixed
*/
public
function
normalizeValue
(
$value
)
{
$this
->
loadOptions
();
return
$this
->
normalizedOptions
[
$value
];
}
/**
* Denormalize the input value.
*
* @param $value
*
* @return mixed
*/
public
function
denormalizeValue
(
$value
)
{
$this
->
loadOptions
();
return
$this
->
denormalizedOptions
[
$value
];
}
private
function
loadOptions
()
{
if
(
$this
->
optionsLoaded
)
{
return
;
}
$this
->
options
=
array
();
$this
->
normalizedOptions
=
array
();
$this
->
denormalizedOptions
=
array
();
$use_label
=
$this
->
configuration
->
get
(
'use_label_as_value'
)
?
true
:
false
;
$option_group_name
=
$this
->
configuration
->
get
(
'option_group_name'
);
if
(
!
$option_group_name
)
{
return
array
()
;
return
;
}
$optionsApi
=
civicrm_api3
(
'OptionValue'
,
'get'
,
[
'
name
'
=>
$option_group_name
,
'
option_group_id
'
=>
$option_group_name
,
'is_active'
=>
1
,
'options'
=>
[
'limit'
=>
0
]
]);
$options
=
array
();
foreach
(
$optionsApi
[
'values'
]
as
$optionValue
)
{
$options
[
$optionValue
[
'value'
]]
=
$optionValue
[
'label'
];
$value
=
$optionValue
[
'value'
];
if
(
$use_label
)
{
$value
=
$optionValue
[
'label'
];
}
$this
->
options
[
$value
]
=
$optionValue
[
'label'
];
$this
->
normalizedOptions
[
$value
]
=
$optionValue
[
'value'
];
$this
->
denormalizedOptions
[
$optionValue
[
'value'
]]
=
$value
;
}
$this
->
optionsLoaded
=
true
;
return
$options
;
}
...
...
info.xml
View file @
63e452b0
...
...
@@ -2,7 +2,9 @@
<extension
key=
"form-processor"
type=
"module"
>
<file>
form_processor
</file>
<name>
Form Processor
</name>
<description>
The form processor gives you the ability to define busines logic in de the user interface to handle form submissions.
</description>
<description>
The form processor gives you the ability to define busines logic in de the user interface to handle form submissions.
You also need the action-provider extension from https://lab.civicrm.org/extensions/action-provider
</description>
<license>
AGPL-3.0
</license>
<maintainer>
<author>
Jaap Jansma
</author>
...
...
@@ -12,14 +14,19 @@
<url
desc=
"Main Extension Page"
>
https://lab.civicrm.org/jaapjansma/form-procesor
</url>
<url
desc=
"Documentation"
>
https://lab.civicrm.org/jaapjansma/form-procesor/README.md
</url>
<url
desc=
"Licensing"
>
http://www.gnu.org/licenses/agpl-3.0.html
</url>
<url
desc=
"Action-Provider Extension"
>
https://lab.civicrm.org/extensions/action-provider
</url>
</urls>
<releaseDate>
2018-0
2
-08
</releaseDate>
<releaseDate>
2018-0
8
-08
</releaseDate>
<version>
1.0
</version>
<develStage>
alpha
</develStage>
<compatibility>
<ver>
4.7
</ver>
<ver>
5.0
</ver>
<ver>
5.1
</ver>
<ver>
5.2
</ver>
<ver>
5.3
</ver>
<ver>
5.4
</ver>
</compatibility>
<comments>
This is a module in prototype stage
</comments>
<classloader>
<psr4
prefix=
"Civi\"
path=
"Civi"
/>
</classloader>
...
...
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