Skip to content

Commit

Permalink
REFACTOR Linkable and oEmbed support (#153)
Browse files Browse the repository at this point in the history
* REFACTOR Linkable and oEmbed support

* UPDATE fixture SlideImage slide 3 SlideType

* UPDATE .travis.yml PHP configuration
  • Loading branch information
muskie9 authored Jan 15, 2019
1 parent 0eed3fa commit e827e0a
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 81 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ env:

matrix:
include:
- php: 7.0
env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.2
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
- php: 5.6
- php: 7.3
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1

before_script:
Expand All @@ -31,4 +31,4 @@ script:
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -t $CODECOV_TOKEN && travis_retry php ocular.phar code-coverage:upload --format=php-clover --access-token=$SCRUT_TOKEN coverage.xml; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -t $CODECOV_TOKEN && travis_retry php ocular.phar code-coverage:upload --format=php-clover --access-token=$SCRUT_TOKEN coverage.xml; fi
Empty file removed _config.php
Empty file.
95 changes: 48 additions & 47 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
{
"name": "dynamic/flexslider",
"description": "Display a FlexSlider on pages of your website",
"authors": [
{
"name": "Dynamic",
"homepage": "http://www.dynamicagency.com",
"email": "[email protected]"
}
],
"keywords": [
"silverstripe",
"flexslider",
"module",
"slideshow",
"slider",
"jquery"
],
"license": "BSD-3-Clause",
"type": "silverstripe-vendormodule",
"require": {
"silverstripe/recipe-cms": "^1.0 || ^4.0",
"silverstripe/asset-admin": "^1.0",
"silverstripe/vendor-plugin": "^1.0",
"symbiote/silverstripe-gridfieldextensions": "^3.0"
},
"require-dev": {
"phpunit/PHPUnit": "^5.7",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"Dynamic\\FlexSlider\\": "src/",
"Dynamic\\FlexSlider\\Test\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"expose": [
"css",
"images",
"thirdparty"
],
"branch-alias": {
"dev-master": "4.0.x-dev"
}
}
"name": "dynamic/flexslider",
"description": "Display a FlexSlider on pages of your website",
"authors": [
{
"name": "Dynamic",
"homepage": "http://www.dynamicagency.com",
"email": "[email protected]"
}
],
"keywords": [
"silverstripe",
"flexslider",
"module",
"slideshow",
"slider",
"jquery"
],
"license": "BSD-3-Clause",
"type": "silverstripe-vendormodule",
"require": {
"silverstripe/recipe-cms": "^1.0 || ^4.0",
"silverstripe/asset-admin": "^1.0",
"silverstripe/vendor-plugin": "^1.0",
"sheadawson/silverstripe-linkable": "^2.0",
"symbiote/silverstripe-gridfieldextensions": "^3.0"
},
"require-dev": {
"phpunit/PHPUnit": "^5.7",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"Dynamic\\FlexSlider\\": "src/",
"Dynamic\\FlexSlider\\Test\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"expose": [
"css",
"images",
"thirdparty"
],
"branch-alias": {
"dev-master": "4.0.x-dev"
}
}
}
116 changes: 100 additions & 16 deletions src/SlideImage.php → src/Model/SlideImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

namespace Dynamic\FlexSlider\Model;

use Sheadawson\Linkable\Forms\EmbeddedObjectField;
use Sheadawson\Linkable\Models\EmbeddedObject;
use Sheadawson\Linkable\Models\Link;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use UncleCheese\DisplayLogic\Forms\Wrapper;

/**
* Class SlideImage
Expand All @@ -17,9 +24,12 @@
* @property string $Headline
* @property string $Description
* @property int $SortOrder
* @property string $SlideType
* @property int $ImageID
* @property int $VideoID
* @property int $PageID
* @property int $PageLinkID
* @property int $LinkID
*/
class SlideImage extends DataObject implements PermissionProvider
{
Expand All @@ -36,29 +46,31 @@ class SlideImage extends DataObject implements PermissionProvider
/**
* @var array
*/
private static $db = array(
private static $db = [
'Name' => 'Varchar(255)',
'Headline' => 'Varchar(255)',
'Description' => 'Text',
'SortOrder' => 'Int',
'ShowSlide' => 'Boolean',
);
'SlideType' => 'Varchar',
];

/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Image' => Image::class,
'Video' => EmbeddedObject::class,
'Page' => \Page::class,
'PageLink' => SiteTree::class,
);
'Link' => Link::class,
];

