iceagency/lumberjack-posttypes-acf-fields

Lumberjack 框架的服务提供商,允许您定义自定义文章类型的字段。

1.0.3 2018-07-31 13:45 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:08:49 UTC


README

Latest Stable Version Coverage Status Total Downloads License

Lumberjack 框架的服务提供商,允许您定义自定义文章类型的字段。[链接](https://github.com/Rareloop/lumberjack)

由 The ICE Agency 团队编写和维护。[链接](https://www.theiceagency.co.uk)

请注意,此仓库尚未准备好用于生产。

路线图

  1. 添加对重复字段的支持
  2. 添加对 ACF 提供的所有字段类型的支持
  3. 更新文档

要求

安装

  1. 安装 Lumberjack,请参阅[此处](https://github.com/Rareloop/lumberjack)的指南。

  2. 通过 Composer 安装: composer require iceagency/lumberjack-posttypes-acf-fields

  3. web/app/themes/lumberjack/config/app.php 中添加提供者

    'providers' => [
        ...
        IceAgency\Lumberjack\Providers\PostTypeFieldsServiceProvider::class,
        ...
    ]
    

入门

  1. web/app/themes/lumberjack/app/config/posttypes.php 中注册您的文章类型

    'register' => [
        ...
        App\PostTypes\YourPostType::class,
        ...
    ]
    
  2. web/app/themes/lumberjack/app/PostTypes/YourPostType.php 中创建您的文章类型类

  3. HasACFFields 接口添加到您的文章类型

    use IceAgency\Lumberjack\Interfaces\HasAcfFields;
    
    class YourPostType extends Post implements HasAcfFields
    {
        ...
    }
    
  4. 对于您需要使用的每个字段类型,请确保在您的文章类型类顶部包含相关的类,例如在此示例中

    use IceAgency\Lumberjack\AcfFields\TextField;
    use IceAgency\Lumberjack\AcfFields\TextAreaField;
    
  5. 添加一个静态方法来定义您的字段配置,如下所示

    public static function getFieldConfig() : array
    {
        return [
            TextField::create('text_field_name')
                ->withLabel('Text Field Label')
                ->isRequired(),
            TextAreaField::create('textarea_field_name')
                ->withLabel('Textarea Field Label')
        ]
    }
    

字段类型

  • 文本: IceAgency\Lumberjack\AcfFields\TextField
  • 文本区域: IceAgency\Lumberjack\AcfFields\TextField
  • 图片: IceAgency\Lumberjack\AcfFields\ImageField
  • 是/否: IceAgency\Lumberjack\AcfFields\BoolField
  • 复选框: IceAgency\Lumberjack\AcfFields\CheckboxField
  • 电子邮件: IceAgency\Lumberjack\AcfFields\EmailField
  • 文件: IceAgency\Lumberjack\AcfFields\FileField
  • 数字: IceAgency\Lumberjack\AcfFields\NumberField
  • 页面链接: IceAgency\Lumberjack\AcfFields\PageLinkField
  • 密码: IceAgency\Lumberjack\AcfFields\PasswordField
  • 文章对象: IceAgency\Lumberjack\AcfFields\PostObjectField
  • 单选按钮: IceAgency\Lumberjack\AcfFields\RadioField
  • 选择: IceAgency\Lumberjack\AcfFields\SelectField
  • URL: IceAgency\Lumberjack\AcfFields\UrlField
  • 用户: IceAgency\Lumberjack\AcfFields\UserField
  • 所见即所得: IceAgency\Lumberjack\AcfFields\WysiwygField

通用字段方法

create($name)

创建一个具有给定名称的字段,这是使用 ACF 的 get_field() 函数检索数据时使用的名称

withLabel($label)

设置字段在 WordPress 管理区域的标签。

isRequired()

使字段为必填项。

withInstructions($instructions)

为字段添加说明。

withDefaultValue($default_value)

为字段添加默认值。

withPlaceholder($placeholder)

用于设置 WordPress 管理区域内字段的占位符。(请注意,这仅适用于文本、文本区域、数字、电子邮件、URL 和密码)

单个字段方法

文本

withMaxLength($max_length)

设置文本的最大长度(接受整数)。

isReadOnly()

将字段设置为只读。

isDisabled()

将字段设置为禁用。

文本区域

withMaxLength($max_length)

设置文本的最大长度(接受整数)。

isReadOnly()

将字段设置为只读。

isDisabled()

将字段设置为禁用。

图片

withMinWidth($min_width)

以像素为单位设置最小宽度(接受整数)

withMinHeight($min_height)

以像素为单位设置最小高度(接受整数)

withMaxWidth($max_width)

设置最大宽度(以像素为单位)(接受整数)

withMaxHeight($max_height)

设置最大高度(以像素为单位)(接受整数)

withMinSize($min_size)

设置最小大小(以MB为单位)(接受整数)

withMaxSize($max_size)

设置最大大小(以MB为单位)(接受整数)

withMimeTypes($mime_types)

以逗号分隔的MIME类型列表(例如:"image/png,image/jpg,image/gif")

withReturnFormat($return_format)

设置返回的格式,从"array","url"或"id"中选择

True/False

withMessage($message)

设置与复选框一起显示的消息

复选框

withOptions($options)

设置要显示的复选框项,$options 应该是一个数组,其中键是复选框值,值代表复选框的标签。

文件

withMinSize($min_size)

设置最小大小(以MB为单位)(接受整数)

withMaxSize($max_size)

设置最大大小(以MB为单位)(接受整数)

withMimeTypes($mime_types)

以逗号分隔的MIME类型列表(例如:"image/png,image/jpg,image/gif")

withReturnFormat($return_format)

设置返回的格式,从"array","url"或"id"中选择

数字

withMin($min)

设置最小数字(接受整数)。

withMax($max)

设置最大数字(接受整数)。

withStep($step)

设置点击箭头时跳过的数字数量(接受整数)。

页面链接

withPostTypes($post_types)

应该作为选项给出的帖子类型数组。

withTaxonomy($taxonomy)

包含给定选项的分类法数组。

allowNull()

设置是否可以将选择设置为null。

isMultiple()

允许用户选择多个选项。

帖子对象

withPostTypes($post_types)

应该作为选项给出的帖子类型数组。

withTaxonomy($taxonomy)

包含给定选项的分类法数组。

allowNull()

设置是否可以将选择设置为null。

isMultiple()

允许用户选择多个选项。

withReturnFormat($return_format)

选择应返回的格式,在"object"和"id"之间选择

单选按钮

withOptions($options)

设置要显示的复选框项,$options 应该是一个数组,其中键是复选框值,值代表复选框的标签。

选择

withOptions($options)

设置要显示的复选框项,$options 应该是一个数组,其中键是复选框值,值代表复选框的标签。

allowNull()

设置是否可以将选择设置为null。

isMultiple()

允许用户选择多个选项。

用户

withRoles($roles)

设置应出现在选择中的用户角色。需要是用户角色数组。

allowNull()

设置是否可以将选择设置为null。

isMultiple()

允许用户选择多个选项。

所见即所得(WYSIWYG)

withTabs($tab_perference)

设置在所见即所得中应显示哪些选项卡,在"all"、"visual"和"text"之间选择

withToolbar($toolbar_perference)

设置在所见即所得中应显示哪个工具栏,在"full"和"basic"之间选择

canUploadMedia()

设置用户是否可以使用所见即所得上传媒体