Skip to content

Commit 096d4f8

Browse files
committed
Fix select box item selected
1 parent 91179a2 commit 096d4f8

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "amkdev/server-path-field",
33
"description": "Craft CMS field type that provides a dropdown field that let you select a server path within the webroot.",
44
"type": "craft-plugin",
5-
"version": "1.0.0.1",
5+
"version": "1.0.0.2",
66
"keywords": [
77
"craft",
88
"cms",

src/fields/ServerPathFieldType.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,14 @@ public function getSettingsHtml()
9393
public function getInputHtml($value, ElementInterface $element = null): string
9494
{
9595
$settings = $this->getSettings();
96-
$path = rtrim(Craft::getAlias('@webroot') . DIRECTORY_SEPARATOR . $settings['rootPath'], DIRECTORY_SEPARATOR);
97-
96+
$settings['rootPath'] = trim(rtrim( $settings['rootPath'], DIRECTORY_SEPARATOR));
97+
$path = Craft::getAlias('@webroot') . DIRECTORY_SEPARATOR . $settings['rootPath'];
9898

9999
$dirList = array();
100100
if (is_dir($path)) {
101101

102102
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
103103

104-
105104
foreach ($iterator as $file) {
106105

107106
if ($file->isDir() && ($file->isDir() && $file->getFilename() != '..')) {
@@ -124,10 +123,10 @@ public function getInputHtml($value, ElementInterface $element = null): string
124123
if (count($dirList) > 0) {
125124
$string = '<div class="select"><select name="' . $this->handle . '">';
126125
$string .= '<option value="">Choose a directory</option>';
127-
128126
foreach ($dirList as $entry) {
129-
$selected = ($value === $entry) ? 'selected="selected' : '';
130-
$string .= '<option ' . $selected . ' value="' . $settings['rootPath'] . DIRECTORY_SEPARATOR . $entry . '">' . $entry . '</option>';
127+
$entyVal = $settings['rootPath'] . DIRECTORY_SEPARATOR . $entry;
128+
$selected = ($value === $entyVal ) ? 'selected="selected' : '';
129+
$string .= '<option ' . $selected . ' value="' . $entyVal . '">' . $entry . '</option>';
131130
}
132131
$string .= '</select></div>';
133132
} else {

0 commit comments

Comments
 (0)