Source of file SDLTSiteConfigExtension.php
Size: 13,189 Bytes - Last Modified: 2021-12-23T10:08:54+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/SDLTSiteConfigExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 | <?php /** * Site Config Extension for SDLT Tool * * @category SilverStripe_Project * @package SDLT * @author Catalyst I.T. SilverStripe Team 2018 <silverstripedev@catalyst.net.nz> * @copyright NZ Transport Agency * @license BSD-3 * @link https://www.catalyst.net.nz */ namespace NZTA\SDLT\Extension; use GraphQL\Type\Definition\ResolveInfo; use SilverStripe\GraphQL\Scaffolding\Interfaces\ScaffoldingProvider; use SilverStripe\GraphQL\Scaffolding\Scaffolders\SchemaScaffolder; use SilverStripe\ORM\DataExtension; use SilverStripe\Assets\Image; use SilverStripe\Forms\FieldList; use SilverStripe\AssetAdmin\Forms\UploadField; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\HTMLEditor\HtmlEditorField; use SilverStripe\Forms\TextField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\Forms\FormField; use SilverStripe\Forms\EmailField; use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Security\Group; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\NumericField; /** * Site Config Extension for SDLT Tool */ class SDLTSiteConfigExtension extends DataExtension implements ScaffoldingProvider { /** * @var array */ private static $db = [ 'AlertEnabled' => 'Boolean', 'AlertMessage' => 'HTMLText', 'NoScriptAlertMessage' => 'HTMLText', 'AlternateHostnameForEmail' => 'Varchar(255)', 'FromEmailAddress' => 'Varchar(255)', 'DataExportEmailSubject' => 'Text', 'DataExportEmailBody' => 'HTMLText', 'EmailSignature' => 'HTMLText', 'NumberOfDaysForApprovalReminderEmail' => 'Int', // Customisation Config 'FooterCopyrightText' => 'Text', ]; /** * Has One relationships * * @var array */ private static $has_one = [ 'Logo' => Image::class, 'AuthLogo' => Image::class, 'LoginHeroImage' => Image::class, // Customisation Config 'HomePageBackgroundImage' => Image::class, 'QuestionnairePdfHeaderImage' => Image::class, 'QuestionnairePdfFooterImage' => Image::class, 'FavIcon' => Image::class, 'SecurityArchitectGroup' => Group::class, 'CisoGroup' => Group::class ]; /** * Ownership relationships - automatically publish these records * * @var array */ private static $owns = [ 'Logo', 'AuthLogo', 'LoginHeroImage', 'HomePageBackgroundImage', 'QuestionnairePdfHeaderImage', 'QuestionnairePdfFooterImage', 'FavIcon', ]; /** * CMS fields for siteconfig extension * * @param FieldList $fields fields passed into the extension * @return void */ public function updateCMSFields(FieldList $fields) { // Main Tab $fields->dataFieldByName('Title') ->setDescription('This title is displayed in the HTML <title>, and at the top of most screens.'); $fields->removeByName('Tagline'); // "Main" tab $fields->addFieldToTab( 'Root.Main', LiteralField::create( 'MainIntro', '<p class="message notice">Configure general SDLT settings.</p>' ), 'Title' ); // "Access" tab $fields->addFieldToTab( 'Root.Access', LiteralField::create( 'AlertIntroAccess', '<p class="message notice">Configure who can do what within the SDLT.</p>' ), 'CanViewType' ); // "Email" tab $fields->addFieldsToTab( 'Root.Email', [ LiteralField::create( 'AlertIntroEmail', '<p class="message notice">Configure some aspects of how email is treated in the system.</p>' ), TextField::create( 'AlternateHostnameForEmail', 'Alternate hostname for email' )->setDescription( 'This setting is used to configure an alternate hostname for use in outgoing email messages. It is' . ' intended to be used in situations where the hostname of the server differs from the URL users' . ' use to log into the website, such as a proxy server or a web application firewall (WAF).' ), ToggleCompositeField::create( 'DataExportEmailToggle', 'Data Export Email', [ EmailField::create( 'FromEmailAddress' ), HtmlEditorField::create( 'EmailSignature' ) ->setRows('3'), TextField::create( 'DataExportEmailSubject', 'Email Subject' ), HtmlEditorField::create( 'DataExportEmailBody', 'Email Body' ) ->setRows(10) ->setDescription( '<p class="message notice">You can use the following variable substitutions in the email body and subject:<br/><br/>' . '<b>{$dataClass}</b> For exported data class<br/>' . '<b>{$dataName}</b> For exported data name<br/>' . '<b>{$fileName}</b> For file name<br/>' . '<b>{$userName}</b> For user name<br/>' . '<b>{$userEmail}</b> For user email.</p>' ) ] ) ] ); // "Images" tab $fields->addFieldsToTab( 'Root.Images', [ LiteralField::create( 'ImagesIntro', '<p class="message notice">Configure how various images and logos appear to users.</p>' ), UploadField::create('AuthLogo', 'Login screen logo') ->setDescription('This is the logo that appears within the authentication screens.'), UploadField::create('Logo', 'Header Logo') ->setDescription('This is the logo that appears in the header. The default dimensions for the logo are 370px x 82px.'), UploadField::create('LoginHeroImage', 'Login screen background image') ->setDescription('This is the background image shown on the login screen.'), UploadField::create('HomePageBackgroundImage', 'Home Page Background Image') ->setDescription('This is the background image shown on the home-screen.'), UploadField::create('FavIcon', 'FavIcon') ->setDescription('This is the site favicon shown on front-end browser tabs. Require: .ico format, dimensions of 16x16, 32x32, or 48x48.') ->setAllowedExtensions(['ico']), ] ); // "Alert" tab. $fields->addFieldsToTab( 'Root.Alert', [ LiteralField::create( 'AlertIntro', '<p class="message notice">Check the box below, to display ' .'a global banner-message along the top of each screen.</p>' ), CheckboxField::create( 'AlertEnabled', 'Alert Enabled' ), HtmlEditorField::create( 'AlertMessage', 'Alert Message' ) ->setRows(5), HtmlEditorField::create( 'NoScriptAlertMessage', 'Javascript disabled Alert Message' )->setRows(5) ] ); // "PDF" tab $fields->addFieldsToTab( 'Root.PDF', [ LiteralField::create( 'PDFIntro', '<p class="message notice">Configure how generated PDFs appear to users.</p>' ), UploadField::create('QuestionnairePdfHeaderImage'), UploadField::create('QuestionnairePdfFooterImage') ] ); // "Footer" tab $fields->addFieldsToTab( 'Root.Footer', [ LiteralField::create( 'FooterIntro', '<p class="message notice">Configure how the global footer appears to users.</p>' ), TextField::create( 'FooterCopyrightText', 'Footer Text' ) ] ); //workflow tab $fields->addFieldsToTab( 'Root.Workflow Emails', [ DropdownField::create( 'SecurityArchitectGroupID', 'Security Architect Group', Group::get()->map('ID', 'Title') ) ->setDescription( 'These people will receive emails when a submission is sent for approval once first submitted.' ), DropdownField::create( 'CisoGroupID', 'Ciso Group', Group::get()->map('ID', 'Title') ) ->setDescription( 'These users in this group will receive emails when a submission is sent for approval once the above security architect/analysts group has approved.' ), // reminder email LiteralField::create( 'ReminderEmails', '<p class="message notice">Reminder Emails </p>' ), NumericField::create( 'NumberOfDaysForApprovalReminderEmail', 'Resend approval emails' ) ->setDescription( 'Set the number of days to resend the approval emails to the Business Owner (if applicable) and CISO groups.' ), ] ); } /** * @param SchemaScaffolder $scaffolder generic comment * @return SchemaScaffolder */ public function provideGraphQLScaffolding(SchemaScaffolder $scaffolder) { $scaffolder ->type(SiteConfig::class) ->addFields([ 'Title', 'FooterCopyrightText', 'LogoPath', 'HomePageBackgroundImagePath', 'PdfHeaderImageLink', 'PdfFooterImageLink', ]) ->operation(SchemaScaffolder::READ) ->setName('readSiteConfig') ->setUsePagination(false) ->setResolver(function ($object, array $args, $context, ResolveInfo $info) { $config = SiteConfig::current_site_config(); return [$config]; }) ->end(); return $scaffolder; } /** * onBeforeWrite * * @return void */ public function onBeforeWrite() { if ($this->owner->AlternateHostnameForEmail) { //strip whitespace characters from both sides of the URL $this->owner->AlternateHostnameForEmail = trim($this->owner->AlternateHostnameForEmail); //also strip / just in case it's there. $this->owner->AlternateHostnameForEmail = rtrim($this->owner->AlternateHostnameForEmail, '/'); //we're now guaranteed to have a URL without a trailing slash so if we add one now it's consistently present $this->owner->AlternateHostnameForEmail .= '/'; } } /** * Called from provideGraphQLScaffolding(). * * @return string */ public function getLogoPath() : string { return (string) $this->owner->Logo()->Link(); } /** * Called from provideGraphQLScaffolding(). * * @return string */ public function getHomePageBackgroundImagePath() : string { return (string) $this->owner->HomePageBackgroundImage()->Link(); } /** * Called from provideGraphQLScaffolding(). * * @return string */ public function getPdfHeaderImageLink() : string { return (string) $this->owner->QuestionnairePdfHeaderImage()->Link(); } /** * Called from provideGraphQLScaffolding(). * * @return string */ public function getPdfFooterImageLink() : string { return (string) $this->owner->QuestionnairePdfFooterImage()->Link(); } } |