CodeGen - Add EXT and TABLE_ADDED to each DAO file
authorColeman Watts <coleman@civicrm.org>
Fri, 7 Aug 2020 19:27:51 +0000 (15:27 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 13 Aug 2020 00:50:02 +0000 (20:50 -0400)
CRM/Core/CodeGen/DAO.php
CRM/Core/CodeGen/Specification.php
xml/templates/dao.tpl

index ef6dc88f96b71cb5dc021a4350eab66a3b18581f..9865d9e5f8be8dee6d1c11a6b67cfde800a8988c 100644 (file)
@@ -28,6 +28,8 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask {
 
   private $useHelper = '';
 
+  private $ext = "'civicrm'";
+
   /**
    * CRM_Core_CodeGen_DAO constructor.
    *
@@ -39,10 +41,11 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask {
     parent::__construct($config);
     $this->name = $name;
     $this->tsFunctionName = $tsFunctionName;
-    // Cleanup helper class with a use statement
+    // If this DAO belongs to an extension, add `use` statement and define EXT constant.
     if (strpos($tsFunctionName, '::ts')) {
       $this->tsFunctionName = 'E::ts';
       $this->useHelper = 'use \\' . explode('::', $tsFunctionName)[0] . ' as E;';
+      $this->ext = 'E::LONG_NAME';
     }
   }
 
@@ -107,6 +110,7 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask {
       $template->assign('indicesPhp', var_export($this->tables[$this->name]['index'], 1));
     }
     $template->assign('tsFunctionName', $this->tsFunctionName);
+    $template->assign('ext', $this->ext);
     $template->assign('useHelper', $this->useHelper);
     return $template;
   }
index 0f4678d74acde15fe778eb0305bcd17b30471d37..4d2be52ad41a80a166a0a7e479ab6de497f6e767 100644 (file)
@@ -212,6 +212,7 @@ class CRM_Core_CodeGen_Specification {
       'objectName' => $klass,
       'title' => $tableXML->title ?? self::nameToTitle($klass),
       'icon' => $tableXML->icon ?? NULL,
+      'add' => $tableXML->add ?? NULL,
       'labelName' => substr($name, 8),
       'className' => $this->classNames[$name],
       'bao' => ($useBao ? str_replace('DAO', 'BAO', $this->classNames[$name]) : $this->classNames[$name]),
index 778269995ba791ea4c9e5178cff25f431bb030e4..87a3463531c9a096e0b7abfdcca99893207263ae 100644 (file)
@@ -13,6 +13,9 @@
  */
 class {$table.className} extends CRM_Core_DAO {ldelim}
 
+     const EXT = {$ext};
+     const TABLE_ADDED = '{$table.add}';
+
      /**
       * Static instance to hold the table name.
       *