Skip to content

Commit 9305b60

Browse files
authored
Remove fsIDs from Options (#25)
1 parent 5463af9 commit 9305b60

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

blocks/easy_image_gallery/advanced_options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @var Concrete\Package\EasyImageGallery\Options $options
1313
* @var Concrete\Core\File\Set\Set[] $fileSets
1414
* @var array $fDetails
15+
* @var int[] $fsIDs
1516
* @var bool $isComposer
1617
*/
1718

blocks/easy_image_gallery/controller.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ private function addOrEdit()
545545
$this->set('options', $this->getOptions());
546546
$this->set('fileSets', $this->getFileSetList());
547547
$this->set('fDetails', $this->getFilesDetails());
548+
$this->set('fsIDs', array_values(
549+
array_unique(
550+
array_filter(
551+
array_map(
552+
static function ($fID) {
553+
return preg_match('/^fsID[1-9]\d{0,18}$/', $fID) ? (int) substr($fID, strlen('fsID')) : 0;
554+
},
555+
explode(',', (string) $this->fIDs)
556+
),
557+
static function ($fsID) {
558+
return $fsID > 0;
559+
}
560+
)
561+
)
562+
));
548563
$this->set('isComposer', false);
549564
}
550565

blocks/easy_image_gallery/form_setup_html.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @var Concrete\Package\EasyImageGallery\Options $options
1313
* @var Concrete\Core\File\Set\Set[] $fileSets
1414
* @var array $fDetails
15+
* @var int[] $fsIDs
1516
* @var bool $isComposer
1617
*/
1718

@@ -27,7 +28,7 @@
2728
foreach ($fileSets as $fs) {
2829
$fsID = (int) $fs->getFileSetID();
2930
?>
30-
<option value="<?= $fsID ?>" <?= in_array($fsID, $options->fsIDs, true) ? 'selected' : '' ?>><?= h($fs->getFileSetName()) ?></option>
31+
<option value="<?= $fsID ?>" <?= in_array($fsID, $fsIDs, true) ? 'selected' : '' ?>><?= h($fs->getFileSetName()) ?></option>
3132
<?php
3233
}
3334
?>
@@ -129,7 +130,7 @@
129130

130131
const sliderEntriesContainer = $('.easy_image-items');
131132

132-
let selectedFilesets = <?= json_encode($options->fsIDs) ?>;
133+
let selectedFilesets = <?= json_encode($fsIDs) ?>;
133134

134135
let is_first_file = true;
135136

src/Concrete/Options.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
*/
1010
final class Options
1111
{
12-
/**
13-
* @var int[]
14-
*/
15-
public $fsIDs = [];
16-
1712
/**
1813
* @var string
1914
*/
@@ -91,14 +86,6 @@ final class Options
9186

9287
private function __construct(array $data)
9388
{
94-
if (isset($data['fsIDs']) && is_array($data['fsIDs'])) {
95-
foreach ($data['fsIDs'] as $id) {
96-
$id = (int) $id;
97-
if ($id > 0 && !in_array($id, $this->fsIDs, true)) {
98-
$this->fsIDs[] = $id;
99-
}
100-
}
101-
}
10289
$this->setString($data, 'lightbox', 'lightbox');
10390
$this->setBool($data, 'preloadImages', false);
10491
$this->setBool($data, 'textFiltering', false);
@@ -133,16 +120,6 @@ public static function fromJson($json)
133120
*/
134121
public static function fromUI(array $data)
135122
{
136-
$fsIDs = [];
137-
if (isset($data['fID']) && is_array($data['fID'])) {
138-
foreach ($data['fID'] as $fID) {
139-
if (strpos($fID, 'fsID') === 0) {
140-
$fsIDs[] = substr($fID, 4);
141-
}
142-
}
143-
}
144-
$data['fsIDs'] = $fsIDs;
145-
146123
return new self($data);
147124
}
148125

@@ -160,7 +137,6 @@ public function getFancyOverlayCSSColor()
160137
public function export()
161138
{
162139
$data = (array) $this;
163-
unset($data['fsIDs']);
164140

165141
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
166142
}

0 commit comments

Comments
 (0)