Skip to content

Commit b3a0765

Browse files
committed
Improves support for snippets defined in partials
1 parent 4310f55 commit b3a0765

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

classes/Snippet.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public static function processTemplateSettings($template)
363363
foreach ($parsedProperties as $index => &$property) {
364364
$property['id'] = $index;
365365

366-
if (isset($property['options'])) {
366+
if (isset($property['options']) && is_array($property['options'])) {
367367
$property['options'] = self::dropDownOptionsToString($property['options']);
368368
}
369369
}
@@ -408,18 +408,26 @@ protected static function preprocessPropertyValues($theme, $snippetCode, $compon
408408

409409
/**
410410
* Converts a keyed object to an array, converting the index to the "property" value.
411-
* @return array
412411
*/
413-
protected static function parseIniProperties($properties)
412+
protected static function parseIniProperties($properties): array
414413
{
415414
foreach ($properties as $index => $value) {
416-
$properties[$index]['property'] = $index;
415+
if (!is_array($value['options'])) {
416+
$value['options'] = self::dropDownOptionsToArray($value['options']);
417+
}
418+
419+
if (is_int($index)) {
420+
$properties[$value['property']] = $value;
421+
unset($properties[$index]);
422+
} elseif (is_string($index)) {
423+
$properties[$index]['property'] = $index;
424+
}
417425
}
418426

419427
return array_values($properties);
420428
}
421429

422-
protected static function dropDownOptionsToArray($optionsString)
430+
protected static function dropDownOptionsToArray(string $optionsString): array
423431
{
424432
$options = explode('|', $optionsString);
425433

@@ -447,7 +455,7 @@ protected static function dropDownOptionsToArray($optionsString)
447455
return $result;
448456
}
449457

450-
protected static function dropDownOptionsToString($optionsArray)
458+
protected static function dropDownOptionsToString(array $optionsArray)
451459
{
452460
$result = [];
453461
$isAssoc = (bool) count(array_filter(array_keys($optionsArray), 'is_string'));

classes/SnippetManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function removeSnippet(string $snippetCode)
9191
* @param string $code Specifies the snippet code.
9292
* @param string $$componentClass Specifies the snippet component class, if available.
9393
* @param boolean $allowCaching Specifies whether caching is allowed for the call.
94-
* @return array Returns an array of Snippet objects.
94+
* @return Snippet|null Returns the Snippet object if found
9595
*/
9696
public function findByCodeOrComponent($theme, $code, $componentClass, $allowCaching = false)
9797
{
@@ -185,7 +185,7 @@ protected static function getPartialMapCacheKey($theme)
185185
/**
186186
* Returns a list of partial-based snippets and corresponding partial names.
187187
* @param \Cms\Classes\Theme $theme Specifies a parent theme.
188-
* @return Returns an associative array with the snippet code in keys and partial file names in values.
188+
* @return array Returns an associative array with the snippet code in keys and partial file names in values.
189189
*/
190190
public function getPartialSnippetMap($theme)
191191
{

0 commit comments

Comments
 (0)