diff --git a/CRM/Extension/Container/Basic.php b/CRM/Extension/Container/Basic.php index 42277242767a..3251722565e7 100644 --- a/CRM/Extension/Container/Basic.php +++ b/CRM/Extension/Container/Basic.php @@ -82,6 +82,14 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface */ public $relUrls = FALSE; + /** + * @var array + * Array(function(CRM_Extension_Info $info): bool) + * List of callables which determine whether an extension is visible. + * Each function returns TRUE if the extension should be visible. + */ + protected $filters = []; + /** * @param string $baseDir * Local path to the container. @@ -216,7 +224,16 @@ protected function getRelPaths() { CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage()); continue; } - $this->relPaths[$info->key] = $relPath; + $visible = TRUE; + foreach ($this->filters as $filter) { + if (!$filter($info)) { + $visible = FALSE; + break; + } + } + if ($visible) { + $this->relPaths[$info->key] = $relPath; + } } if ($this->cache) { $this->cache->set($this->cacheKey, $this->relPaths); @@ -259,6 +276,20 @@ protected function getRelUrls() { return $this->relUrls; } + /** + * Register a filter which determine whether a copy of an extension + * appears as available. + * + * @param callable $callable + * function(CRM_Extension_Info $info): bool + * Each function returns TRUE if the extension should be visible. + * @return $this + */ + public function addFilter($callable) { + $this->filters[] = $callable; + return $this; + } + /** * Convert a list of relative paths to relative URLs. * diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index b3157ffd5722..f9665524d9b9 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -155,6 +155,12 @@ public function getFullContainer() { } } + if (!defined('CIVICRM_TEST')) { + foreach ($containers as $container) { + $container->addFilter([__CLASS__, 'isNotTestExtension']); + } + } + $this->fullContainer = new CRM_Extension_Container_Collection($containers, $this->getCache(), 'full'); } return $this->fullContainer; @@ -302,6 +308,10 @@ public static function getCompatibilityInfo() { return Civi::$statics[__CLASS__]['compatibility']; } + public static function isNotTestExtension(CRM_Extension_Info $info) { + return (bool) !preg_match('/^test\./', $info->key); + } + /** * Take an extension's raw XML info and add information about the * extension's status on the local system.