'functions' => \CRM_Api4_Page_Api4Explorer::getSqlFunctions(),
'displayTypes' => Display::getDisplayTypes(['id', 'name', 'label', 'description', 'icon']),
'styles' => \CRM_Utils_Array::makeNonAssociative(self::getStyles()),
+ 'defaultPagerSize' => \Civi::settings()->get('default_pager_size'),
'afformEnabled' => $extensions->isActiveModule('afform'),
'afformAdminEnabled' => $extensions->isActiveModule('afform_admin'),
];
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']],
// Add paths (but only RUD actions) with translated titles
foreach ($entity['paths'] as $action => $path) {
unset($entity['paths'][$action]);
- switch ($action) {
- case 'view':
- $title = E::ts('View %1', [1 => $entity['title']]);
- break;
-
- case 'update':
- $title = E::ts('Edit %1', [1 => $entity['title']]);
- break;
-
- case 'delete':
- $title = E::ts('Delete %1', [1 => $entity['title']]);
- break;
-
- default:
- continue 2;
+ if (in_array($action, ['view', 'update', 'delete'], TRUE)) {
+ $entity['paths'][] = [
+ 'path' => $path,
+ 'action' => $action,
+ ];
}
- $entity['paths'][] = [
- 'path' => $path,
- 'title' => $title,
- 'action' => $action,
- ];
}
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly'],
foreach ($schema as &$entity) {
if (in_array('DAOEntity', $entity['type'], TRUE) && !in_array('EntityBridge', $entity['type'], TRUE)) {
foreach (array_reverse($entity['fields'], TRUE) as $index => $field) {
- if (!empty($field['fk_entity']) && !$field['options'] && !empty($schema[$field['fk_entity']]['label_field'])) {
+ if (!empty($field['fk_entity']) && !$field['options'] && empty($field['serialize']) && !empty($schema[$field['fk_entity']]['label_field'])) {
$isCustom = strpos($field['name'], '.');
// Custom fields: append "Contact ID" to original field label
if ($isCustom) {
});
$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],