From bebb3e591f3bc099765a06ba9a21fee0c16a1829 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 1 Nov 2019 12:40:56 -0700 Subject: [PATCH] (REF) AfformScanner::getLayout() - Extract new method --- ext/afform/core/CRM/Afform/AfformScanner.php | 12 ++++++++++++ ext/afform/core/Civi/Api4/Action/Afform/Get.php | 9 ++++----- ext/afform/core/afform.php | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ext/afform/core/CRM/Afform/AfformScanner.php b/ext/afform/core/CRM/Afform/AfformScanner.php index fe2c91f6cc..f7ba60a704 100644 --- a/ext/afform/core/CRM/Afform/AfformScanner.php +++ b/ext/afform/core/CRM/Afform/AfformScanner.php @@ -152,6 +152,18 @@ class CRM_Afform_AfformScanner { } } + /** + * @param string $formName + * Ex: 'view-individual' + * @return string|NULL + * Ex: 'Hello world!' + * NULL if no layout exists + */ + public function getLayout($formName) { + $filePath = $this->findFilePath($formName, self::LAYOUT_FILE); + return $filePath === NULL ? NULL : file_get_contents($filePath); + } + /** * Get the effective metadata for all forms. * diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Get.php b/ext/afform/core/Civi/Api4/Action/Afform/Get.php index 61da5f8d52..e6571eb591 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/Get.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/Get.php @@ -22,11 +22,10 @@ class Get extends BasicGetAction { $values = []; foreach ($names as $name) { $record = $scanner->getMeta($name); - $layout = $scanner->findFilePath($name, 'aff.html'); - if ($layout) { - // FIXME check for file existence+substance+validity - $html = file_get_contents($layout); - $record['layout'] = $this->convertHtmlToOutput($html); + $layout = $scanner->getLayout($name); + if ($layout !== NULL) { + // FIXME check for validity? + $record['layout'] = $this->convertHtmlToOutput($layout); } $values[] = $record; } diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index bbd0b627b0..a18f2bd67a 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -400,7 +400,7 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) { $fileName = '~afform/' . _afform_angular_module_name($name, 'camel'); $htmls = [ - $fileName => file_get_contents($scanner->findFilePath($name, 'aff.html')), + $fileName => $scanner->getLayout($name), ]; $htmls = \Civi\Angular\ChangeSet::applyResourceFilters(Civi::service('angular')->getChangeSets(), 'partials', $htmls); -- 2.25.1