Commit d5d10b3d authored by colemanw's avatar colemanw
Browse files

Use api to get directive/module names

parent 326574df
......@@ -6,23 +6,27 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
public function run() {
list ($pagePath, $pageArgs) = func_get_args();
$module = _afform_angular_module_name($pageArgs['afform']);
$this->set('afModule', $module);
$afform = civicrm_api4('Afform', 'get', [
'checkPermissions' => FALSE,
'where' => [['name', '=', $pageArgs['afform']]],
'select' => ['title', 'module_name', 'directive_name'],
], 0);
$this->set('afModule', $afform['module_name']);
$loader = new \Civi\Angular\AngularLoader();
$loader->setModules([$module, 'afformStandalone']);
$loader->setModules([$afform['module_name'], 'afformStandalone']);
$loader->setPageName(implode('/', $pagePath));
$loader->getRes()->addSetting([
'afform' => [
'open' => _afform_angular_module_name($pageArgs['afform'], 'dash'),
'open' => $afform['directive_name'],
],
]);
$loader->load();
$afform = civicrm_api4('Afform', 'get', ['checkPermissions' => FALSE, 'where' => [['name', '=', $module]], 'select' => ['title']]);
if (!empty($afform[0]['title'])) {
$title = strip_tags($afform[0]['title']);
if (!empty($afform['title'])) {
$title = strip_tags($afform['title']);
CRM_Utils_System::setTitle($title);
CRM_Utils_System::appendBreadCrumb([['title' => $title, 'url' => CRM_Utils_System::url(implode('/', $pagePath), NULL, FALSE, '/')]]);
}
......
......@@ -26,12 +26,11 @@ class FormDataModel {
public function __construct($layout) {
$root = AHQ::makeRoot($layout);
$this->entities = array_column(AHQ::getTags($root, 'af-entity'), NULL, 'name');
foreach (Afform::get()->setCheckPermissions(FALSE)->addSelect('name')->execute() as $block) {
$this->blocks[_afform_angular_module_name($block['name'], 'dash')] = $block;
}
foreach (array_keys($this->entities) as $entity) {
$this->entities[$entity]['fields'] = $this->entities[$entity]['joins'] = [];
}
// Pre-load full list of afforms in case this layout embeds other afform directives
$this->blocks = (array) Afform::get()->setCheckPermissions(FALSE)->setSelect(['name', 'directive_name'])->execute()->indexBy('directive_name');
$this->parseFields($layout);
}
......
......@@ -33,11 +33,8 @@ trait AfformSaveTrait {
}
else {
// Fetch existing metadata
$fields = \Civi\Api4\Afform::getfields()->setCheckPermissions(FALSE)->addSelect('name')->execute()->column('name');
$fields = \Civi\Api4\Afform::getfields()->setCheckPermissions(FALSE)->setAction('create')->addSelect('name')->execute()->column('name');
unset($fields[array_search('layout', $fields)]);
unset($fields[array_search('name', $fields)]);
unset($fields[array_search('has_local', $fields)]);
unset($fields[array_search('has_base', $fields)]);
$orig = \Civi\Api4\Afform::get()->setCheckPermissions(FALSE)->addWhere('name', '=', $item['name'])->setSelect($fields)->execute()->first();
}
......@@ -74,6 +71,8 @@ trait AfformSaveTrait {
}
// FIXME if asset-caching is enabled, then flush the asset cache.
$item['module_name'] = _afform_angular_module_name($item['name'], 'camel');
$item['directive_name'] = _afform_angular_module_name($item['name'], 'dash');
return $meta + $item;
}
......
......@@ -12,18 +12,13 @@ use Civi\Api4\Action\Afform\Submit;
*/
function _afform_fields_filter($params) {
$result = [];
$fields = \Civi\Api4\Afform::getfields()->setCheckPermissions(FALSE)->execute()->indexBy('name');
$fields = \Civi\Api4\Afform::getfields()->setCheckPermissions(FALSE)->setAction('create')->execute()->indexBy('name');
foreach ($fields as $fieldName => $field) {
if (isset($params[$fieldName])) {
$result[$fieldName] = $params[$fieldName];
}
if (isset($result[$fieldName])) {
switch ($fieldName) {
case 'is_public':
$result[$fieldName] = CRM_Utils_String::strtobool($result[$fieldName]);
break;
if ($field['data_type'] === 'Boolean' && !is_bool($params[$fieldName])) {
$result[$fieldName] = CRM_Utils_String::strtobool($params[$fieldName]);
}
}
}
......@@ -157,11 +152,11 @@ function afform_civicrm_angularModules(&$angularModules) {
$afforms = \Civi\Api4\Afform::get()
->setCheckPermissions(FALSE)
->setSelect(['name', 'requires'])
->setSelect(['name', 'requires', 'module_name', 'directive_name'])
->execute();
foreach ($afforms as $afform) {
$angularModules[_afform_angular_module_name($afform['name'], 'camel')] = [
$angularModules[$afform['module_name']] = [
'ext' => E::LONG_NAME,
'js' => ['assetBuilder://afform.js?name=' . urlencode($afform['name'])],
'requires' => $afform['requires'],
......@@ -169,7 +164,7 @@ function afform_civicrm_angularModules(&$angularModules) {
'partialsCallback' => '_afform_get_partials',
'_afform' => $afform['name'],
'exports' => [
_afform_angular_module_name($afform['name'], 'dash') => 'AE',
$afform['directive_name'] => 'AE',
],
];
}
......
......@@ -50,7 +50,7 @@
_.each(afforms, function(form) {
evaluate(form.layout);
if (form.block) {
$scope.meta.blocks[_.kebabCase(form.name)] = form;
$scope.meta.blocks[form.directive_name] = form;
}
if (form.name === $scope.afGuiEditor.name) {
$scope.afform = form;
......@@ -638,8 +638,8 @@
}
dialogService.open('saveBlockDialog', '~/afGuiEditor/saveBlock.html', model, options)
.then(function(block) {
$scope.editor.meta.blocks[_.kebabCase(block.name)] = block;
setBlockDirective(_.kebabCase(block.name));
$scope.editor.meta.blocks[block.directive_name] = block;
setBlockDirective(block.directive_name);
initializeBlockContainer();
});
};
......
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