SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Create pages, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Ability to create pages. Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Archive pages, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Ability to archive pages. Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Publish authored pages (limited to blog posts), 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
[User Notice] Missing localisation default for key Ability to publish any page that you are an author of (currently only applies to blog posts). Requires the "Access to 'Pages' section" permission
GET /dev/tasks/i18nTextCollectorTask
Line 747 in /home/bradc/public_html/vendor/silverstripe/framework/src/i18n/TextCollection/i18nTextCollector.php
trigger_error(Missing localisation default for key Ability to publish any page that you are an author of (currently only applies to blog posts). Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Unpublish authored pages (limited to blog posts), 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
[User Notice] Missing localisation default for key Ability to unpublish any page that you are an author of (currently only applies to blog posts). Requires the "Access to 'Pages' section" permission
GET /dev/tasks/i18nTextCollectorTask
Line 747 in /home/bradc/public_html/vendor/silverstripe/framework/src/i18n/TextCollection/i18nTextCollector.php
trigger_error(Missing localisation default for key Ability to unpublish any page that you are an author of (currently only applies to blog posts). Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Publish any page, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
[User Notice] Missing localisation default for key Ability to publish any page on the site, regardless of the settings on the Access tab. Requires the "Access to 'Pages' section" permission
GET /dev/tasks/i18nTextCollectorTask
Line 747 in /home/bradc/public_html/vendor/silverstripe/framework/src/i18n/TextCollection/i18nTextCollector.php
trigger_error(Missing localisation default for key Ability to publish any page on the site, regardless of the settings on the Access tab. Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
trigger_error(Missing localisation default for key Unpublish any page, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485
[User Notice] Missing localisation default for key Ability to unpublish any page on the site, regardless of the settings on the Access tab. Requires the "Access to 'Pages' section" permission
GET /dev/tasks/i18nTextCollectorTask
Line 747 in /home/bradc/public_html/vendor/silverstripe/framework/src/i18n/TextCollection/i18nTextCollector.php
trigger_error(Missing localisation default for key Ability to unpublish any page on the site, regardless of the settings on the Access tab. Requires the "Access to 'Pages' section" permission, 1024)
i18nTextCollector.php:747
SilverStripe\i18n\TextCollection\i18nTextCollector->collectFromCode(<?php
namespace Sitelease\OpenCore\Extensions;
use Sitelease\OpenCore\Stripes\Stripe;
use Sitelease\OpenCore\Stripes\NavStripe;
use Sitelease\OpenCore\Stripes\Composite\NavBarCompositeStripe;
use Sitelease\OpenCore\Stripes\ThemeManagerStripe;
use Sitelease\OpenCore\Forms\Fields\YamlConfigGenField;
use SilverStripe\ORM\DB;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\UploadField;
use ErrorException;
use Psr\Log\LoggerInterface;
use Sitelease\OpenCore\Extensions\RemovableExtension;
class OpenCorePageExtension extends RemovableExtension implements PermissionProvider
{
/**
* If true, the stripe manager interface will be
* displayed on this page
*
* @config
*/
private static $display_stripe_interface = true;
/**
* The type of interface that should be rendered
* for stripe management.
*
* Can be "tabs" or "toggles"
*
* @config
*/
private static $stripe_interface_type = "tabs";
/**
* The field to place the stripe manager before
* when rendering it in the CMS
*
* @config
*/
private static $stripe_interface_before_field = "Metadata";
private static $db = [
'Summary' => 'HTMLText',
'ReadMoreText' => 'Varchar',
];
/**
* Has_one relationship
* @var array
*/
private static $has_one = [
'FeaturedImage' => Image::class,
'ThemeStylesManager' => ThemeManagerStripe::class,
];
private static $owns = [
'FeaturedImage',
];
/**
* Has_many relationship
* @var array
*/
// private static $has_many = [
// 'Stripes' => Stripe::class,
// ];
/**
* Get the Mobile Menu from the first Nav Stripe with
* the mobile menu enabled
*
* @return DBHTMLText|false A HTML markup fragment
*/
public function getMobileMenu()
{
$owner = $this->owner;
$navBarStripes = $owner->Stripes()->filter(array(
"ClassName" => NavBarCompositeStripe::class,
));
if ($navBarStripes->exists()) {
$navBarStripe = $navBarStripes->first();
if ($navBarStripe->isDataLinked()) {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->DataLinkedToID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
} else {
$navStripes = NavStripe::get()->filter(array(
"ParentCompositeStripeID" => $navBarStripe->ID,
"EnableMobileMenu" => 1,
));
if ($navStripes->exists()) {
$navStripe = $navStripes->first();
return $navStripe->getMobileMenu();
}
}
}
return false;
}
public function updateCMSFields(FieldList $fields)
{
$owner = $this->owner;
$featuredImageField = UploadField::create(
'FeaturedImage',
'Featured Image'
)
->addExtraClass('stacked')
->setDescription('The image to be displayed in card displays');
$summaryField = HTMLEditorField::create(
'Summary',
'Custom Summary'
)
->addExtraClass('stacked');
$readMoreTextField = TextField::create(
'ReadMoreText',
'Read More Button Text',
)
->setDescription("The text to display on the button that points to this page. Used in card displays");
$extraContent = ToggleCompositeField::create(
'ExtraContent',
_t(__CLASS__ . '.ExtraContent', 'Add Additional Content for Card and Info Displays'),
[
$featuredImageField,
$summaryField,
$readMoreTextField,
]
);
$extraContent->setHeadingLevel(4);
if ($owner->Summary) {
$extraContent->setStartClosed(false);
}
$fields->removeByName("Summary");
$fields->removeByName("ReadMoreText");
$fields->removeByName("FeaturedImage");
$fields->insertAfter('Content', $extraContent);
return $fields;
}
/**
* Update CMS fields in the "Settings" tab
*
* @author Benjamin Blake (sitelease.ca)
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields)
{
if ($this->extensionRemoved()) {
return;
}
$owner = $this->owner;
$config = $owner->config();
// If the stripe manager display is enabled and a Stripe Manager is connected
if ($config->get("display_stripe_interface")) {
// If Admin user add YAML generation field
if (Permission::check("ADMIN")) {
$yamlGenField = YamlConfigGenField::create("GenerateYamlConfig", $owner)
->setDescription("Allows you to generate out YAML configurations for this page's"
." stripes, as they are currently configured (but without content)");
$fields->addFieldsToTab(
'Root.Settings',
$yamlGenField
);
}
}
}
/**
* Event handler called before writing to the database.
*
* @uses DataExtension->onAfterWrite()
*/
// public function onBeforeWrite()
// {
// $owner = $this->owner;
// // Skip if disabled, or if duplicated from another page
// if ($this->extensionRemoved() || $owner->isDuplicate) {
// return;
// }
// $stripeConfig = $owner->getStripesConfig();
// }
////////////////////////////////////////
// SiteTree Batch Actions //
////////////////////////////////////////
/**
* Returns true if this page can have a reusable stripe added to it
* via the batch add reusable stripe action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canAddReusableStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Creates a new stripe and connects it to the passed in
* reusable stripe before relating it to this page
*
* Used by the "AddReusableStripe" batch action
*
* @param Stripe $reusableStripe The reusable stripe to connect to this page
* @param boolean $overwrite If true, any existing stripe with the same name will be overwritten
* @return boolean
*/
public function doAddReusableStripe(Stripe $reusableStripe, bool $overwrite = false)
{
$owner = $this->owner;
$owner->invokeWithExtensions('onBeforeAddReusableStripe', $owner);
// Check for an existing stripe with the same name in the manager
$existingStripe = $owner->getStripe($reusableStripe->InternalName);
if ($existingStripe) {
if ($overwrite) {
// Remove existing stripe and replace it with the new stripe,
// but keep the sort order
$extraData = $owner->Stripes()->getExtraData("Stripes", $existingStripe->ID);
$reusableStripe->addToPage($owner, true, [
"SortOrder" => $extraData["SortOrder"],
]);
$existingStripe->removeFromPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
} else {
// Return false if we are not to overwrite this stripe
return false;
}
} else {
$reusableStripe->addToPage($owner);
$owner->invokeWithExtensions('onAfterAddReusableStripe', $reusableStripe);
}
return true;
}
/**
* Returns true if this page can have stripes removed from it
* via the batch stripe removal action
*
* Checks to ensure the user has edit permissions
*
* @return boolean
*/
public function canRemoveStripe()
{
$owner = $this->owner;
return ($owner->canEdit());
}
/**
* Remove a stripe of a type with a particular name
* if it exists in this page
*
* Used by the "RemoveStripe" batch action
*
* NOTE: This takes into account reusable stripe's and won't delete them,
* but instead remove the relationship to the manager
*
* @todo Implement the $forceDelete option
* @param string $stripeTitle The interface name of the stripe to remove from this page's
* stripe manager
* @param string $stripeClass The class of the stripe to be removed (this will ensure we
* don't accidentally remove stripes)
* @param boolean $forceDelete If true, the stripe will be deleted even if its used by other
* locals (NOT IMPLEMENTED)
* @return boolean
*/
public function doRemoveStripe(string $stripeTitle, string $stripeClass, bool $forceDelete = false)
{
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
..., /home/bradc/public_html/vendor/sitelease/sl-open-core/src/Extensions/OpenCorePageExtension.php, SilverStripe\Core\Manifest\Module)
i18nTextCollector.php:485