-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: make announcement selectable via extension on SiteConfig
- Add silverstripe/standards - Update test suite
- Loading branch information
Showing
8 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
Name: browser-update | ||
--- | ||
SilverStripe\SiteConfig\SiteConfig: | ||
extensions: | ||
- DNADesign\BrowserUpdate\Extension\SiteConfigExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace DNADesign\BrowserUpdate\Extension; | ||
|
||
use DNADesign\BrowserUpdate\Model\Announcement; | ||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Forms\DropdownField; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\SiteConfig\SiteConfig; | ||
|
||
/** | ||
* @extends Extension<SiteConfig> | ||
* | ||
* @method Announcement BrowserAnnouncement() | ||
* @property int $BrowserAnnouncementID | ||
* | ||
* @see \DNADesign\BrowserUpdate\Tests\Extension\SiteConfigExtensionTest | ||
*/ | ||
class SiteConfigExtension extends Extension | ||
{ | ||
/** | ||
* @var array<class-string<DataObject>> | ||
*/ | ||
private static array $has_one = [ | ||
'BrowserAnnouncement' => Announcement::class, | ||
]; | ||
|
||
protected function updateCMSFields(FieldList $fields): void | ||
{ | ||
$fields->addFieldsToTab('Root.BrowserUpdate', [ | ||
DropdownField::create('BrowserAnnouncementID', 'Active browser announcement') | ||
->setDescription('This announcement will display on all pages unless dismissed by the user.') | ||
->setSource(Announcement::get()->map()) | ||
->setEmptyString('None'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace DNADesign\BrowserUpdate\Tests\Extension; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Forms\DropdownField; | ||
use SilverStripe\Forms\FormField; | ||
use SilverStripe\SiteConfig\SiteConfig; | ||
|
||
final class SiteConfigExtensionTest extends SapphireTest | ||
{ | ||
/** | ||
* @return array<array{string, class-string<FormField>}> | ||
*/ | ||
public function updateCMSFieldsProvider(): array | ||
{ | ||
return [ | ||
['BrowserAnnouncementID', DropdownField::class], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider updateCMSFieldsProvider | ||
* @param class-string<FormField> $fieldClass | ||
*/ | ||
public function testUpdateCMSFields(string $fieldName, string $fieldClass): void | ||
{ | ||
$fields = SiteConfig::current_site_config()->getCMSFields(); | ||
$field = $fields->dataFieldByName($fieldName); | ||
|
||
$this->assertInstanceOf($fieldClass, $field); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters