From 09fef788a1d7b3482686432a5eae2f1c2593fb69 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 22 Feb 2019 22:19:06 +0300 Subject: [PATCH] Flextype Core: New Fieldsets API - improvements --- flextype/Fieldsets.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/flextype/Fieldsets.php b/flextype/Fieldsets.php index 81d15d8a..193d2ac7 100644 --- a/flextype/Fieldsets.php +++ b/flextype/Fieldsets.php @@ -18,6 +18,33 @@ use Flextype\Component\Registry\Registry; class Fieldsets { + /** + * Fetch Fieldsets for current theme + * + * @access public + * @return array + */ + public static function fetchList() : array + { + $fieldsets = []; + + // Get fieldsets files + $_fieldsets = Filesystem::listContents(Fieldsets::_dir_location()); + + // If there is any template file then go... + if (count($_fieldsets) > 0) { + foreach ($_fieldsets as $fieldset) { + if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') { + $fieldset_content = YamlParser::decode(Filesystem::read($fieldset['path'])); + $fieldsets[$fieldset['basename']] = $fieldset_content['title']; + } + } + } + + // return fieldsets + return $fieldsets; + } + /** * Rename fieldset * @@ -107,6 +134,17 @@ class Fieldsets return Filesystem::has(Fieldsets::_file_location($fieldset)); } + /** + * Helper method _dir_location + * + * @access private + * @return string + */ + private static function _dir_location() : string + { + return PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/'; + } + /** * Helper method _file_location * @@ -114,7 +152,7 @@ class Fieldsets * @param string $name Name * @return string */ - private static function _file_location($name) + private static function _file_location(string $name) : string { return PATH['themes'] . '/' . Registry::get('settings.theme') . '/fieldsets/' . $name . '.yaml'; }