Skip to content

Commit

Permalink
Fix select box item selected
Browse files Browse the repository at this point in the history
  • Loading branch information
amkdev committed Jun 10, 2021
1 parent 91179a2 commit 096d4f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amkdev/server-path-field",
"description": "Craft CMS field type that provides a dropdown field that let you select a server path within the webroot.",
"type": "craft-plugin",
"version": "1.0.0.1",
"version": "1.0.0.2",
"keywords": [
"craft",
"cms",
Expand Down
11 changes: 5 additions & 6 deletions src/fields/ServerPathFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ public function getSettingsHtml()
public function getInputHtml($value, ElementInterface $element = null): string
{
$settings = $this->getSettings();
$path = rtrim(Craft::getAlias('@webroot') . DIRECTORY_SEPARATOR . $settings['rootPath'], DIRECTORY_SEPARATOR);

$settings['rootPath'] = trim(rtrim( $settings['rootPath'], DIRECTORY_SEPARATOR));
$path = Craft::getAlias('@webroot') . DIRECTORY_SEPARATOR . $settings['rootPath'];

$dirList = array();
if (is_dir($path)) {

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


foreach ($iterator as $file) {

if ($file->isDir() && ($file->isDir() && $file->getFilename() != '..')) {
Expand All @@ -124,10 +123,10 @@ public function getInputHtml($value, ElementInterface $element = null): string
if (count($dirList) > 0) {
$string = '<div class="select"><select name="' . $this->handle . '">';
$string .= '<option value="">Choose a directory</option>';

foreach ($dirList as $entry) {
$selected = ($value === $entry) ? 'selected="selected' : '';
$string .= '<option ' . $selected . ' value="' . $settings['rootPath'] . DIRECTORY_SEPARATOR . $entry . '">' . $entry . '</option>';
$entyVal = $settings['rootPath'] . DIRECTORY_SEPARATOR . $entry;
$selected = ($value === $entyVal ) ? 'selected="selected' : '';
$string .= '<option ' . $selected . ' value="' . $entyVal . '">' . $entry . '</option>';
}
$string .= '</select></div>';
} else {
Expand Down

0 comments on commit 096d4f8

Please sign in to comment.