From dd10599cda0c72e22b8ee9b1369751373bd7e975 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 10 Dec 2019 22:22:03 -0500 Subject: [PATCH] Fix afform partial name ng-include was failing with ~afform* but works with ~/afform* --- ext/afform/core/afform.php | 22 +++---------------- .../tests/phpunit/Civi/Afform/FilterTest.php | 20 ++++++++++++++--- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 62759fe6b4..5824fca870 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -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(). */ diff --git a/ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php b/ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php index 8f94f03442..fba7e5e028 100644 --- a/ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php +++ b/ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php @@ -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, '
'); - $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, '
'); - $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, '
'); - $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); -- 2.25.1