Skip to content

Commit

Permalink
Merge pull request #18 from bummzack/ss4-fixes
Browse files Browse the repository at this point in the history
Turn the module into a vendor-module.
  • Loading branch information
Damian Mooyman authored Jan 22, 2018
2 parents fa547b2 + 9716223 commit 53e20e6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 45 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ composer require tractorcow/silverstripe-colorpicker ^4@dev
Here's how you define a DB field to be a color:

```php
private static $db = array(
'BgColor' => 'TractorCow\Colorpicker\Color'
);
private static $db = [
'BgColor' => 'Color'
];
```


Alternatively, you can also use the fully qualified classname.
The best way to do this is to import the class at the top of your PHP file, like so:

use TractorCow\Colorpicker\Color;

In your class, you can then use:

```php
private static $db = [
'BgColor' => Color::class
];
```

That's all... scaffolding will take care of creating the appropriate form-field.

If you use `getCMSFields` to create your fields yourself, you might want to do something like this:
Expand Down
8 changes: 0 additions & 8 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
<?php
/**
* ColorPicker jQuery widget/plugin by http://www.eyecon.ro/colorpicker/
*/

// define colorpicker dir so that the installation doesn't need a fixed directory name
if (!defined('COLORPICKER_DIR')) {
define('COLORPICKER_DIR', basename(__DIR__));
}
7 changes: 7 additions & 0 deletions _config/model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
Name: colorpicker-fieldtypes
After: corefieldtypes
---
SilverStripe\Core\Injector\Injector:
Color:
class: TractorCow\Colorpicker\Color
63 changes: 35 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
{
"name": "tractorcow/silverstripe-colorpicker",
"description": "Color picker field for Silverstripe CMS using the ColorPicker jQuery plugin",
"type": "silverstripe-module",
"keywords": ["silverstripe", "color", "colour"],
"authors": [
{
"name": "Damian Mooyman",
"email": "damian.mooyman@gmail.com"
}
],
"support": {
"issues": "https://github.com/tractorcow/silverstripe-colorpicker/issues"
},
"require": {
"silverstripe/framework": "4.*"
},
"extra": {
"installer-name": "colorpicker",
"branch-alias": {
"dev-master": "4.0.x-dev"
}
},
"autoload": {
"psr-4": {
"TractorCow\\Colorpicker\\": "src/",
"TractorCow\\Colorpicker\\Tests\\": "tests/php/"
}
}
"name": "tractorcow/silverstripe-colorpicker",
"description": "Color picker field for Silverstripe CMS using the ColorPicker jQuery plugin",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"color",
"colour",
"colorpicker"
],
"authors": [
{
"name": "Damian Mooyman",
"email": "damian.mooyman@gmail.com"
}
],
"support": {
"issues": "https://github.com/tractorcow/silverstripe-colorpicker/issues"
},
"require": {
"silverstripe/framework": "^4.0"
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
},
"expose": [
"client"
]
},
"autoload": {
"psr-4": {
"TractorCow\\Colorpicker\\": "src/",
"TractorCow\\Colorpicker\\Tests\\": "tests/php/"
}
}
}
4 changes: 2 additions & 2 deletions src/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Color extends DBVarchar
{
private static $casting = [
'Luminance' => 'Float',
'AlteredColorHSV' => 'TractorCow\Colorpicker\Color'
'AlteredColorHSV' => Color::class
];

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public function __construct($name = null, $options = [])

public function scaffoldFormField($title = null, $params = null)
{
$field = new ColorField($this->name, $title);
$field = ColorField::create($this->name, $title);
return $field;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Forms/ColorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function __construct($name, $title = null, $value = '', $form = null)

public function Field($properties = [])
{
Requirements::javascript('tractorcow/silverstripe-colorpicker: client/javascript/colorfield.js');
Requirements::javascript('tractorcow/silverstripe-colorpicker: client/javascript/colorpicker.js');
Requirements::css('tractorcow/silverstripe-colorpicker: client/css/colorpicker.css');

$this->addExtraClass('colorfield');
Requirements::javascript(COLORPICKER_DIR . '/client/javascript/colorpicker.js');
Requirements::javascript(COLORPICKER_DIR . '/client/javascript/colorfield.js');
Requirements::css(COLORPICKER_DIR . '/client/css/colorpicker.css');

$this->setAttribute('style', sprintf(
'background-image: none; background-color: %s; %s',
Expand Down

0 comments on commit 53e20e6

Please # to comment.