Skip to content

Commit

Permalink
Fix issue #4
Browse files Browse the repository at this point in the history
Code formating and optimization
  • Loading branch information
jelicanin committed Dec 1, 2018
1 parent 12f2013 commit ad66cf0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
File renamed without changes.
48 changes: 24 additions & 24 deletions src/CannedContent.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

namespace Fractas\CannedContent;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\YamlFixture;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DB;
use SilverStripe\Dev\YamlFixture;
use SilverStripe\Security\Permission;

class CannedContent extends DataObject
{
private static $table_name = 'CannedContent';

private static $db = array(
private static $db = [
'Name' => 'Varchar(255)',
'Description' => 'Varchar(255)',
'Content' => 'HTMLText',
'IsActive' => 'Boolean',
);
];

private static $defaults = array(
private static $defaults = [
'IsActive' => true,
);
];

private static $casting = array(
private static $casting = [
'Title' => 'Varchar',
'Link' => 'Varchar',
);
];

private static $indexes = array();
private static $indexes = [];

private static $default_sort = 'ID DESC';

private static $summary_fields = array(
private static $summary_fields = [
'Name',
'IsActive.Nice',
'Created.Nice',
);
];

private static $searchable_fields = array(
private static $searchable_fields = [
'Name' => 'PartialMatchFilter',
);
];

private static $field_labels = array(
private static $field_labels = [
'Name' => 'Name for Canned Content Template',
'IsActive.Nice' => 'Is Active',
'Created.Nice' => 'Created',
);
];

private static $singular_name = 'Canned Content Template';

Expand All @@ -78,12 +78,12 @@ public function getCMSFields()
{
$fields = new FieldList(new TabSet('Root', new Tab('Main')));

$fields->addFieldsToTab('Root.Main', array(
$fields->addFieldsToTab('Root.Main', [
new TextField('Name', 'Name'),
new CheckboxField('IsActive', 'Is Active'),
new TextareaField('Description', 'Description'),
new HtmlEditorField('Content', 'Content'),
));
]);

return $fields;
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public function canDelete($member = null)
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}

public function canCreate($member = null, $context = array())
public function canCreate($member = null, $context = [])
{
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
}
Expand All @@ -130,9 +130,9 @@ public function requireDefaultRecords()
parent::requireDefaultRecords();

$anyrecord = self::get()->first();
if (!$anyrecord) {
if (! $anyrecord) {
$factory = Injector::inst()->create('SilverStripe\Dev\FixtureFactory');
$fixture = YamlFixture::create('vendor/fractas/canned-content/tests/fixtures.yml');
$fixture = YamlFixture::create('vendor/fractas/canned-content/seed/fixtures.yml');
$fixture->writeInto($factory);

DB::alteration_message('Default Canned Content Templates created', 'created');
Expand Down
3 changes: 1 addition & 2 deletions src/CannedContentAdmin.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Fractas\CannedContent;

use SilverStripe\Admin\ModelAdmin;
use Fractas\CannedContent\CannedContent;

class CannedContentAdmin extends ModelAdmin
{
private static $managed_models = [
CannedContent::class
CannedContent::class,
];

private static $url_segment = 'cannedsoup';
Expand Down
12 changes: 6 additions & 6 deletions src/CannedContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ class CannedContentController extends Controller
{
private static $url_segment = 'cannedcontent';

private static $allowed_actions = array(
private static $allowed_actions = [
'templates',
'template',
);
];

public function templates(HTTPRequest $request)
{
$items = CannedContent::get()->where(array('IsActive' => '1'));
$output = array();
$items = CannedContent::get()->where(['IsActive' => '1']);
$output = [];

if ($items->exists()) {
foreach ($items as $item) {
if ($item->exists()) {
$output[] = array(
$output[] = [
'title' => $item->Name,
'url' => $item->Link(),
'description' => isset($item->Description) ? $item->Description : $item->Name,
);
];
}
}
}
Expand Down

0 comments on commit ad66cf0

Please sign in to comment.