bigfork/silverstripe-linkset
Composer 安装命令:
composer require bigfork/silverstripe-linkset
包简介
Silverstripe module that allows for easy adding of links to the CMS
README 文档
README
Adds easy to implement link options to the CMS
Features
- Choose from the following options: None, Page, File, URL
- Option to remove fields that don't apply to your implementation
- Can output link straight to template
Installation
$ composer require bigfork/silverstripe-linkset
How to use
You will need to create a $has_one relation on your data object
private static array $has_one = [
'ButtonLink' => LinkSet::class,
];
Then add the LinksetField to your fieldlist
$fields->addFieldsToTab(
'Root.Main',
[
...otherFields,
LinksetField::create($this, 'ButtonLink'),
...otherFields,
]
);
LinkSetField constructor accepts five params:
- DataObject $data - The object the relation is on $this
- string $name - Name of the field should match the relation key
- ?string $title (optional) - Title of the field, will set the heading above the fields
- array $fieldsToRemove (optional) - To remove Title from the list of fields pass in array for example ['Title']. Possible options to remove are:
- Title
- LinkType
- LinkURL
- LinkTarget
- LinkedPageID
- LinkedFile
- array $typesToRemove (optional) - Remove link types from the radio, to remove the option for None pass in array for example ['None']. Possible options to remove are:
- None
- Page
- File
- URL
With all the parameters your code may look like:
$fields->addFieldsToTab(
'Root.Main',
[
...otherFields,
LinksetField::create($this, 'ButtonLink', 'Button link', ['Title'], ['None']),
...otherFields,
]
);
Using in templates
You can output the link in the template by calling the relation
{$ButtonLink.AddExtraClass('button button--primary')}
This will output a simple anchor tag with the all the fields that had been set on the LinkSetField group.
Custom anchors can be done by accessing the fields through the relation as normal
<% with $ButtonLink %>
<a
href="{$Link}
class="button"
<% if $LinkTarget %> target="{$LinkTarget}"<% end_if %>
<% if $LinkType = 'File' %> download<% end_if %>
>
{$Title}
</a>
<% end_with %>
bigfork/silverstripe-linkset 适用场景与选型建议
bigfork/silverstripe-linkset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bigfork/silverstripe-linkset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bigfork/silverstripe-linkset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-08-18