Commit 326574df authored by colemanw's avatar colemanw
Browse files

Merge branch 'name' into 'master'

Api - output module_name & directive_name

See merge request extensions/afform!25
parents 1e76a585 e63eabff
......@@ -19,17 +19,33 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
$getComputed = $this->_isFieldSelected('has_local') || $this->_isFieldSelected('has_base');
$getLayout = $this->_isFieldSelected('layout');
$toGet = $this->_itemsToGet('name');
$names = $toGet ?? array_keys($scanner->findFilePaths());
// This helps optimize lookups by file/module/directive name
$toGet = array_filter([
'name' => $this->_itemsToGet('name'),
'module_name' => $this->_itemsToGet('module_name'),
'directive_name' => $this->_itemsToGet('directive_name'),
]);
$names = $toGet['name'] ?? array_keys($scanner->findFilePaths());
$values = $this->getAutoGenerated($names, $toGet, $getLayout);
foreach ($names as $name) {
$info = [
'name' => $name,
'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)) {
continue;
}
}
$record = $scanner->getMeta($name);
if (!$record && !isset($values[$name])) {
continue;
}
$values[$name] = array_merge($values[$name] ?? [], $record ?? []);
$values[$name] = array_merge($values[$name] ?? [], $record ?? [], $info);
if ($getComputed) {
$scanner->addComputedFields($values[$name]);
}
......@@ -58,12 +74,16 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
*/
protected function getAutoGenerated(&$names, $toGet, $getLayout) {
$values = $groupNames = [];
foreach ($toGet ?? [] as $name) {
if (strpos($name, 'blockCustom_') === 0 && strlen($name) > 12) {
$groupNames[] = substr($name, 12);
foreach ($toGet['name'] ?? [] as $name) {
if (strpos($name, 'afjoinCustom_') === 0 && strlen($name) > 13) {
$groupNames[] = substr($name, 13);
}
}
if ($toGet && !$groupNames) {
if (
(!empty($toGet['name']) && !$groupNames)
|| (!empty($toGet['module_name']) && !strstr(implode(' ', $toGet['module_name']), 'afjoinCustom'))
|| (!empty($toGet['directive_name']) && !strstr(implode(' ', $toGet['directive_name']), 'afjoin-custom'))
) {
return $values;
}
$customApi = CustomGroup::get()
......@@ -85,7 +105,7 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
);
}
foreach ($customApi->execute() as $custom) {
$name = 'blockCustom_' . $custom['name'];
$name = 'afjoinCustom_' . $custom['name'];
if (!in_array($name, $names)) {
$names[] = $name;
}
......
......@@ -7,7 +7,7 @@ use Civi\Api4\Generic\BasicBatchAction;
use Civi\Api4\Generic\BasicGetFieldsAction;
/**
* Class Afform
* User-configurable forms
* @package Civi\Api4
*/
class Afform extends AbstractEntity {
......@@ -126,6 +126,12 @@ class Afform extends AbstractEntity {
];
if ($self->getAction() === 'get') {
$fields[] = [
'name' => 'module_name',
];
$fields[] = [
'name' => 'directive_name',
];
$fields[] = [
'name' => 'has_local',
];
......
......@@ -206,7 +206,7 @@ function afform_gui_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
}
}
// Load fields from entity joins
// Load fields from afform blocks with joins
$blockData = \Civi\Api4\Afform::get()
->setCheckPermissions(FALSE)
->addWhere('join', 'IS NOT NULL')
......@@ -221,7 +221,7 @@ function afform_gui_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
}
}
// Todo: scan for other elements
// Todo: add method for extensions to define other elements
$data['elements'] = [
'container' => [
'title' => ts('Container'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment