$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']);
'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);
/**
* 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);