storypioneers/kirby-selector

该软件包已被废弃,不再维护。没有建议的替代软件包。
该软件包的最新版本(v1.5.3)没有提供许可证信息。

安装: 774

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 26

类型:kirby-plugin

v1.5.3 2018-01-25 08:54 UTC

This package is not auto-updated.

Last update: 2020-08-22 07:12:27 UTC


README

此附加面板字段用于 Kirby 2,允许您在蓝图中使用直观的替代文件选择字段。

作者数字故事讲述先驱 feat. Jonas Doebertin

许可证GNU GPL v3.0

Screenshot

安装

kirby-selector 目录复制或链接到 site/plugins/ composer require storypioneers/kirby-selector 使用 Kirby CLI kirby plugin:install storypioneers/kirby-selector

使用

在您的蓝图中

安装后,只需将 selector 字段添加到您的蓝图中,并设置一些选项(如有必要)。

fields:
	postimage:
		label: Main Post Image
		type:  selector
		mode:  single
		types:
			- image
fields:
	attachments:
		label: Post Attachments
		type:  selector
		mode:  multiple
		types:
			- all

在您的模板/控制器/模型中

根据设计,选择器字段仅存储所选文件的 文件名。如果您需要访问文件的完整路径或其他属性/文件对象的函数,您必须首先将文件名转换为完整的文件对象。

单选模式

当您在单选模式下使用选择器字段时,获取完整文件对象的方法相当简单。只需用您的基于选择器的字段名称替换 yourselectorfield 即可。

	// Convert the filename to a full file object
	$file = $page->yourselectorfield()->toFile();

	// Use the file object
	echo $file->url();

多选模式

在多选模式下,选择器字段存储一个以逗号分隔的文件名列表,基于您选择了多少个文件。要将此列表转换为功能齐全的文件集合(类似于 $page->files()),您需要更多的代码。

	// Transform the comma-separated list of filenames into a file collection
	$filenames = $page->yourselectorfield()->split(',');
	if(count($filenames) < 2) $filenames = array_pad($filenames, 2, '');
	$files = call_user_func_array(array($page->files(), 'find'), $filenames);

	// Use the file collection
	foreach($files as $file)
	{
		echo $file->url();
	}

选项

该字段提供了一些选项,可以直接从您的蓝图中设置每个字段的选项。

模式

定义字段将工作在的模式。可能的值是 singlemultiple

  • single:使用 single 模式时,字段的复选框将像一组单选按钮一样工作,允许您只选择一个文件。如果您想指定文章的主要图片,这很有用。

  • multiple:此选项允许您在单个文件选择器字段中选择多个文件。所选文件将存储为以逗号分隔的列表。

类型

定义文件选择器字段显示的文件类型。可能的值是 allimagevideoaudiodocumentarchivecodeunknown。您可以指定任何数量的这些类型。

fields:
	attachments:
		label: Post Attachments
		type:  selector
		mode:  multiple
		types:
			- image
			- video
			- audio
			- document

排序

文件将按照文件名升序(a-z)显示。然而,此选项允许您更改默认的排序行为。您可以按文件大小、尺寸、类型等进行排序。无数可能的值包括sortfilenamesizewidthheighttypemodifiedratio。您还可以按任何自定义的 文件字段 进行排序。值sort将确保文件按照您在面板文件部分通过 拖放 指定的顺序显示。

fields:
	featured:
		label: Featured Image
		type:  selector
		mode:  single
		sort:  size
		types:
			- image

flip

此选项允许您反转使用sort选项指定的排序顺序。您可以将其设置为truefalse

autoselect

此选项允许您告诉选择器在没有任何其他文件被选中时自动选择列表中的第一个、最后一个或所有文件。可能的值有none(默认)、firstlastall

fields:
	featured:
		label:      Featured Image
		type:       selector
		mode:       single
		sort:       filename
		autoselect: first
		types:
			- image

filter

此选项允许您设置文件名过滤器。这可以是简单的字符串或完整的正则表达式。只有与过滤器字符串或正则表达式匹配的文件将显示在选择器字段中。您可以将其设置为任何字符串,如background.min.jslarge,或正则表达式,如/\.((png)|(jpe?g))/i

fields:
	featured:
		label:  Page Background Image
		type:   selector
		mode:   single
		filter: background
		types:
			- image

仅显示文件名中包含background一词的图像文件。

fields:
	featured:
		label:  Page Background Image
		type:   selector
		mode:   single
		filter: /\.((png)|(jpe?g))/i

使用正则表达式仅显示.jpg.jpeg.png文件。

size

size选项允许您限制选择器字段的高度并使其可滚动。最初仅显示指定数量的文件。这可以是数字或auto(选择器字段将适应完整文件列表的高度)。

fields:
	featured:
		label: Page Background Image
		type:  selector
		mode:  single
		size:  4