Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b5992a8
feat: Add site config extension.
sig-lani Jun 18, 2020
e3d6074
feat: Add yml to apply site config extension.
sig-lani Jun 18, 2020
91932a7
feat: Modify afterCallActionHandler function.
sig-lani Jun 18, 2020
0af768f
style: Reword EnvBarOverride field label.
sig-lani Jun 18, 2020
c7719f1
feat: Add disable_auto_insert config variable check and $EnvBar templ…
sig-lani Jun 18, 2020
8315c4f
docs: Update documentation and changelog.
sig-lani Jun 18, 2020
cd967cb
Update README.md
sig-lani Jun 19, 2020
e2cbb18
Update EnvBarExtension.php documentation
lanifield Jun 21, 2020
0d6a63b
Update README.md
lanifield Jun 21, 2020
afc85c7
fix: Correct type issues in DocBlocks
lanifield Jun 21, 2020
a885b30
Merge pull request #10 from signify-nz/feature/scrutinizer-quality-te…
sig-lani Jun 23, 2020
399f2a3
fix: Remove whitespaces found at end of lines
sig-lani Jun 23, 2020
9741731
Update travis.yml
sig-lani Jun 23, 2020
437f0d8
refactor: Modify site config field from EnvBarOverride to EnvBarDisplay
sig-lani Jul 10, 2020
ef0e452
test: Add tests for CMS display control functionality
sig-lani Jul 10, 2020
187f91a
test: Modify list of tests run by travis
sig-lani Jul 10, 2020
588acff
fix: Change EnvBarDisplay default value to 1
sig-lani Aug 24, 2020
df30167
fix: Change EnvBarDisplay default value to true
sig-lani Aug 24, 2020
0fcd61c
fix: Modify test to show or hide EnvBar via CMS checkbox
sig-lani Aug 24, 2020
f26f2e1
chore: Use stable versions of SilverStripe in CI
ChloeSartorelli Dec 1, 2020
6857783
chore: Update PHP versions in travis config.
ChloeSartorelli Dec 1, 2020
f294b64
chore: Require stable version of postgresql
ChloeSartorelli Dec 1, 2020
15647db
Merge pull request #13 from GuySartorelli/patch-2
sig-lani Dec 1, 2020
88d468d
Merge branch 'feat/control-display-via-cms-settings' of https://githu…
sig-lani Dec 15, 2020
d358920
fix: Modify testDisplayDisabled to request draft staged page.
sig-lani Dec 15, 2020
6965238
feat: Allow plugins for composer 2.
sig-steve Apr 28, 2022
97c8d23
test: Fix SiteConfig tests.
sig-steve Apr 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ services:

env:
global:
- TRAVIS_NODE_VERSION="10"
- COMPOSER_ROOT_VERSION=4.3.x-dev

matrix:
include:
- php: 5.6
env: DB=MYSQL RECIPE_VERSION=4.3.x-dev PHPUNIT_TEST=1
- php: 7.0
env: DB=PGSQL RECIPE_VERSION=4.3.x-dev PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL RECIPE_VERSION=4.3.x-dev PHPUNIT_TEST=1 PHPCS_TEST=1
env: DB=MYSQL RECIPE_VERSION=~4.3.0 PHPUNIT_TEST=1 PHPCS_TEST=1
- php: 7.2
env: DB=PGSQL RECIPE_VERSION=4.4.x-dev PHPUNIT_TEST=1
env: DB=PGSQL RECIPE_VERSION=~4.4.0 PHPUNIT_TEST=1
- php: 7.3
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_COVERAGE_TEST=1
env: DB=MYSQL RECIPE_VERSION=^4
- php: 7.4
env: DB=MYSQL RECIPE_VERSION=^4 PHPUNIT_COVERAGE_TEST=1

before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
Expand All @@ -30,11 +28,11 @@ before_script:

- composer validate
- composer require --no-update silverstripe/recipe-cms:"$RECIPE_VERSION"
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.1.x-dev; fi
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:^2.1.0; fi
- composer install --prefer-source --no-interaction --no-progress --optimize-autoloader --verbose --profile

script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/EnvBarExtensionTest.php; fi
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi

Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Changelog

1.0.0 (2020-02-03)
- Initial release
1.1.0 (2020-06-18)
- Add override to settings to disable automatic frontend display
- Add yml config and template variable to enable developer repositioning

1.0.0 (2020-05-26)
- Initial release

