Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
form-processor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mattwire
form-processor
Commits
62bc7244
Commit
62bc7244
authored
5 years ago
by
jaapjansma
Browse files
Options
Downloads
Patches
Plain Diff
Added Yes/No OptionList type
parent
f6a7c1af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
Civi/FormProcessor/Type/Factory.php
+1
-0
1 addition, 0 deletions
Civi/FormProcessor/Type/Factory.php
Civi/FormProcessor/Type/YesNoOptionListType.php
+91
-0
91 additions, 0 deletions
Civi/FormProcessor/Type/YesNoOptionListType.php
with
93 additions
and
0 deletions
CHANGELOG.md
+
1
−
0
View file @
62bc7244
...
...
@@ -10,6 +10,7 @@ Version 1.3
*
Added a type with a list of weekdays
*
Added field type for time
*
Added field type for formatted decimal numbers
*
Added field type for Yes/No values as an option list
Version 1.2
===========
...
...
This diff is collapsed.
Click to expand it.
Civi/FormProcessor/Type/Factory.php
+
1
−
0
View file @
62bc7244
...
...
@@ -25,6 +25,7 @@
$this
->
addType
(
new
DateType
(
E
::
ts
(
'Date'
)));
$this
->
addType
(
new
TimeType
(
E
::
ts
(
'Time'
)));
$this
->
addType
(
new
GenericType
(
'Boolean'
,
E
::
ts
(
'Yes/No'
)));
$this
->
addType
(
new
YesNoOptionListType
(
'YesNoOptionList'
,
E
::
ts
(
'Yes/No as Option List'
)));
$this
->
addType
(
new
OptionGroupType
(
'OptionGroup'
,
E
::
ts
(
'Option Group'
)));
$this
->
addType
(
new
CountryType
(
'Country'
,
E
::
ts
(
'Country'
)));
$this
->
addType
(
new
MailingGroupType
(
'MailingGroup'
,
E
::
ts
(
'Mailing Group'
)));
...
...
This diff is collapsed.
Click to expand it.
Civi/FormProcessor/Type/YesNoOptionListType.php
0 → 100644
+
91
−
0
View file @
62bc7244
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace
Civi\FormProcessor\Type
;
use
\Civi\FormProcessor\Config\Specification
;
use
\Civi\FormProcessor\Config\SpecificationBag
;
use
\Civi\FormProcessor\Type\AbstractType
;
use
\Civi\FormProcessor\Type\OptionListInterface
;
use
\CRM_FormProcessor_ExtensionUtil
as
E
;
class
YesNoOptionListType
extends
AbstractType
implements
OptionListInterface
{
private
$options
;
private
$optionsLoaded
=
false
;
/**
* Get the configuration specification
*
* @return SpecificationBag
*/
public
function
getConfigurationSpecification
()
{
return
new
SpecificationBag
(
array
(
new
Specification
(
'yes_label'
,
'String'
,
E
::
ts
(
'Yes label'
),
true
,
E
::
ts
(
'Yes'
),
null
,
null
,
false
),
new
Specification
(
'no_label'
,
'String'
,
E
::
ts
(
'No label'
),
true
,
E
::
ts
(
'No'
),
null
,
null
,
false
),
));
}
public
function
validateValue
(
$value
,
$allValues
=
array
())
{
return
true
;
}
/**
* Returns the type number from CRM_Utils_Type
*/
public
function
getCrmType
()
{
return
\CRM_Utils_Type
::
T_BOOLEAN
;
}
public
function
getOptions
(
$params
)
{
$this
->
loadOptions
();
return
$this
->
options
;
}
/**
* Normalize the input value.
*
* @param $value
*
* @return mixed
*/
public
function
normalizeValue
(
$value
)
{
return
$value
?
'1'
:
'0'
;
}
/**
* Denormalize the input value.
*
* @param $value
*
* @return mixed
*/
public
function
denormalizeValue
(
$value
)
{
return
$value
?
'1'
:
'0'
;
}
private
function
loadOptions
()
{
if
(
$this
->
optionsLoaded
)
{
return
;
}
$this
->
options
=
array
();
$yes_label
=
$this
->
configuration
->
get
(
'yes_label'
)
?
$this
->
configuration
->
get
(
'yes_label'
)
:
E
::
ts
(
'Yes'
);
$no_label
=
$this
->
configuration
->
get
(
'no_label'
)
?
$this
->
configuration
->
get
(
'no_label'
)
:
E
::
ts
(
'No'
);
$options
=
array
(
0
=>
$no_label
,
1
=>
$yes_label
);
$this
->
optionsLoaded
=
true
;
return
$options
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment