blackdoor/silverstripe-display-logic
Composer 安装命令:
composer require blackdoor/silverstripe-display-logic
包简介
Allows assignment of conditions for display and hide of specific form fields based on client side behavior.
README 文档
README
Description
The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior.
Example usage
<?php $products->displayIf("HasProducts")->isChecked(); $products->displayIf("Products")->isAnyOf(['product1', 'product2', 'product3']); $sizes->hideUnless("ProductType")->isEqualTo("t-shirt") ->andIf("Price")->isGreaterThan(10); $payment->hideIf("Price")->isEqualTo(0); $shipping->displayIf("ProductType")->isEqualTo("furniture") ->andIf() ->group() ->orIf("RushShipping")->isChecked() ->orIf("ShippingAddress")->isNotEmpty() ->end();
Available comparison functions
- isEqualTo
- isNotEqualTo
- isGreaterThan
- isLessThan
- contains
- startsWith
- endsWith
- isEmpty
- isNotEmpty
- isBetween
- isChecked
- isNotChecked()
- hasCheckedOption
- hasCheckedAtLeast
- hasCheckedLessThan
- IsIn
Available display conditions
- displayIf()
- displayUnless()
- hideIf()
- hideUnless()
Kitchen sink example
<?php public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab("Root.Test", array( TextField::create("Name","Name of event"), TextField::create("VenueSize","Size of venue"), $refreshments = CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?"), $vendors = CheckboxSetField::create("Vendors","Vendors", Member::get()->map()), $tent = TextField::create("TentSize","You're going to need a tent. What size is it?"), OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')), $internal = DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --"), $external = TextField::create("ExternalLink", "Link to external page"), $label = TextField::create("LinkLabel", "Label for link"), $useEmbed = CheckboxField::create("UseEmbedCode","I have embed code"), $embed = TextareaField::create("EmbedCode","Enter the embed code.") )); $refreshments->displayIf("VenueSize")->isGreaterThan(100); $vendors->displayIf("Refreshments")->isChecked(); $tent->displayIf("Vendors")->hasCheckedAtLeast(3); $internal->displayIf("LinkType")->isEqualTo("internal"); $external->displayIf("LinkType")->isEqualTo("external"); $label->displayIf("LinkType")->isEqualTo("internal")->orIf("LinkType")->isEqualTo("external"); $useEmbed->displayIf("LinkType")->isEqualTo("external"); $embed->displayIf("UseEmbedCode")->isChecked() ->orIf() ->group() ->orIf("ExternalLink")->contains("youtube.com") ->orIf("ExternalLink")->contains("vimeo.com") ->end(); return $fields; }
Kitchen sink example, with chaining
<?php use UncleCheese\DisplayLogic\Wrapper; //... public function getCMSFields() { $f = parent::getCMSFields(); $f->addFieldsToTab("Root.Test", array( TextField::create("Name","Name of event"), TextField::create("VenueSize","Size of venue"), CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?") ->displayIf("VenueSize")->isGreaterThan(100)->end(), CheckboxSetField::create("Vendors","Vendors", Member::get()->map()) ->displayIf("Refreshments")->isChecked()->end(), TextField::create("TentSize","You're going to need a tent. What size is it?") ->displayIf("Vendors")->hasCheckedAtLeast(3)->end(), CheckboxField::create('HasUpload', 'Has an upload'), DisplayLogicWrapper::create( UploadField::create('FileUpload', 'Upload a file'), LiteralField::create('test', '<strong>Keep the file small!</strong>') )->displayIf('HasUpload')->isChecked()->end(), OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')), DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --") ->displayIf("LinkType")->isEqualTo("internal") ->end(), TextField::create("ExternalLink", "Link to external page") ->displayIf("LinkType")->isEqualTo("external") ->end(), Wrapper::create( ReadonlyField::create('URL','Base URL','http://example.com') )->displayIf('LinkType')->isEqualTo('internal')->end(), TextField::create("LinkLabel", "Label for link") ->displayIf("LinkType")->isChecked()->end(), CheckboxField::create("UseEmbedCode","I have embed code") ->displayIf("LinkType")->isEqualTo("external") ->end(), TextareaField::create("EmbedCode","Enter the embed code.") ->displayIf("UseEmbedCode")->isChecked() ->orIf() ->group() ->orIf("ExternalLink")->contains("youtube.com") ->orIf("ExternalLink")->contains("vimeo.com") ->end() )); return $f; }
Dealing with non-standard form fields
Sometimes you will want to wrap display logic around a form field that does not use the standard FormField template, such as GridField or LiteralField. For these cases, you can wrap the form field in UncleCheese\DisplayLogic\Wrapper.
$fields->addFieldToTab("Root.Main", Wrapper::create( LiteralField::create("foo","<h2>Hello</h2>") ) ->displayIf("Title")->isEmpty()->end() );
What's the difference between displayIf() and hideUnless()?
Not much. hideUnless() will take a CSS class that hides it by default before the script loads, to eliminate any flash of form fields before the script has loaded. In general, use displayIf() when the common case is for the field to be hidden, and hideUnless() when the common case is for the field to be shown. The same logic applies to hideIf() and displayUnless().
blackdoor/silverstripe-display-logic 适用场景与选型建议
blackdoor/silverstripe-display-logic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「Forms」 「logic」 「silverstripe」 「display」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blackdoor/silverstripe-display-logic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blackdoor/silverstripe-display-logic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blackdoor/silverstripe-display-logic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ConfirmationField is a form field for Atk14 applications. It's like the BooleanField (checkbox) but the ConfirmationField must be ticked.
Field for number with restricted count of digits and decimal places
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Addons to the display-logic module by UncleCheese
Supercharged text field validation.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-11-29