iamntz/carbon-rest-multiselect
Composer 安装命令:
composer require iamntz/carbon-rest-multiselect
包简介
carbon rest multiselect
关键字:
README 文档
README
Prov
Adds a rest_multiselect field type to Carbon Fields 3. Install using Composer:
composer require iamntz/carbon-rest-multiselect:^3.0
For Carbon Fields 2 (legacy):
composer require iamntz/carbon-rest-multiselect:^2.0
Usage:
Field::make('rest_multiselect', 'my-name', 'My Label') ->set_endpoint( 'base', get_rest_url( null, 'wp/v2/posts' ) ) ->set_endpoint( 'search', get_rest_url( null, 'wp/v2/posts/?search=' ) ) ->set_endpoint( 'fetch_by_id', get_rest_url( null, 'wp/v2/posts/?include=' ) ) // endpoint used to look up for saved posts ->set_value_key('id') // the REST response key to use as a value in the select ->set_selection_limit(999) // what's the maximum amount of selectable items. ->set_label_key('title.rendered') // OR ->set_label_key(['date', 'title.rendered']) // the REST response key to use as a label in the select
ALL endpoints are required!
If needed, you can specify nonces (or extra variables) directly on the endpoint url: get_rest_url( null, "wp/v2/posts/?nonce={$generated_nonce}&search=" )
set_label_key
This one is as extensible as it gets: you can use either a string, a dotted string (so it will search for children) or an array that will be combined in to a nicely formatted string.
You can also set some transformations on labels:
->set_label_key(['title.rendered|substring:0,10|toUpperCase', 'date|wrap(%label%)']);
Basically any JS prototype function that's callable on a string.
There is an exception: you can use a wrap transform that will ... well, wrap your label.
set_selection_limit
You can set what's the maximum amount of selectable items. This will work ad infinitum, without any limit or warning (just like regular HTML select tag works). So any new selection will be appended to the existing items, therefore if the limit is reached, then the first element of the selection is lost, the new element will be appended.
Basically if you add ->set_selection_limit(1) you make the field to behave just like a regular HTML select.
Return Value
The field will always return an array of items, with values picked form the key set via set_value_key('id') method.
Credits
Heavily inspired by @elvishp2006's awesome plugin. Unfortunately, there is no way of extending that one to allow multiple selection without breaking compatibility (different storage and such).
Support me
You can get hosting, donate or be my patreon.
License
The code is released under MIT license.
iamntz/carbon-rest-multiselect 适用场景与选型建议
iamntz/carbon-rest-multiselect 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 273 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「carbon-field」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iamntz/carbon-rest-multiselect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamntz/carbon-rest-multiselect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iamntz/carbon-rest-multiselect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Carbon Fields extension, that adds a Icon field type.
Carbon Fields extension, that adds a SmartLink field type.
Carbon Fields extension, that adds a Rich Text field type with no media.
A basic Carbon Fields extension, that adds support for Number type field.
Carbon Fields extension, that adds a URL picker field type.
Carbon Fields extension, that adds a Radio_Image_Enhanced field type.
统计信息
- 总下载量: 273
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2018-09-11