Commit d3f4ea69 authored by colemanw's avatar colemanw
Browse files

Fix afform partial name

ng-include was failing with ~afform* but works with ~/afform*
parent a424a60d
......@@ -172,7 +172,7 @@ function afform_civicrm_angularModules(&$angularModules) {
'requires' => $meta['requires'],
'basePages' => [],
'snippets' => [
"~afform/$name.aff.html" => $layout,
"~/afform/$name.aff.html" => $layout,
],
'exports' => [
_afform_angular_module_name($name, 'dash') => 'AE',
......@@ -300,7 +300,7 @@ function _afform_reverse_deps_find($formName, $html, $revMap) {
*/
function afform_civicrm_alterAngular($angular) {
$fieldMetadata = \Civi\Angular\ChangeSet::create('fieldMetadata')
->alterHtml(';^~afform/;', function($doc, $path) {
->alterHtml(';\\.aff\\.html$;', function($doc, $path) {
$entities = _afform_getMetadata($doc);
foreach (pq('af-field', $doc) as $afField) {
......@@ -412,28 +412,12 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) {
'camel' => _afform_angular_module_name($name, 'camel'),
'meta' => $meta,
'metaJson' => json_encode($meta),
'templateUrl' => "~afform/$name.aff.html",
'templateUrl' => "~/afform/$name.aff.html",
]);
$mimeType = 'text/javascript';
$content = $smarty->fetch('afform/AfformAngularModule.tpl');
}
/**
* Apply any filters to an HTML partial.
*
* @param string $formName
* @param string $html
* Original HTML.
* @return string
* Modified HTML.
*/
function _afform_html_filter($formName, $html) {
$fileName = '~afform/' . _afform_angular_module_name($formName, 'camel');
$htmls = [$fileName => $html];
$htmls = \Civi\Angular\ChangeSet::applyResourceFilters(Civi::service('angular')->getChangeSets(), 'partials', $htmls);
return $htmls[$fileName];
}
/**
* Implements hook_civicrm_alterMenu().
*/
......
......@@ -20,10 +20,24 @@ class FilterTest extends \PHPUnit\Framework\TestCase implements HeadlessInterfac
return \Civi\Test::headless()->installMe(__DIR__)->apply();
}
/**
* Apply any filters to an HTML partial.
*
* @param string $fileName
* @param string $html
* Original HTML.
* @return string
* Modified HTML.
*/
private function htmlFilter($fileName, $html) {
$htmls = \Civi\Angular\ChangeSet::applyResourceFilters(\Civi::service('angular')->getChangeSets(), 'partials', [$fileName => $html]);
return $htmls[$fileName];
}
public function testDefnInjection() {
$inputHtml = sprintf(self::PERSON_TPL,
'<div af-fieldset="person"><af-field name="first_name" /></div>');
$filteredHtml = _afform_html_filter('~afform/MyForm.html', $inputHtml);
$filteredHtml = $this->htmlFilter('~/afform/MyForm.aff.html', $inputHtml);
$converter = new \CRM_Afform_ArrayHtml(TRUE);
$parsed = $converter->convertHtmlToArray($filteredHtml);
......@@ -35,7 +49,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase implements HeadlessInterfac
public function testDefnInjectionNested() {
$inputHtml = sprintf(self::PERSON_TPL,
'<span><div af-fieldset="person"><foo><af-field name="first_name" /></foo></div></span>');
$filteredHtml = _afform_html_filter('~afform/MyForm.html', $inputHtml);
$filteredHtml = $this->htmlFilter('~/afform/MyForm.aff.html', $inputHtml);
$converter = new \CRM_Afform_ArrayHtml(TRUE);
$parsed = $converter->convertHtmlToArray($filteredHtml);
......@@ -47,7 +61,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase implements HeadlessInterfac
public function testDefnOverrideTitle() {
$inputHtml = sprintf(self::PERSON_TPL,
'<div af-fieldset="person"><af-field name="first_name" defn="{title: \'Given name\'}" /></div>');
$filteredHtml = _afform_html_filter('~afform/MyForm.html', $inputHtml);
$filteredHtml = $this->htmlFilter('~/afform/MyForm.aff.html', $inputHtml);
$converter = new \CRM_Afform_ArrayHtml(TRUE);
$parsed = $converter->convertHtmlToArray($filteredHtml);
......
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