jakxnz / silverstripe-announce
显示 SilverStripe 的公告消息
Requires
- php: >=5.6
- silverstripe/framework: ^4
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-29 06:02:33 UTC
README
向 SilverStripe 的页面控制器和视图发送公告。可用于生成普通消息、模态框、警报和突出显示。
可以堆叠多个公告。
公告可以模板化以匹配如 Bootstrap 之类的组件库。
安装
注意:对于 SilverStripe 3 中的类似模块,请考虑使用 axyr/silverstripe-flashmessage
要求
- SilverStripe >= 4.0
- PHP >= 5.6
Composer
composer require jakxnz/silverstripe-announce
SilverStripe
执行 dev/build?flush=all 以刷新你的 SilverStripe 项目。
简介
使用标题、标题、内容、页脚和操作创建公告。控制是否应该存储以供以后响应。控制是否应该可关闭。
公告保留在 StilverStripe 的 Controller 中,并存储在公告存储中(默认为 $_SESSION)。
每个公告都通过 SilverStripe Controller 扩展提供给视图。
一次只能堆叠一组公告。
可以替换公告存储为实现了 AnnouncementStoreInterface 的自定义类;
用法
排队一个新的公告
Announcements::queue('AnnouncementName', 'Announcement Title', 'This is an announcement message');
Accounments::queue() 将接受所有 Announcement 参数
排队一个现有的公告
$msg = Announcement::create('AnnouncementName', 'Announcement Title', 'This is an announcement message');
Announcements::queue($msg);
获取所有当前公告
$announcements = Announcements::get();
按名称获取公告
Announcements::get()->getByName('AnnouncementName');
按类型获取公告
Announcements::get()->getByType(Announcement::DEFAULT);
清除公告队列
Announcements::clear();
在模板的顶层显示公告
<% if $Announcements %>
$Announcements
<% end_if %>
自定义公告
所有选项的示例
use CodeCraft\Announce\Model\Announcement;
use CodeCraft\Announce\Model\Action;
...
$announcement = Announcement::create(
$name = 'AnnouncementName',
$title = 'Announcement Title',
$content = 'A plain or html string',
$heading = 'A plain or html string',
$footer = 'A plain or html string',
$actions = [
Action::create(
$name = 'ActionName',
$content = 'A plain or html string',
$type = Action::BUTTON,
$link = 'https://www.google.com/',
$extraClass = 'btn btn-primary'
)
],
$type = Announcement::DEFAULT
)
// Store announcement
->setStoreable(true)
// Dismissable
->setDismissable(true)
// Name
->setName('AnnouncementName')
// Title
->setTitle('Announcement Title')
->setTitle('<p>Announcement Title</p>')
// Content
->setContent('Announcement body')
->setContent('<p>Announcement body</p>')
// Heading
->setHeading('Announcement heading')
->setHeading('<p>Announcement heading</p>')
// Footer
->setFooter('Announcement footer')
->setFooter('<p>Announcement footer</p>')
// Action
->addAction(
Action::create()
->setName('ActionName')
->setContent('OK')
->setContent('<p>OK</p>')
->setType(Action::BUTTON)
->setLink('http://www.google.com/')
->addExtraClass('btn btn-primary')
->setAttribute('title', 'A helpful title')
)
// Type
->setType(Announcement::DEFAULT)
// Template
->setTemplate('templates\CodeCraft\Announce\Announcement');
公告存储
访问公告存储
Announcements::get()->getStore();
预期公告将被存储为 array
设置可存储
公告默认存储,以便它们可以包含在下一次相关响应中。
定义公告是否应该存储
$msg = Announcement::create('AnnouncementName', 'Un-stored Announcement', 'This announcement is not stored')
->setStoreable(false);
自定义公告模板
通过 覆盖模板 为所有公告设置自定义模板
为任何公告设置自定义模板
$msg = Announcement::create('AnnouncementName', 'Announcement Title', 'This is an announcement message')
->setTemplate('MyTemplate');
覆盖模板
公告模板
通过覆盖 templates/CodeCraft/Announce/Model/Announcement 来覆盖所有公告操作的默认模板
公告动作模板
通过覆盖 templates/CodeCraft/Announce/Model/Action 来覆盖所有公告操作的默认模板
阅读更多关于 SilverStripe 的信息 模板继承
按名称的公告
每个公告名称都是唯一的。通过名称调用公告
后端
Announcements::get()->getByName('AnnouncementName');
模板
$Announcements.ByName('AnnouncementName');
按类型的公告
使用可用的类型之一设置任何公告的类型;Announcement::DEFAULT、Announcement::MODAL、Announcement::TRAY、Announcement::MESSAGE 或 Announcement::CALLOUT。
$msg = Announcement::create('Name')->setType(Announcement::MODAL);
按类型调用公告
后端
Announcements::get()->getByType(Announcement::MODAL);
模板
$Announcements.ByType('modal');
可以是 'default'、'modal'、'tray'、'message'、'callout'
限制
- 没有任何 CMS 可编辑功能
许可
修改后的 BSD 许可证
版权所有 (c) 2018, Jackson Darlow
阅读 许可证
待办事项
- 测试
- 添加冗余,以处理公告存储在公告堆栈之前的情况
- 添加禁用存储的方法
- 创建数据库公告存储
- 创建Redis公告存储
- 将公告类型常量替换为面向对象模型
- 创建电子邮件公告类型
- 为针对用户的公告创建公告历史记录
- 标记用户查看的公告
- 添加CMS可编辑公告,类似于nzta/silverstripe-sitebanner
- 版本CMS可编辑公告