fromholdio / silverstripe-relativeurlfield
1.1.0
2024-05-06 18:36 UTC
Requires
- silverstripe/cms: ~4.1 || ~5.0
This package is auto-updated.
Last update: 2024-09-06 19:35:24 UTC
README
类似于 SiteTreeURLSegmentField,除了
- 没有
SiteTree
依赖 - 可在任何地方使用 - 设置
BaseURL
(或使用Director::absoluteBaseURL
作为后备) - 用户可以输入 URL 别名 - 或完整的 URL 路径(通过字段设置切换)
- 用户可以选择是否包含查询字符串(通过字段设置切换)
- 基于 URL 别名(或完整路径),执行碰撞检查,并在值中添加
-n
计数器 - 默认情况下,使用 BaseURL 和提供的 URL 别名/路径,检查与网站树中页面的碰撞
- Base URL 总是显示给用户,包括在输入相对 URL 路径时,以便用户看到上下文并理解他们应该输入 URL 的哪一部分
仅在 SS5 上测试,但应也能在 SS4 上工作。
使用简单直接
$field = RelativeURLField::create('FieldName', 'Field Title'); // available toggles/settings $field->setBaseURL(); // The base URL that the user-entered value is relative to. Defaults to Director::absoluteBaseURL(). $field->setBaseURLBySiteTree(); // Pass a SiteTree object here, to use it's AbsoluteLink as the BaseURL (useful for Multisites for example, pass the Site object). $field->setIsQueryStringAllowed(); // Can user include a query string? (will be stripped if not) $field->setisFullPathAllowed(); // Can user enter a path with multiple slugs? (else their value will have '/'s removed) $field->setHelpText(); // Special chars text // manage collision checks $field->addCollisionCheck($key, ?$callable); // pass a string Key and either implement check via $callable, or use Key via extension hook $field->removeCollisionCheck($key); // remove by Key. 'sitetree' is enabled by default.