/**
* Class CRM_Afform_AfformScanner
*
- * The AfformScanner searches the extensions and `civicrm.files` for subfolders
- * named `afform`. Each item in there is interpreted as a form instance.
+ * The AfformScanner searches the `ang` directory of extensions and `civicrm.files` for files
+ * named `*.aff.*`. Each item is interpreted as a form instance.
*
* To reduce file-scanning, we keep a cache of file paths.
*/
* Get a list of all forms and their file paths.
*
* @return array
- * Ex: ['view-individual' => ['/var/www/foo/afform/view-individual']]
+ * Ex: ['afformViewIndividual' => ['/var/www/foo/ang/afformViewIndividual']]
*/
public function findFilePaths(): array {
if ($this->isUseCachedPaths()) {
}
/**
- * Get the full path to the given file.
+ * Get the absolute path to the given file.
*
* @param string $formName
- * Ex: 'view-individual'
+ * Ex: 'afformViewIndividual'
* @param string $suffix
* Ex: 'aff.json'
* @return string|NULL
- * Ex: '/var/www/sites/default/files/civicrm/afform/view-individual.aff.json'
+ * Ex: '/var/www/sites/default/files/civicrm/ang/afform/afformViewIndividual.aff.json'
*/
- public function findFilePath($formName, $suffix) {
+ public function findFilePath(string $formName, string $suffix): ?string {
$paths = $this->findFilePaths();
if (isset($paths[$formName])) {
}
/**
- * Determine the path where we can write our own customized/overriden
+ * Determine the path where we can write our own customized/overridden
* version of a file.
*
* @param string $formName
- * Ex: 'view-individual'
- * @param string $file
+ * Ex: 'afformViewIndividual'
+ * @param string $fileType
* Ex: 'aff.json'
- * @return string|NULL
- * Ex: '/var/www/sites/default/files/civicrm/afform/view-individual.aff.json'
+ * @return string
+ * Ex: '/var/www/sites/default/files/civicrm/afform/afformViewIndividual.aff.json'
*/
- public function createSiteLocalPath($formName, $file) {
- return $this->getSiteLocalPath() . DIRECTORY_SEPARATOR . $formName . '.' . $file;
+ public function createSiteLocalPath(string $formName, string $fileType): string {
+ return $this->getSiteLocalPath() . DIRECTORY_SEPARATOR . $formName . '.' . $fileType;
}
- public function clear() {
+ public function clear(): void {
$this->cache->delete('afformAllPaths');
}
* Get the effective metadata for a form.
*
* @param string $name
- * Ex: 'view-individual'
+ * Ex: 'afformViewIndividual'
* @return array
* An array with some mix of the following keys: name, title, description, server_route, requires, is_public.
* NOTE: This is only data available in *.aff.json. It does *NOT* include layout.
* Ex: [
- * 'name' => 'view-individual',
+ * 'name' => 'afformViewIndividual',
* 'title' => 'View an individual contact',
* 'server_route' => 'civicrm/view-individual',
* 'requires' => ['afform'],
*
* @param array $record
*/
- public function addComputedFields(&$record) {
+ public function addComputedFields(array &$record) {
$name = $record['name'];
- // Ex: $allPaths['viewIndividual']['org.civicrm.foo'] == '/var/www/foo/afform/view-individual'].
+ // Ex: $allPaths['viewIndividual']['org.civicrm.foo'] == '/var/www/foo/ang/afformViewIndividual'].
$allPaths = $this->findFilePaths()[$name] ?? [];
// Empty string key refers to the site local path
$record['has_local'] = isset($allPaths['']);
}
/**
- * Get the effective metadata for all forms.
+ * Get the effective metadata for all file-based forms.
*
* @return array
* A list of all forms, keyed by form name.
- * NOTE: This is only data available in *.aff.json. It does *NOT* include layout.
- * Ex: ['view-individual' => ['title' => 'View an individual contact', ...]]
+ * NOTE: This is only data available in metadata files. It does *NOT* include layout.
+ * Ex: ['afformViewIndividual' => ['title' => 'View an individual contact', ...]]
*/
- public function getMetas() {
+ public function getMetas(): array {
$result = [];
foreach (array_keys($this->findFilePaths()) as $name) {
$result[$name] = $this->getMeta($name);
}
/**
- * @param array $formPaths
+ * @param array[] $formPaths
* List of all form paths.
* Ex: ['foo' => [0 => '/var/www/org.example.foobar/ang']]
* @param string $parent
* @param string $module
* Name of module or '' empty string for local files.
*/
- private function appendFilePaths(&$formPaths, $parent, $module) {
+ private function appendFilePaths(array &$formPaths, string $parent, string $module) {
$files = preg_grep(self::FILE_REGEXP, (array) glob("$parent/*"));
foreach ($files as $file) {
/**
* Get the path where site-local form customizations are stored.
*
- * @return mixed|string
+ * @return string
* Ex: '/var/www/sites/default/files/civicrm/afform'.
*/
- public function getSiteLocalPath() {
+ public function getSiteLocalPath(): string {
// TODO Allow a setting override.
// return Civi::paths()->getPath(Civi::settings()->get('afformPath'));
return Civi::paths()->getPath('[civicrm.files]/ang');