Utils and helpers for SilverStripe CMS.
SilverStripe CMS ^4.0
composer require arillo/silverstripe-utils
This module is a bundle of classes to alter functionality in the CMS.
Attach Arillo\Utils\HiddenLeftAndMain
to any LeftAndMain subclass you want to hide, e.g. in config.yml
:
SilverStripe\CampaignAdmin\CampaignAdmin:
extensions:
- Arillo\Utils\HiddenLeftAndMain
If you use silverstripe-fluent
with TractorCow\Fluent\Extension\FluentFilteredExtension
you can add Arillo\Utils\FluentFilteredHelper
to your translated DataObject and it will attach all Locales on record creation and deletes locale entries on record deletion. In config, e.g. add:
MyDataObject:
# will create locale entries for this record on first save, default: true
auto_create_locales: true
# will delete locale entries on record deletion, default: false
auto_delete_locales: true
extensions:
- 'TractorCow\Fluent\Extension\FluentFilteredExtension'
- 'Arillo\Utils\FluentFilteredHelper'
With Arillo\Utils\FluentHelper::force_delete
you can improve UX in CMS while record deletion. At the moment Fluent forces you to delete a page in each Locale, to remove it from SiteTree. Example usage:
<?php
use SilverStripe\CMS\Model\SiteTree;
use Arillo\Utils\FluentHelper;
class Page extends SiteTree
{
public function onBeforeDelete()
{
parent::onBeforeDelete();
FluentHelper::force_delete($this); // insert this
}
}
Some unsorted functions.
Remove campaign-related actions from Menu:
<?php
use SilverStripe\CMS\Model\SiteTree;
use Arillo\Utils\CMS;
class Page extends SiteTree
{
public function getCMSActions()
{
return CMS::remove_campaign_actions(parent::getCMSActions());
}
}
Thumbnail helper function for gridfield usage:
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Assets\Image;
use Arillo\Utils\CMS;
class MyDataObject extends DataObject
{
private static $has_one = [ 'Image' => Image::class ];
private static $summary_fields = [ 'Thumbnail' => 'Image' ];
public function getThumbnail()
{
return CMS::thumbnail($this->Image());
}
}
Display a message in CMS (bootstrap alert style). E.g.:
<?php
use SilverStripe\CMS\Model\SiteTree;
use Arillo\Utils\AlertField;
class Page extends SiteTree
{
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
AlertField::create('PageInfo', "Page type: {$this->ClassName}", 'dark')
, 'Title');
return $fields;
}
}
Add this extension to a DataObject to make it sortable:
use SilverStripe\ORM\DataObject;
use Arillo\Utils\SortableDataObject;
class MyDataObject extends DataObject
{
private static $extensions = [
SortableDataObject::class,
];
}
You can apply GridFieldOrderableRows
to the managing GridField
with the following helper function:
use Arillo\Utils\SortableDataObject;
...
..
.
SortableDataObject::make_gridfield_sortable($gridField);
There are 3 global helper functions for template usage:
Is DEV: <% if $IsDev %>yes<% else %>no<% end_if %> <br>
Is TEST: <% if $IsTest %>yes<% else %>no<% end_if %> <br>
Is PROD: <% if $IsProd %>yes<% else %>no<% end_if %> <br>
in php:
Arillo\Utils\Env::is_dev();
Arillo\Utils\Env::is_prod();
Arillo\Utils\Env::is_test();
Helper for pages & templates functions.
Adds PageInstance
and PageControllerInstance
template methods. Most helpfull in case there should be only one instance of a SiteTree subclass:
<%-- access a page by classname in templates --%>
$PageInstance(SomeSiteTreeSubClassName).Title
$PageInstance(SomeSiteTreeSubClassName).Link
<%-- e.g. render a Form from a diffrent controller --%>
$PageControllerInstance(SomeSiteTreeSubClassName).Form
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem