public static function getSchema() {
$schema = [];
$entities = \Civi\Api4\Entity::get()
- ->addSelect('name', 'title', 'type', 'title_plural', 'description', 'label_field', 'icon', 'paths', 'dao', 'bridge', 'ui_join_filters')
- ->addWhere('searchable', '=', TRUE)
+ ->addSelect('name', 'title', 'type', 'title_plural', 'description', 'label_field', 'icon', 'paths', 'dao', 'bridge', 'ui_join_filters', 'searchable')
+ ->addWhere('searchable', '!=', 'none')
->addOrderBy('title_plural')
->setChain([
'get' => ['$name', 'getActions', ['where' => [['name', '=', 'get']]], ['params']],
});
$fields = array_column($entity['fields'], NULL, 'name');
$bridge = in_array('EntityBridge', $entity['type']) ? $entity['name'] : NULL;
+ $bridgeFields = array_keys($entity['bridge'] ?? []);
foreach ($references as $reference) {
$keyField = $fields[$reference->getReferenceKey()] ?? NULL;
- // Exclude any joins that are better represented by pseudoconstants
- if (is_a($reference, 'CRM_Core_Reference_OptionValue')
- || !$keyField || !empty($keyField['options'])
+ if (
+ // Sanity check - keyField must exist
+ !$keyField ||
+ // Exclude any joins that are better represented by pseudoconstants
+ is_a($reference, 'CRM_Core_Reference_OptionValue') || (!$bridge && !empty($keyField['options'])) ||
// Limit bridge joins to just the first
- || $bridge && array_search($keyField['name'], $entity['bridge']) !== 0
+ ($bridge && array_search($keyField['name'], $bridgeFields) !== 0) ||
// Sanity check - table should match
- || $daoClass::getTableName() !== $reference->getReferenceTable()
+ $daoClass::getTableName() !== $reference->getReferenceTable()
) {
continue;
}
// Bridge joins (sanity check - bridge must specify exactly 2 FK fields)
elseif (count($entity['bridge']) === 2) {
// Get the other entity being linked through this bridge
- $baseKey = array_search($reference->getReferenceKey(), $entity['bridge']) ? $entity['bridge'][0] : $entity['bridge'][1];
+ $baseKey = array_search($reference->getReferenceKey(), $bridgeFields) ? $bridgeFields[0] : $bridgeFields[1];
$baseEntity = $allowedEntities[$fields[$baseKey]['fk_entity']] ?? NULL;
if (!$baseEntity) {
continue;
$alias = $baseEntity['name'] . "_{$bridge}_" . $targetEntityName;
$joins[$baseEntity['name']][] = [
'label' => $baseEntity['title'] . ' ' . $targetsTitle,
- 'description' => E::ts('Multiple %1 per %2', [1 => $targetsTitle, 2 => $baseEntity['title']]),
+ 'description' => $entity['bridge'][$baseKey]['description'] ?? E::ts('Multiple %1 per %2', [1 => $targetsTitle, 2 => $baseEntity['title']]),
'entity' => $targetEntityName,
'conditions' => array_merge(
[$bridge],
$alias = $targetEntityName . "_{$bridge}_" . $baseEntity['name'];
$joins[$targetEntityName][] = [
'label' => $targetEntity['title'] . ' ' . $baseEntity['title_plural'],
- 'description' => E::ts('Multiple %1 per %2', [1 => $baseEntity['title_plural'], 2 => $targetEntity['title']]),
+ 'description' => $entity['bridge'][$reference->getReferenceKey()]['description'] ?? E::ts('Multiple %1 per %2', [1 => $baseEntity['title_plural'], 2 => $targetEntity['title']]),
'entity' => $baseEntity['name'],
'conditions' => array_merge(
[$bridge],