Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
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
Development
CiviCRM Core
Commits
0572f599
Unverified
Commit
0572f599
authored
3 years ago
by
Seamus Lee
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #21316 from colemanw/afformGet
Afform - Optimize Get by checking type
parents
ba484caf
2ca6eeda
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ext/afform/core/Civi/Api4/Action/Afform/Get.php
+25
-16
25 additions, 16 deletions
ext/afform/core/Civi/Api4/Action/Afform/Get.php
with
25 additions
and
16 deletions
ext/afform/core/Civi/Api4/Action/Afform/Get.php
+
25
−
16
View file @
0572f599
...
...
@@ -19,17 +19,22 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
$scanner
=
\Civi
::
service
(
'afform_scanner'
);
$getComputed
=
$this
->
_isFieldSelected
(
'has_local'
)
||
$this
->
_isFieldSelected
(
'has_base'
);
$getLayout
=
$this
->
_isFieldSelected
(
'layout'
);
$values
=
[];
// This helps optimize lookups by file/module/directive name
$
toGet
=
array_filter
([
$
getNames
=
array_filter
([
'name'
=>
$this
->
_itemsToGet
(
'name'
),
'module_name'
=>
$this
->
_itemsToGet
(
'module_name'
),
'directive_name'
=>
$this
->
_itemsToGet
(
'directive_name'
),
]);
$getTypes
=
$this
->
_itemsToGet
(
'type'
);
$names
=
$
toGet
[
'name'
]
??
array_keys
(
$scanner
->
findFilePaths
());
$names
=
$
getNames
[
'name'
]
??
array_keys
(
$scanner
->
findFilePaths
());
$values
=
$this
->
getAutoGenerated
(
$names
,
$toGet
,
$getLayout
);
// Get autogenerated blocks if type block is not excluded
if
(
!
$getTypes
||
in_array
(
'block'
,
$getTypes
,
TRUE
))
{
$values
=
$this
->
getAutoGenerated
(
$names
,
$getNames
,
$getLayout
);
}
if
(
$this
->
checkPermissions
)
{
$names
=
array_filter
(
$names
,
[
$this
,
'checkPermission'
]);
...
...
@@ -41,13 +46,18 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
'module_name'
=>
_afform_angular_module_name
(
$name
,
'camel'
),
'directive_name'
=>
_afform_angular_module_name
(
$name
,
'dash'
),
];
foreach
(
$toGet
as
$key
=>
$get
)
{
if
(
!
in_array
(
$info
[
$key
],
$get
))
{
// Skip if afform does not match requested name
foreach
(
$getNames
as
$key
=>
$names
)
{
if
(
!
in_array
(
$info
[
$key
],
$names
))
{
continue
2
;
}
}
$record
=
$scanner
->
getMeta
(
$name
);
if
(
!
$record
&&
!
isset
(
$values
[
$name
]))
{
// Skip if afform does not exist or is not of requested type(s)
if
(
(
!
$record
&&
!
isset
(
$values
[
$name
]))
||
(
$getTypes
&&
!
in_array
(
$record
[
'type'
],
$getTypes
,
TRUE
))
)
{
continue
;
}
$values
[
$name
]
=
array_merge
(
$values
[
$name
]
??
[],
$record
??
[],
$info
);
...
...
@@ -81,28 +91,27 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
/**
* Generates afform blocks from custom field sets.
*
* @param $names
* @param
$toGet
* @param $getLayout
* @param
array
$names
* @param
array $getNames
* @param
bool
$getLayout
* @return array
* @throws \API_Exception
*/
protected
function
getAutoGenerated
(
&
$names
,
$
toGet
,
$getLayout
)
{
protected
function
getAutoGenerated
(
&
$names
,
$
getNames
,
$getLayout
)
{
$values
=
$groupNames
=
[];
foreach
(
$
toGet
[
'name'
]
??
[]
as
$name
)
{
foreach
(
$
getNames
[
'name'
]
??
[]
as
$name
)
{
if
(
strpos
(
$name
,
'afblockCustom_'
)
===
0
&&
strlen
(
$name
)
>
13
)
{
$groupNames
[]
=
substr
(
$name
,
14
);
}
}
// Early return if this api call is fetching afforms by name and those names are not custom-related
if
((
!
empty
(
$
toGet
[
'name'
])
&&
!
$groupNames
)
||
(
!
empty
(
$
toGet
[
'module_name'
])
&&
!
strstr
(
implode
(
' '
,
$
toGet
[
'module_name'
]),
'afblockCustom'
))
||
(
!
empty
(
$
toGet
[
'directive_name'
])
&&
!
strstr
(
implode
(
' '
,
$
toGet
[
'directive_name'
]),
'afblock-custom'
))
if
((
!
empty
(
$
getNames
[
'name'
])
&&
!
$groupNames
)
||
(
!
empty
(
$
getNames
[
'module_name'
])
&&
!
strstr
(
implode
(
' '
,
$
getNames
[
'module_name'
]),
'afblockCustom'
))
||
(
!
empty
(
$
getNames
[
'directive_name'
])
&&
!
strstr
(
implode
(
' '
,
$
getNames
[
'directive_name'
]),
'afblock-custom'
))
)
{
return
$values
;
}
$customApi
=
CustomGroup
::
get
()
->
setCheckPermissions
(
FALSE
)
$customApi
=
CustomGroup
::
get
(
FALSE
)
->
addSelect
(
'name'
,
'title'
,
'help_pre'
,
'help_post'
,
'extends'
,
'max_multiple'
)
->
addWhere
(
'is_multiple'
,
'='
,
1
)
->
addWhere
(
'is_active'
,
'='
,
1
);
...
...
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