mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 08:04:05 +02:00
Flextype Core: New Fieldsets API - improvements
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
Reference in New Issue
Block a user