Source of file WidgetSetWidget.php
Size: 4,481 Bytes - Last Modified: 2021-12-23T10:24:18+00:00
/var/www/docs.ssmods.com/process/src/src/Model/WidgetSetWidget.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | <?php namespace WidgetSets\Model; use SilverStripe\Control\Controller; use SilverStripe\Widgets\Model\Widget; use SilverStripe\Versioned\Versioned; /** * Provides some basic functionality for all Widgetset widgets. * * @package WidgetSets * @subpackage Model * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 28.09.2017 * @copyright 2017 pixeltricks GmbH * @license see license file in modules root directory */ class WidgetSetWidget extends Widget { /** * Attributes * * @var array */ private static $db = array( 'ExtraCssClasses' => 'Varchar(255)', ); /** * DB table name * * @var string */ private static $table_name = 'WidgetSetWidget'; /** * Field labels for display in tables. * * @param boolean $includerelations A boolean value to indicate if the labels returned include relation fields * * @return array * * @author Roland Lehmann <rlehmann@pixeltricks.de>, * Sebastian Diel <sdiel@pixeltricks.de> * @since 03.03.2014 */ public function fieldLabels($includerelations = true) { $fieldLabels = array_merge( parent::fieldLabels($includerelations), array( 'ExtraCssClasses' => _t(WidgetSetWidget::class . '.CssFieldLabel', 'Additional CSS class (optional):'), 'FrontTitle' => _t(WidgetSetWidget::class . '.FRONTTITLE', 'Headline'), 'FrontContent' => _t(WidgetSetWidget::class . '.FRONTCONTENT', 'Content'), 'WidgetSetContentLabel' => _t(WidgetSetWidget::class . '.WIDGETSET_CONTENT_FIELD_LABEL', 'Widgets for the content area'), 'WidgetSetSidebarLabel' => _t(WidgetSetWidget::class . '.WIDGETSET_SIDEBAR_FIELD_LABEL', 'Widgets for the sidebar'), 'AssignedWidgets' => _t(WidgetSetWidget::class . '.ASSIGNED_WIDGETS', 'Assigned Widgets'), 'InheritFromParent' => _t(WidgetSetWidget::class . '.INHERIT_FROM_PARENT', 'Inherit widgets from parent'), ) ); $this->extend('updateFieldLabels', $fieldLabels); return $fieldLabels; } /** * Returns an array of field/relation names (db, has_one, has_many, * many_many, belongs_many_many) to exclude from form scaffolding in * backend. * * @return array * * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 19.04.2018 */ public function excludeFromScaffolding() { $excludeFromScaffolding = [ 'Sort', 'Parent', ]; $this->extend('updateExcludeFromScaffolding', $excludeFromScaffolding); return $excludeFromScaffolding; } /** * Returns the title of this widget for display in the WidgetArea GUI. * * @return string * * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 27.03.2012 */ public function CMSTitle() { return _t(static::class . '.CMSTITLE', 'Widget'); } /** * Returns the description of what this template does for display in the * WidgetArea GUI. * * @return string * * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 27.03.2012 */ public function Description() { return _t(static::class . '.DESCRIPTION', 'Widget'); } /** * Automatically publishes the WidgetArea (Parent) after writing. * * @return void * * @author Sebastian Diel <sdiel@pixeltricks.de> * @since 30.04.2018 */ protected function onAfterWrite() { parent::onAfterWrite(); if ($this->Parent()->exists()) { $this->Parent()->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); } } /** * Returns whether this widget is displayed in content area (WidgetSetContent * relation). * * @return boolean */ public function IsInContentArea() { $isInContentArea = false; $currentPage = Controller::curr()->data(); $widgetSet = $this->owner->Parent()->WidgetSet(); $matchingSet = $currentPage->WidgetSetContent()->byID($widgetSet->ID); if ($matchingSet instanceof WidgetSet && $matchingSet->exists()) { $isInContentArea = true; } return $isInContentArea; } } |