Skip to content

Commit 49b23b6

Browse files
committed
Initial commit
0 parents  commit 49b23b6

15 files changed

+562
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Asset Folder Field Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## 1.0.0 - 2020-02-26
8+
### Added
9+
- Initial release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Alexander M. Korn
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Ryan Whitney
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
![Plugin Icon: A folder with a dropdown arrow on a blue background.](./src/icon.svg)
2+
3+
# Server Path Field plugin for Craft CMS 3.x
4+
5+
A dropdown field that lets you select a directory in the public webroot of a Craft CMS site. It's possible to define a root path (within the webroot) and filter directories.
6+
7+
## Requirements
8+
9+
This plugin requires Craft CMS 3.0.0 or later.
10+
11+
## Installation
12+
13+
To install the plugin, follow these instructions.
14+
15+
1. Open your terminal and go to your Craft project:
16+
17+
cd /path/to/project
18+
19+
2. Then tell Composer to load the plugin:
20+
21+
composer require amkdev/server-path-field
22+
23+
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Server Path Field.
24+
25+
## Server Path Field Overview
26+
27+
Server Path Field adds a custom FieldType to Craft CMS called Server Path. This lets you choose from any direcotry found in the webroot, which then returns it as string.
28+
29+
This plugin is pretty basic, but gets the job done.
30+
31+
## Disclaimer
32+
33+
This plugin is distributed free of charge under the MIT License. The author is not responsible for any data loss or issues resulting from use of the plugin.
34+
35+
## Special Thanks
36+
37+
This plugin is based on the Asset Folder Field plugin by Ryan Whitney.
38+
39+
This plugin was made with the help of assets and code found within the CraftCMS community. These folks are **not** affiliated with this plugin in any way, though I greatly appreciate their contributions to the community.
40+
41+
Thanks to [@mmikkel](https://github.com/mmikkel/IncognitoField-Craft3), whose [IncognitoField](https://github.com/mmikkel/IncognitoField-Craft3) plugin was heavily referenced and used as a general framework when using this plugin. 🎉
42+
43+
Thanks to [@anubarak](https://github.com/Anubarak), whose [StackExchange answer](https://craftcms.stackexchange.com/a/24011) provided the basis for the folder finding logic. 🎉
44+
45+
And thanks to [@landon](https://thenounproject.com/landan), whose [folder icon](https://thenounproject.com/search/?q=folder&i=1594035) was used in the logo. 🎉

composer.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "amkdev/server-path-field",
3+
"description": "A dropdown field that lets you select an server path within the webroot.",
4+
"type": "craft-plugin",
5+
"version": "1.0.0",
6+
"keywords": [
7+
"craft",
8+
"cms",
9+
"craftcms",
10+
"craft-plugin",
11+
"server path field"
12+
],
13+
"support": {
14+
"docs": "https://github.com/amkdev/server-path-field/blob/master/README.md",
15+
"issues": "https://github.com/amkdev/server-path-field/issues"
16+
},
17+
"license": "MIT",
18+
"authors": [
19+
{
20+
"name": "Alexander M. Korn",
21+
"homepage": "https://github.com/amkdev"
22+
}
23+
],
24+
"require": {
25+
"craftcms/cms": "^3.0.0"
26+
},
27+
"repositories": [
28+
{
29+
"type": "composer",
30+
"url": "https://asset-packagist.org"
31+
}
32+
],
33+
"autoload": {
34+
"psr-4": {
35+
"amkdev\\serverpathfield\\": "src/"
36+
}
37+
},
38+
"extra": {
39+
"name": "Server Path Field",
40+
"handle": "server-path-field",
41+
"schemaVersion": "1.1.1",
42+
"hasCpSettings": false,
43+
"hasCpSection": false,
44+
"changelogUrl": "https://github.com/amkdev/server-path-field/blob/master/CHANGELOG.md",
45+
"class": "amkdev\\serverpathfield\\ServerPathField"
46+
}
47+
}

src/ServerPathField.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Server Path Field plugin for Craft CMS
4+
*
5+
* ServerPathField
6+
*
7+
* @author Various
8+
* @link https://github.com/amkdev
9+
*/
10+
11+
namespace amkdev\ServerPathField;
12+
13+
use amkdev\serverpathfield\fields\ServerPathFieldType;
14+
15+
use Craft;
16+
use craft\base\Plugin;
17+
use craft\services\Fields;
18+
use craft\events\RegisterComponentTypesEvent;
19+
20+
use yii\base\Event;
21+
22+
/**
23+
* Class ServerPathField
24+
*
25+
* @author Various
26+
* @package ServerPathField
27+
*
28+
*/
29+
class ServerPathField extends Plugin
30+
{
31+
// Static Properties
32+
// =========================================================================
33+
34+
/**
35+
* @var ServerPathField
36+
*/
37+
public static $plugin;
38+
39+
// Public Methods
40+
// =========================================================================
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function init()
46+
{
47+
parent::init();
48+
self::$plugin = $this;
49+
50+
// Register our fields
51+
Event::on(
52+
Fields::class,
53+
Fields::EVENT_REGISTER_FIELD_TYPES,
54+
function(RegisterComponentTypesEvent $event) {
55+
$event->types[] = ServerPathFieldType::class;
56+
}
57+
);
58+
59+
Craft::info(
60+
Craft::t(
61+
'server-path-field',
62+
'{name} plugin loaded',
63+
['name' => $this->name]
64+
),
65+
__METHOD__
66+
);
67+
}
68+
69+
// Protected Methods
70+
// =========================================================================
71+
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Server Path Field plugin for Craft CMS
4+
*
5+
* ServerPathField Field Asset
6+
*
7+
* @author Various
8+
* @link https://github.com/amkdev
9+
*/
10+
11+
namespace amkdev\serverpathfield\assetbundles\serverpathfield;
12+
13+
use Craft;
14+
use craft\web\AssetBundle;
15+
use craft\web\assets\cp\CpAsset;
16+
17+
/**
18+
* @author
19+
* @package ServerPathField
20+
* @since
21+
*/
22+
class ServerPathFieldFieldAsset extends AssetBundle
23+
{
24+
// Public Methods
25+
// =========================================================================
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
public function init()
31+
{
32+
$this->sourcePath = "@amkdev/serverpathfield/assetbundles/serverpathfield/dist";
33+
34+
$this->depends = [
35+
CpAsset::class,
36+
];
37+
38+
$this->js = [
39+
'js/serverpathfield.js',
40+
];
41+
42+
$this->css = [
43+
'css/serverpathfield.css',
44+
];
45+
46+
parent::init();
47+
}
48+
}

src/assetbundles/serverpathfield/dist/css/ServerPathField.css

Whitespace-only changes.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Server Path Field plugin for Craft CMS
3+
*
4+
* ServerPathField Field JS
5+
*
6+
* @author Various
7+
* @link https://github.com/amkdev
8+
*/
9+
10+
;(function ( $, window, document, undefined ) {
11+
12+
var pluginName = "ServerPathField",
13+
defaults = {
14+
};
15+
16+
// Plugin constructor
17+
function Plugin( element, options ) {
18+
this.element = element;
19+
20+
this.options = $.extend( {}, defaults, options) ;
21+
22+
this._defaults = defaults;
23+
this._name = pluginName;
24+
25+
this.init();
26+
}
27+
28+
Plugin.prototype = {
29+
30+
init: function(id) {
31+
var _this = this;
32+
33+
$(function () {
34+
35+
/* -- _this.options gives us access to the $jsonVars that our FieldType passed down to us */
36+
37+
});
38+
}
39+
};
40+
41+
// A really lightweight plugin wrapper around the constructor,
42+
// preventing against multiple instantiations
43+
$.fn[pluginName] = function ( options ) {
44+
return this.each(function () {
45+
if (!$.data(this, "plugin_" + pluginName)) {
46+
$.data(this, "plugin_" + pluginName,
47+
new Plugin( this, options ));
48+
}
49+
});
50+
};
51+
52+
})( jQuery, window, document );

0 commit comments

Comments
 (0)