From 841850b13232d8b3eab48274e8ff53d0b9a4df7c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 12 Jun 2018 22:18:15 -0700 Subject: [PATCH] _afform_angular_module_name - Accept `$format` option --- ext/afform/afform.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ext/afform/afform.php b/ext/afform/afform.php index 01305db2e8..a1a46e121e 100644 --- a/ext/afform/afform.php +++ b/ext/afform/afform.php @@ -218,11 +218,25 @@ function afform_civicrm_alterMenu(&$items) { } /** - * @param $name + * @param string $name + * Ex: fooBar + * @param string $format + * 'camel' or 'dash'. * @return string + * Ex: 'FooBar' or 'foo-bar'. */ -function _afform_angular_module_name($name) { - return 'afform' . strtoupper($name{0}) . substr($name, 1); +function _afform_angular_module_name($name, $format = 'camel') { + switch ($format) { + case 'camel': + return 'afform' . strtoupper($name{0}) . substr($name, 1); + + case 'dash': + $camel = _afform_angular_module_name($name, 'camel'); + return strtolower(implode('-', array_filter(preg_split('/(?=[A-Z])/', $camel)))); + + default: + throw new \Exception("Unrecognized format"); + } } /** -- 2.25.1