/**
* @var array
*/
private static $owns = array(
'Image'
);
private static $owns = [
'Image',
];

/**
* @var string
Expand All @@ -80,36 +92,55 @@ class SlideImage extends DataObject implements PermissionProvider
/**
* @var array
*/
private static $summary_fields = array(
private static $defaults = [
'SlideType' => 'Image',
];

/**
* @var array
*/
private static $summary_fields = [
'Image.CMSThumbnail' => 'Image',
'Name' => 'Name',
);
];

/**
* @var array
*/
private static $searchable_fields = array(
private static $searchable_fields = [
'Name',
'Headline',
'Description',
);
];

/**
* @var int
*/
private static $image_size_limit = 512000;

/**
* @var array
*/
private static $slide_types = [
'Image',
'Video',
'Text',
];

/**
* @return \SilverStripe\Forms\FieldList
*/
public function getCMSFields()
{
$this->getViewerTemplates();
$this->beforeUpdateCMSFields(function ($fields) {
$fields->removeByName([
'ShowSlide',
'SortOrder',
'PageID',
'Image',
'SlideType',
'VideoID',
]);

// Name
Expand Down Expand Up @@ -156,7 +187,23 @@ public function getCMSFields()

$image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);

$fields->insertAfter($image, 'Description');
$fields->addFieldToTab(
'Root.Main',
CompositeField::create(FieldList::create(
DropdownField::create('SlideType')
->setSource($this->getTypeSource())
->setTitle('Image or Video'),
Wrapper::create(
$image
)->displayIf('SlideType')->isEqualTo('Image')->end(),
Wrapper::create(
$videoField = EmbeddedObjectField::create('Video')
->setTitle('Video URL')
->setDescription('Supported links: YouTube, Vimeo')
)->displayIf('SlideType')->isEqualTo('Video')->end()
))->setName('MediaFields'),
'Description'
);
});

$fields = parent::getCMSFields();
Expand All @@ -179,12 +226,26 @@ public function validate()
);
}

if (!$this->ImageID) {
$types = $this->getTypeSource();

if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) {
$result->addError(
_t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save')
);
}

if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) {
$result->addError(
_t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save')
);
}

if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) {
$result->addError(
_t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save')
);
}

return $result;
}

Expand All @@ -193,11 +254,11 @@ public function validate()
*/
public function providePermissions()
{
return array(
return [
'Slide_EDIT' => 'Slide Edit',
'Slide_DELETE' => 'Slide Delete',
'Slide_CREATE' => 'Slide Create',
);
];
}

/**
Expand Down Expand Up @@ -243,4 +304,27 @@ public function canView($member = null, $context = [])
{
return true;
}

/**
* @return array
*/
public function getTypeSource()
{
$types = $this->config()->get('slide_types');
asort($types);
return array_combine($types, $types);
}

/**
* @param string $suffix
* @return array
*/
public function getViewerTemplates($suffix = '')
{
$suffix = isset($this->getTypeSource()[$this->SlideType])
? "_{$this->SlideType}"
: '';

return parent::getViewerTemplates($suffix);
}
}
File renamed without changes.
7 changes: 6 additions & 1 deletion tasks/SlidePublishTask.php → src/Task/SlidePublishTask.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\Flexslider\Tasks;
namespace Dynamic\Flexslider\Task;

use Dynamic\FlexSlider\Model\SlideImage;
use SilverStripe\Control\Director;
Expand All @@ -22,6 +22,11 @@ class SlidePublishTask extends BuildTask
*/
protected $description = 'Migration task - pre versioning on SlideImage (3.x)';

/**
* @var string
*/
private static $segment = 'slide-publish-task';

/**
* @var bool
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\flexslider\tasks;
namespace Dynamic\flexslider\Task;

use Dynamic\FlexSlider\ORM\FlexSlider;
use SilverStripe\CMS\Model\SiteTree;
Expand All @@ -26,6 +26,11 @@ class SlideThumbnailNavMigrationTask extends BuildTask
*/
protected $description = 'Set default values for slider after the thumbnail nav update';

/**
* @var string
*/
private static $segment = 'slide-thumbnail-nav-migration-task';

/**
* @var bool
*/
Expand Down
Loading

0 comments on commit e827e0a

Please sign in to comment.