fab / vidi
记录的通用列表,具有多种与数据交互的方式,例如高级筛选、行内编辑、批量编辑等。Veni, vidi, vici!
Requires
- php: >=8.0
- typo3/cms-core: ^11
Requires (Dev)
- laravel/pint: ^1.2
- dev-master
- 6.0.0
- 5.x-dev
- 5.3.x-dev
- 5.3.1
- 5.3.0
- 5.2.0
- 5.1.0
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.1
- 4.0.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.1
- 3.0.0
- 2.7.x-dev
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.7
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.x-dev
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- dev-feature/without-objectmanager
- dev-feature/remove-legacy-object-manager
This package is auto-updated.
Last update: 2024-09-12 08:53:11 UTC
README
Vidi for TYPO3 CMS

Vidi代表“多功能且交互式显示”,是一个列表组件的代号,旨在列出各种类型的记录,并具有高级筛选功能。默认情况下,该扩展为FE用户/组提供了两个示例,但可以配置为任何数据类型。
Veni, vidi, vici!
项目和发布信息
项目的首页:https://github.com/fabarea/vidi
稳定版本:http://typo3.org/extensions/repository/view/vidi
Git开发版本
cd typ3conf/ext git clone https://github.com/fabarea/vidi.git
有关最新开发的最新消息也发布在 http://twitter.com/fudriot
安装和需求
在扩展管理器中正常安装扩展或通过composer下载。
` composer require fab/vidi `
配置
配置主要在扩展管理器中提供,相当直观。请检查那里的可能选项。
用户TSconfig
创建新记录时需要定义pid(页面ID),以满足TCEmain的需求。并非所有记录都需要pid,因为其中一些可以在根级别,因此pid为0。但是,大多数需要大于0的pid值。首先,可以在扩展管理器中配置一个全局pid,作为后备值。此外,还可以设置用户TSconfig,这将为每种数据类型配置一个自定义pid,从而实现更精细的配置。我们还可以定义额外的约束,这些约束可用于默认筛选Vidi模块
# Short syntax for data type "tx_domain_model_foo": tx_vidi.dataType.tx_domain_model_foo.storagePid = 33 # Extended syntax for data type "tx_domain_model_foo": tx_vidi { dataType { tx_domain_model_foo { # Define the pid for a new record storagePid = 33 # Default criterion to be used as default filter constraints { # Records are found on pid "33" # Possible operators >= > < <= = like 0 = pid = 33 # Records belongs to category 1 OR 2 1 = categories.uid in 1,2 } } } }
使用...获取数据
内容视图助手
要获取内容,可以使用content.find()
视图助手在Fluid模板中检索数据。下面它将与Vidi内容仓库交互。例如,让我们显示属于用户组“1”的所有前端用户列表,并显示他们所属的用户组
<strong>Number of people: {v:content.count(matches: {usergroup: 3}, type: 'fe_users')}</strong> <f:for each="{v:content.find(matches: {usergroup: 3}, orderings: {uid: 'ASC'}, type: 'fe_users')}" as="person"> <div> {person.uid}:{person.username} <!-- !!! Notice how you can fetch relation through their properties! --> <f:if condition="{person.usergroup}}"> <ul> <f:for each="{person.usergroup}" as="group"> <li>{group.title}</li> </f:for> </ul> </f:if> </div> </f:for> {namespace m=Fab\Vidi\ViewHelpers}
我们可以使用视图助手findOne
以相同的方式检索单个记录,但这次是
<v:content.findOne type="fe_users" identifier="123"> <div> <strong>{object.username}</strong> </div> </v:content.findOne>
给定matches
,可以累积多个条件。值foo
对应于字段名,bar对应于值
<v:content.findOne type="fe_users" matches="{foo: bar}"> <div> <strong>{object.username}</strong> </div> </v:content.findOne>
给定URL中的一个参数,可以动态检索对象。我们假设URL如下所示:http://domain.tld/detail/?tx_vidifrontend_pi1[uid]=164
<v:content.findOne type="fe_users" argumentName="object""> <div> <strong>{object.username}</strong> </div> </v:content.findOne>
如果需要,我们可以使用具有属性 argumentName
的自定义参数名称,并使用属性 as
为对象提供一个别名。URL将如下所示:http://domain.tld/detail/?user=164
<v:content.findOne type="fe_users" argumentName="object" as="user"> <div> <strong>{user.username}</strong> </div> </v:content.findOne>
视频内容库(编程方式)
每种内容类型(例如,fe_users,fe_groups)都有自己的内容库实例,该实例由Repository Factory内部管理。要获取适当的实例,可以使用此代码获取库。
// Fetch the adequate repository for a known data type. $dataType = 'fe_users'; $contentRepository = \Fab\Vidi\Domain\Repository\ContentRepositoryFactory::getInstance($dataType); // From there, you can query the repository as you are used to in Flow / Extbase. // Fetch all users having name "foo". $contentRepository->findByName('foo'); // Fetch one user with username "foo" $contentRepository->findOneByUsername('foo'); // Fetch all users belonging to User Group "1". Usergroup must be written that sort following the TCA of fe_users, column "usergroup". $contentRepository->findByUsergroup(1);
对于复杂的查询,可以实例化一个匹配器对象,在其中添加多个条件。然后,内容库将解释匹配条件。以下是一个检索文件集的示例
// Initialize a Matcher object. /** @var \Fab\Vidi\Persistence\Matcher $matcher */ $matcher = GeneralUtility::makeInstance('Fab\Vidi\Persistence\Matcher'); // Add some criteria. $matcher->equals('storage', '1'); // "metadata" is required and corresponds to a field path making the join between the "sys_file_metadata" and "sys_file". $matcher->equals('metadata.categories', '1'); // Add criteria with "like" $matcher->like('metadata.title', 'foo'); // Fetch the objects. $files = $contentRepository->findBy($matcher);
注意:此示例在前端也有效。但是,并非所有内容都到位,例如本地化。这已列入我的待办事项。
面元
面元在视觉搜索中可见,并允许按条件搜索。面元通常映射到字段,但这不是强制性的;它可以是任意值。要提供自定义面元,必须实现 FabVidiFacetFacetInterface 接口。最好是借鉴 FabVidiFacetStandardFacet。
``` # fe_users 表格的示例 $GLOBALS['TCA']['fe_users']['grid']['facets'][FabVidiFacetCompositeFacet::class] =
- [
'name' => 'uid', 'label' => 'LLL:EXT:my_example/Resources/Private/Language/locallang.xlf:foo', 'configuration' => [
'disable' => 0, 'email' => '*', 'pid' => 123,]
],
在 Vidi 模块中添加工具
对于每个 Vidi 模块,可以注册一些工具来对内容类型执行各种维护、实用或处理操作。可以通过在 BE 模块的右上角图标中单击访问工具的着陆页。如果用户可用的工具,则显示该图标。以下是一个示例,它显示用于检查网格中使用的关系的工具,该工具是为管理员用户提供的。要注册自己的工具,请在 ext_tables.php
中添加以下行
if (TYPO3 == 'BE') { // Register a Tool for a FE User content type only. \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('*', 'Fab\Vidi\Tool\RelationAnalyserTool'); // Register some Tools for all Vidi modules. \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('fe_users', 'Fab\Vidi\Tool\RelationAnalyserTool'); }
覆盖权限
工具是否可访问由工具类本身定义。我们可以通过方法 isShown 控制哪些 BE 组(管理员、编辑者、...)可以访问工具。然而,规则可以通过在 ext_tables 中添加配置来编程性覆盖。假设我们想允许对“查找重复项”工具的访问,该工具在 Media 中提供,我们将做以下操作
\Fab\Vidi\Tool\ToolRegistry::getInstance() ->overridePermission('sys_file', 'Fab\Media\Tool\DuplicateFilesFinderTool', function() { return true; }); # where: # * sys_file: the scope of the, can be possibly '*' for every data type. # * DuplicateFilesFinderTool: the name of the tool. # * function(): the closure to override the default permissions.
TCA 网格
网格是 Vidi 列表组件的核心。TCA 已扩展以描述网格及其列应该如何呈现。以下示例中提供灵感,以供您自己的数据类型使用
'grid' => [ 'columns' => [ '__checkbox' => [ 'renderer' => \Fab\Vidi\Grid\CheckBoxRenderer::class, ], 'uid' => [ 'visible' => false, 'label' => 'Id', 'width' => '5px', ], 'username' => [ 'visible' => true, 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:username', ], 'usergroup' => [ 'visible' => true, 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:usergroup', ], '__buttons' => [ 'renderer' => \Fab\Vidi\Grid\ButtonGroupRenderer::class, ], ], ],
TCA "网格"
'grid' => [ 'excluded_fields' => 'foo, bar', 'export' => [], 'facets' => [], 'columns' => [] ],
- 键
- included_fields
- 描述
- 严格包含此 CSV 列表中的字段
- 键
- excluded_fields
- 描述
- 当某些字段应从网格中排除时
- 键
- export
- 描述
- 数据导出配置,CSV、XML、...
- 键
- facets
- 描述
- 面元配置
- 键
- columns
- 描述
- 网格中列的配置
TCA "grid.columns"
配置 $GLOBALS['TCA']['tx_foo']['grid']['columns']['field_name']
作为示例
'grid' => array( 'columns' => array( 'username' => array( 'visible' => true, 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:username', ), ), ),
可以为字段名称分配的可能键和值
- 键
- sortable
- 数据类型
- 布尔型
- 描述
是否可以排序列。如果表具有 "sortby" 值,则此值不尊重
['ctrl']['sorby'] => 'sorting'
- 默认值
- true
- 键
- visible
- 数据类型
- 布尔型
- 描述
- 列默认是否可见或隐藏。如果列默认不可见,则可以通过列选择器(BE模块右上角的按钮)显示
- 默认值
- true
- 键
- renderer
- 数据类型
- 字符串
- 描述
- 实现网格渲染接口的类名
- 默认值
- NULL
- 键
- 格式
- 数据类型
- 字符串
- 描述
- 一个实现
\Fab\Vidi\Formatter\FormatterInterface
的完整限定类名 - 默认值
- NULL
- 键
- 标签
- 数据类型
- 字符串
- 描述
- 可选标签,用于覆盖字段的默认标签 - 即 TCA['tableName']['columns']['fieldName']['label'] 中的标签
- 默认值
- NULL
- 键
- 可编辑
- 数据类型
- 字符串
- 描述
- 字段是否可编辑。
- 默认值
- NULL
- 键
- 数据类型
- 数据类型
- 字符串
- 描述
- 字段所属的表名。如果字段来自其他表,则仅定义此选项。网格渲染器将用于渲染内容。
- 默认值
- NULL
- 键
- 类
- 数据类型
- 字符串
- 描述
- 将显示到每个单元格的类名。
- 默认值
- NULL
- 键
- 包装
- 数据类型
- 字符串
- 描述
- 内容可能的包装。当单元格的内容需要以特殊方式样式化时很有用。
- 默认值
- NULL
- 键
- 宽度
- 数据类型
- int
- 描述
- 列可能的宽度
- 默认值
- NULL
- 键
- 可隐藏
- 数据类型
- 布尔型
- 描述
- 列是否可隐藏。
- 默认值
- true
- 键
- 本地化
- 数据类型
- 布尔型
- 描述
- 如果字段在 TCA 中配置为本地化,则在网格中有机会强制不进行本地化。
- 默认值
- true
TCA "grid.facets"
配置 $GLOBALS['TCA']['tx_foo']['grid']['facets']
作为示例
'grid' => array( 'facets' => array( 'uid', 'username', .... ), ),
考虑为维度的字段列表。
TCA "grid.export"
配置 $GLOBALS['TCA']['tx_foo']['grid']['export']
作为示例
'grid' => array( 'export' => array( 'include_files' => false, ), ),
可以分配给键 export
的可能键和值
- 键
- include_files
- 描述
- 是否将文件与 CSV、XML 等文件一起压缩
- 默认值
- true
- 键
- show_wizard(未实现)
- 描述
- 显示一个弹出窗口,其中可以选择要导出的字段。
TCA "vidi"
如果需要,Vidi 配置的特殊键。
配置 $GLOBALS['TCA']['tx_foo']['vidi']
作为示例
'vidi' => array( 'mappings' => array( // field_name => propertyName 'TSconfig' => 'tsConfig', 'felogin_redirectPid' => 'feLoginRedirectPid', 'felogin_forgotHash' => 'feLoginForgotHash', ), ),
可以分配给键 vidi
的可能键和值
- 键
- mappings
- 描述
当字段名不遵循下划线命名约定(filed_name -> propertyName)时,Vidi 需要一些帮助来找到等价项的映射规则。
示例
"WeirdField_Name" => 'weirdFieldName'
网格渲染器
默认情况下,列的值将直接显示,除非进行 HTML 实体转换。在某些情况下,可能希望自定义输出,例如显示关系时。可以为列配置网格渲染器。您可以编写自己的网格渲染器,它们只需要实现网格渲染器接口。
基本网格渲染器
# "foo" is the name of a field and is assumed to have a complex rendering 'foo' => array( 'label' => 'LLL:EXT:lang/locallang_tca.xlf:tx_bar_domain_model.foo', // Label is required 'renderer' => \Fab\Vidi\Grid\RelationRenderer::class, ),
具有选项的网格渲染器
# "foo" is the name of a field and is assumed to have a complex rendering 'foo' => array( 'label' => 'LLL:EXT:lang/locallang_tca.xlf:tx_bar_domain_model.foo', // Label is required 'renderer' => \Fab\Vidi\Grid\GenericColumn:class, 'rendererConfiguration' => [ 'foo' => 'bar' ] ),
具有选项的多个网格渲染器
'foo' => array( 'label' => 'LLL:EXT:lang/locallang_tca.xlf:tx_bar_domain_model.foo', // Label is required 'renderers' => [ \Fab\Vidi\Grid\RelationRenderer:class, ... // more possible renderers ], ),
网格格式化器
您可以使用 vidi 的内置格式化器或自定义格式化器来格式化列的值。
有两个内置格式化器
\Fab\Vidi\Formatter\Date
- 使用 d.m.Y 格式化时间戳\Fab\Vidi\Formatter\Datetime
- 使用 d.m.Y - H:i 格式化时间戳
如果想要提供自定义格式化器,则必须实现 \Fab\Vidi\Formatter\FormatterInterface
示例,使用内置格式化器
'starttime' => array( 'label' => ... 'format' => 'Fab\Vidi\Formatter\Date', ),
示例,使用 Acme 包中的自定义 FancyDate 格式化器
'starttime' => array( 'label' => ... 'format' => 'Acme\Package\Vidi\Formatter\FancyDate', ),
TCA 服务 API
此 API 允许以编程方式获取与 TCA 相关的信息。由于 TCA 覆盖了大量数据,该服务分为类型。有四个部分被解决:表、字段、网格和表单。 "网格" TCA 不是官方的,是扩展 TCA 以满足 Vidi 的需求。
- 表:处理 TCA 的 "ctrl" 部分。典型的信息是表名的标签、默认排序等。
- 字段:处理 TCA 的 "columns" 部分。典型的信息是字段名称的配置、标签等。
- 网格:处理 TCA 的 "grid" 部分。
- 表单:处理 TCA 的 "types"(以及可能的 "palette")部分。获取构成记录类型的字段。
该API旨在通用,可以用于TYPO3中的所有数据类型。一些代码示例。
use Fab\Vidi\Tca\Tca; # Return the field type Tca::table($tableName)->field($fieldName)->getType(); # Return the translated label for a field Tca::table($tableName)->field($fieldName)->getLabel(); # Get all field configured for a table name Tca::table($tableName)->getFields(); ...
属性映射
在内部,Vidi根据驼峰命名法规则,将字段名(在数据库中)自动转换为属性名(对象的属性)。例如,field_name
将被转换为propertyName
。
然而,由于历史原因,某些字段名可能不遵循约定。Vidi需要一点帮助来查找fieldName与propertyName之间的等效关系。这可以通过配置来解决。
# Context: $GLOBALS['fe_users']['vidi'] # Example used for "fe_users" 'vidi' => array( 'mappings' => array( 'lockToDomain' => 'lockToDomain', 'TSconfig' => 'tsConfig', 'felogin_redirectPid' => 'feLoginRedirectPid', 'felogin_forgotHash' => 'feLoginForgotHash', ), ),
数据处理
对于“更新”、“删除”、“复制”、“移动”等操作,默认情况下配置了Core的DataHandler。在大多数情况下,它会运行得很好。然而,如果有特殊需求,可以调用自己的Data Handler(例如,@see FILE:media中的FileDataHandler)。另一个原因是速度。当大量编辑数据并依赖于Core DataHandler时,您将注意到性能影响。虽然这将使您与TCEmain(处理您的钩子、缓存处理等)断开连接,但使用自己的DataHandler将使大量处理变得更快。
# Context: $GLOBALS['sys_file']['vidi'] # Example used for "sys_file" 'vidi' => array( 'data_handler' => array( // For all actions '*' => 'TYPO3\CMS\Media\DataHandler\FileDataHandler' // Or for individual action ProcessAction::UPDATE => 'MyVendor\MyExt\DataHandler\FooDataHandler' ), ),
模块加载器
如果您需要挂钩到模块并为新按钮或替换组件添加一些自定义行为,您可以通过Vidi模块加载器配置模块。以下是一个快速示例
$moduleLoader = GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader', 'sys_file'); $moduleLoader->addJavaScriptFiles(...)
为了获得更多信息,请考虑在扩展Media中的ext_tables.php
的示例。
请注意,对于每个Vidi模块,您都可以在专用模块中添加任何类型的实用工具(参看在Vidi模块中添加工具)。
常见问题解答
- 关于性能如何?
我们没有具体的数字。然而,Vidi非常接近数据库,如果索引配置良好,当处理大量数据时,Vidi模块的表现相当不错。一般来说,Vidi能够获取所需的准确数量的记录。此外,一旦获取,Vidi还能够内部缓存数据,如关系。
如果您遇到慢速的网格,请考虑减少可见列的数量,尤其是“关系”列,因为它们是最昂贵的渲染列。如果列在网格中隐藏,则出于性能考虑,将不会计算内容。
- 如何开始使用新的自定义Vidi模块?
从0.4.0版开始,Vidi提供了一种名为“list2”的新实验性功能。其想法是将Vidi的全部功能带到每种记录类型,而无需进一步配置。它可以在扩展管理器的设置中激活。如果您需要进一步配置网格,可以参考EXT:vidi/Configuration/Overrides/fe_users.php
中的fe_users的示例。