(REF) AfformScanner::getLayout() - Extract new method
authorTim Otten <totten@civicrm.org>
Fri, 1 Nov 2019 19:40:56 +0000 (12:40 -0700)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:19 +0000 (19:13 -0700)
ext/afform/core/CRM/Afform/AfformScanner.php
ext/afform/core/Civi/Api4/Action/Afform/Get.php
ext/afform/core/afform.php

index fe2c91f6cc914863d4d7a3fcb80b731709b95046..f7ba60a704b560630b7b1fadc7f1c0b6930ec030 100644 (file)
@@ -152,6 +152,18 @@ class CRM_Afform_AfformScanner {
     }
   }
 
+  /**
+   * @param string $formName
+   *   Ex: 'view-individual'
+   * @return string|NULL
+   *   Ex: '<em>Hello world!</em>'
+   *   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.
    *
index 61da5f8d523a0f921dc31d50e355d56fa54bba31..e6571eb591e3119f132a364d7c69e71d8fa66abf 100644 (file)
@@ -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;
     }
index bbd0b627b08d25f02de1f37c8736018d860459c7..a18f2bd67a6a12c9e52a8eeacfa13dcf5efa231c 100644 (file)
@@ -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);