SearchKit - Add translatable descriptions to entities
[civicrm-core.git] / Civi / Api4 / Generic / AbstractEntity.php
index ce0fb9d29bf9dbb85ca412e198fdc677e8ef6c5a..66bd4d3c1d7915461639a43d1a1eee75d4187de9 100644 (file)
@@ -147,6 +147,9 @@ abstract class AbstractEntity {
       'paths' => static::getEntityPaths(),
       'class' => static::class,
       'id_field' => 'id',
+      // Entities without a @searchable annotation will default to secondary,
+      // which makes them visible in SearchKit but not at the top of the list.
+      'searchable' => 'secondary',
     ];
     // Add info for entities with a corresponding DAO
     $dao = \CRM_Core_DAO_AllCoreTables::getFullName($info['name']);
@@ -159,11 +162,11 @@ abstract class AbstractEntity {
     foreach (ReflectionUtils::getTraits(static::class) as $trait) {
       $info['type'][] = self::stripNamespace($trait);
     }
-    // Entities without a @searchable annotation will default to secondary,
-    // which makes them visible in SearchKit but not at the top of the list.
-    $info['searchable'] = 'secondary';
     $reflection = new \ReflectionClass(static::class);
     $info = array_merge($info, ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']]));
+    if ($dao) {
+      $info['description'] = $dao::getEntityDescription() ?? $info['description'] ?? NULL;
+    }
     unset($info['package'], $info['method']);
     return $info;
   }