diff --git a/CRM/Api4/Page/Api4Explorer.php b/CRM/Api4/Page/Api4Explorer.php index af188f313609..0f1125f5ca2c 100644 --- a/CRM/Api4/Page/Api4Explorer.php +++ b/CRM/Api4/Page/Api4Explorer.php @@ -10,7 +10,6 @@ +--------------------------------------------------------------------+ */ -use Civi\Api4\Service\Schema\Joinable\Joinable; use Civi\Api4\Utils\CoreUtil; /** @@ -23,18 +22,11 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page { public function run() { $apiDoc = new ReflectionFunction('civicrm_api4'); $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]); - // Don't show n-to-many joins in Explorer - $entityLinks = (array) civicrm_api4('Entity', 'getLinks', [], ['entity' => 'links']); - foreach ($entityLinks as $entity => $links) { - $entityLinks[$entity] = array_filter($links, function($link) { - return $link['joinType'] != Joinable::JOIN_TYPE_ONE_TO_MANY; - }); - } + $vars = [ 'operators' => CoreUtil::getOperators(), 'basePath' => Civi::resources()->getUrl('civicrm'), 'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(), - 'links' => $entityLinks, 'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()), 'functions' => self::getSqlFunctions(), 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'), diff --git a/Civi/Api4/Action/Entity/GetLinks.php b/Civi/Api4/Action/Entity/GetLinks.php index 8ae38eead3d2..e0458b56b599 100644 --- a/Civi/Api4/Action/Entity/GetLinks.php +++ b/Civi/Api4/Action/Entity/GetLinks.php @@ -15,11 +15,15 @@ use Civi\Api4\Utils\CoreUtil; /** - * Get a list of FK links between entities + * Get a list of FK links between entities. + * + * This action is deprecated; the API no longer uses these links to determine available joins. + * @deprecated */ class GetLinks extends \Civi\Api4\Generic\BasicGetAction { public function getRecords() { + \CRM_Core_Error::deprecatedWarning('APIv4 Entity::getLinks is deprecated.'); $result = []; /** @var \Civi\Api4\Service\Schema\SchemaMap $schema */ $schema = \Civi::container()->get('schema_map'); diff --git a/Civi/Api4/Entity.php b/Civi/Api4/Entity.php index b693895572c2..1660d74d8cb0 100644 --- a/Civi/Api4/Entity.php +++ b/Civi/Api4/Entity.php @@ -128,6 +128,7 @@ public static function getFields($checkPermissions = TRUE) { /** * @param bool $checkPermissions + * @deprecated * @return Action\Entity\GetLinks */ public static function getLinks($checkPermissions = TRUE) { diff --git a/Civi/Api4/Service/Schema/SchemaMapBuilder.php b/Civi/Api4/Service/Schema/SchemaMapBuilder.php index e89b7c359ada..7db2ac0d5bc7 100644 --- a/Civi/Api4/Service/Schema/SchemaMapBuilder.php +++ b/Civi/Api4/Service/Schema/SchemaMapBuilder.php @@ -68,8 +68,6 @@ private function loadTables(SchemaMap $map) { $this->addCustomFields($map, $table, $data['name']); } } - - $this->addBackReferences($map); } /** @@ -98,49 +96,6 @@ private function addJoins(Table $table, $field, array $data) { } } - /** - * Loop through existing links and provide link from the other side - * - * @param SchemaMap $map - */ - private function addBackReferences(SchemaMap $map) { - foreach ($map->getTables() as $table) { - foreach ($table->getTableLinks() as $link) { - $target = $map->getTableByName($link->getTargetTable()); - $tableName = $link->getBaseTable(); - // Exclude custom field tables - if (strpos($link->getTargetTable(), 'civicrm_value_') !== 0 && strpos($link->getBaseTable(), 'civicrm_value_') !== 0) { - $plural = str_replace('civicrm_', '', $this->getPlural($tableName)); - $joinable = new Joinable($tableName, $link->getBaseColumn(), $plural); - $joinable->setJoinType($joinable::JOIN_TYPE_ONE_TO_MANY); - $target->addTableLink($link->getTargetColumn(), $joinable); - } - } - } - } - - /** - * Simple implementation of pluralization. - * Could be replaced with symfony/inflector - * - * @param string $singular - * - * @return string - */ - private function getPlural($singular) { - $last_letter = substr($singular, -1); - switch ($last_letter) { - case 'y': - return substr($singular, 0, -1) . 'ies'; - - case 's': - return $singular . 'es'; - - default: - return $singular . 's'; - } - } - /** * @param \Civi\Api4\Service\Schema\SchemaMap $map * @param \Civi\Api4\Service\Schema\Table $baseTable diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index f28cec6dbe9b..3d800559426b 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -10,10 +10,10 @@