Skip to content

Commit

Permalink
refactor - SlideImage - move CMS fields to onBeforeUpdateCMSFields() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Aug 27, 2018
1 parent 13a18a0 commit f94fb8a
Showing 1 changed file with 52 additions and 50 deletions.
102 changes: 52 additions & 50 deletions src/SlideImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,57 +102,59 @@ class SlideImage extends DataObject implements PermissionProvider
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName([
'ShowSlide',
'SortOrder',
'PageID',
'Image',
]);

// Name
$fields->dataFieldByName('Name')
->setTitle(
_t(__CLASS__ . '.NAME', 'Name')
)
->setDescription(
_t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
);

// Headline
$fields->dataFieldByName('Headline')
->setTitle(
_t(__CLASS__ . '.HEADLINE', 'Headline')
)
->setDescription(
_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
);

// Description
$fields->dataFieldByName('Description')
->setTitle(
_t(__CLASS__ . '.DESCRIPTION', 'Description')
)
->setDescription(
_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
);

// Page link
$fields->dataFieldByName('PageLinkID')
->setTitle(
_t(__CLASS__ . '.PAGE_LINK', "Choose a page to link to:")
);
$this->beforeUpdateCMSFields(function ($fields) {
$fields->removeByName([
'ShowSlide',
'SortOrder',
'PageID',
'Image',
]);

// Name
$fields->dataFieldByName('Name')
->setTitle(
_t(__CLASS__ . '.NAME', 'Name')
)
->setDescription(
_t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
);

// Headline
$fields->dataFieldByName('Headline')
->setTitle(
_t(__CLASS__ . '.HEADLINE', 'Headline')
)
->setDescription(
_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
);

// Description
$fields->dataFieldByName('Description')
->setTitle(
_t(__CLASS__ . '.DESCRIPTION', 'Description')
)
->setDescription(
_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
);

// Page link
$fields->dataFieldByName('PageLinkID')
->setTitle(
_t(__CLASS__ . '.PAGE_LINK', "Choose a page to link to:")
);

// Image
$image = UploadField::create(
'Image',
_t(__CLASS__ . '.IMAGE', 'Image')
)->setFolderName('Uploads/SlideImages');

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

$fields->insertAfter($image, 'Description');
});

// Image
$image = UploadField::create(
'Image',
_t(__CLASS__ . '.IMAGE', 'Image')
)->setFolderName('Uploads/SlideImages');

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

$fields->insertAfter($image, 'Description');
$fields = parent::getCMSFields();

$this->extend('updateSlideImageFields', $fields);

Expand Down

0 comments on commit f94fb8a

Please sign in to comment.