(2020-02-03)
- Initial development
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/signify-nz/silverstripe-environmentindicator.svg?branch=master)](https://travis-ci.org/signify-nz/silverstripe-environmentindicator)
[![codecov](https://codecov.io/gh/signify-nz/silverstripe-environmentindicator/branch/master/graph/badge.svg)](https://codecov.io/gh/signify-nz/silverstripe-environmentindicator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/signify-nz/silverstripe-environmentindicator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/signify-nz/silverstripe-environmentindicator/?branch=master)

# Environment Indicator

Expand All @@ -23,9 +23,20 @@ __Composer:__

## Documentation

No further configuration is required.
No further configuration is required, however customisation is optional.

Customisation can be achieved by editing the EnvBar.ss template or the envbar- .js and .css files. Functional tests are available in the tests directory. These will need to be updated if you modify the template.
### Developer

To disable the automatic placement of the bar as the first element of the body (if, for example, you have a fixed notification bar in your theme design), please add the following to a yml file in your site _config directory:

```yml
Signify\EnvBar\Extensions\EnvBarExtension:
disable_auto_insert: true
```

You can then use the template variable `$EnvBar` in a more suitable position (recommended placement is in the Page.ss file or an include that is visible sitewide).

Customisation of the content and/or appearance can be achieved by editing the EnvBar.ss template or the envbar- .js and .css files. Functional tests are available in the tests directory. These will need to be updated if you modify the template.

* [Changelog](CHANGELOG.md)
* [Contributing](CONTRIBUTING.md)
Expand All @@ -34,7 +45,10 @@ Customisation can be achieved by editing the EnvBar.ss template or the envbar- .

## Usage

This module performs an informative function only. No special usage instructions are available.
This module performs an informative function only.

There is a setting in the CMS to disable the bar from being visible on the frontend.
![Override Setting](docs/en/img/Override_Setting.png)

![Live Published Anonymous](docs/en/img/Live_Pub_Anon.png)
![Live Published Editor](docs/en/img/Live_Pub_Edit.png)
Expand Down
5 changes: 4 additions & 1 deletion _config/environmentindicatorconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ After: "framework/*, cms/*"
---
SilverStripe\CMS\Controllers\ContentController:
extensions:
- Signify\EnvBar\Extensions\EnvBarExtension
- Signify\EnvBar\Extensions\EnvBarExtension
SilverStripe\SiteConfig\SiteConfig:
extensions:
- Signify\EnvBar\Extensions\EnvBarSiteConfigExtension
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
}
},
"config": {
"process-timeout": 600
"process-timeout": 600,
"allow-plugins": {
"composer/installers": true,
"silverstripe/vendor-plugin": true
}
},
"prefer-stable": true,
"minimum-stability": "dev"
Expand Down
Binary file added docs/en/img/Override_Setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 55 additions & 22 deletions src/Extensions/EnvBarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Signify\EnvBar\Extensions;

use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Requirements;

Expand All @@ -20,24 +22,25 @@
* and user access (member permissions) and returns values to populate the
* EnvBar.
*
* It also contains methods to modify the HTTPResponse before and after the
* @see SilverStripe\Control\RequestHandler inserting the CSS and HTML required
* to produce the EnvBar.
* It also contains methods to modify the @see SilverStripe\Control\HTTPResponse
* before and after the @see SilverStripe\Control\RequestHandler
* inserting the CSS and HTML required to produce the EnvBar.
*
* @package Signify\EnvBar\Extensions
* @author Lani Field <lani.field@signify.co.nz>
* @version 1.0.0
* @author Lani Field <lani.field@signify.co.nz>
* @version 1.0.1
*
* @param HTTPRequest $request
* @return HTTPResponse $result with the EnvBar CSS and HTML inserted.
* @param \SilverStripe\Control\HTTPRequest $request
* @return \SilverStripe\Control\HTTPResponse $result
* with the EnvBar CSS and HTML inserted.
*/
class EnvBarExtension extends DataExtension
{
/**
* Load the CSS requirement.
*
* @param HTTPRequest $request
* @param string $action
* @param \SilverStripe\Control\HTTPRequest $request
* @param string $action
* @return void
* @see SilverStripe\Control\RequestHandler::handleAction
*/
Expand All @@ -47,19 +50,28 @@ public function beforeCallActionHandler($request, $action)
}

/**
* Rewrite the HTML of the viewed page to insert the EnvBar.
* Rewrite the HTML of the viewed page to insert the EnvBar if the
* two conditions (display and auto-insert enabled) have been met.
*
* @param HTTPRequest $request
* @param string $action
* @param DBHTMLText $result from the original RequestHandler
* @return HTTPResponse $result with the EnvBar CSS and HTML inserted
* @param \SilverStripe\Control\HTTPRequest $request
* @param string $action
* @param \SilverStripe\ORM\FieldType\DBHTMLText $result
* from the original RequestHandler
* @return \SilverStripe\ORM\FieldType\DBHTMLText $result
* with the EnvBar HTML inserted
* @see SilverStripe\Control\RequestHandler::handleAction
*/
public function afterCallActionHandler($request, $action, $result)
{
if (!($result instanceof DBHTMLText)) {
// Check if display is turned on in the CMS
if (!SiteConfig::current_site_config()->EnvBarDisplay) {
return $result;
}
// Check if automatic placement has been turned off in a _config yml
if (Config::inst()->get(__CLASS__, 'disable_auto_insert')) {
return $result;
}

$html = $result->getValue();
$envBar = $this->generateEnvBar()->getValue();
$html = preg_replace(
Expand All @@ -68,14 +80,17 @@ public function afterCallActionHandler($request, $action, $result)
$html
);
$result->setValue($html);

return $result;
}

/**
* Check the environment type.
*
* @return string "dev" if the site is in dev mode, "test" if the site is
* in test mode (e.g. QA or UAT), "live" otherwise (e.g. Production)
* @return string
* "dev" if the site is in dev mode,
* "test" if the site is in test mode (e.g. QA or UAT),
* "live" otherwise (e.g. Production)
*/
public function getEnvironment()
{
Expand All @@ -91,9 +106,10 @@ public function getEnvironment()
/**
* Check the version of the page being viewed.
*
* @return string "published" if it is the current live version in this
* environment, "draft" if it is a modified or unpublished version,
* "not staged" otherwise
* @return string
* "published" if it is the current live version in this environment,
* "draft" if it is a modified or unpublished version,
* "not staged" otherwise
*/
public function getPageStatus()
{
Expand All @@ -109,7 +125,9 @@ public function getPageStatus()
/**
* Check whether CurrentUser has access to edit pages.
*
* @return boolean "true" if the user can edit pages, "false" otherwise
* @return boolean
* "true" if the user can edit pages,
* "false" otherwise
*/
public function getCanAccess()
{
Expand All @@ -122,10 +140,25 @@ public function getCanAccess()
}

/**
* Generate the HTML to inject using the EnvBar.ss template.
* Get EnvBar HTML as a template variable.
*
* @return DBHTMLText
*/
public function getEnvBar()
{
if (
Config::inst()->get(__CLASS__, 'disable_auto_insert')
&& SiteConfig::current_site_config()->EnvBarDisplay
) {
return $this->generateEnvBar();
}
}

/**
* Generate the HTML to inject using the EnvBar.ss template.
*
* @return \SilverStripe\ORM\FieldType\DBHTMLText
*/
private function generateEnvBar()
{
return $this->owner->renderWith('EnvBar');
Expand Down
49 changes: 49 additions & 0 deletions src/Extensions/EnvBarSiteConfigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Signify\EnvBar\Extensions;

use BadMethodCallException;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;

/**
* Add override boolean to the site config settings
* @see SilverStripe\SiteConfig\SiteConfig
* to allow CMS admin to disable automatic display of the Environment Indicator
* bar on the frontend pages.
*
* @author Lani Field <lani.field@signify.co.nz>
* @version 1.1.0
* @package Signify\EnvBar\Extensions
*/
class EnvBarSiteConfigExtension extends DataExtension
{
/**
* Add override column to SiteConfig db record.
*
* @var string[]
*/
private static $db = [
'EnvBarDisplay' => 'Boolean',
];

/**
* Add Checkbox field for override value to new Environment Indicator tab
* in CMS Settings.
*
* @param FieldList $fields
* @return void
* @throws BadMethodCallException
*/
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldsToTab('Root.EnvironmentIndicator', [
CheckboxField::create(
'EnvBarDisplay',
'Display the environment indicator bar?'
)->setDescription('Check to show the environment indicator bar on'
. ' all pages being viewed in this environment.'),
]);
}
}
1 change: 1 addition & 0 deletions tests/EnvBarExtensionTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SilverStripe\SiteConfig\SiteConfig:
Title: Test site
CanViewType: Anyone
CanEditType: LoggedInUsers
EnvBarDisplay: true

SilverStripe\Security\Group:
admins:
Expand Down
Loading