ezsystems / ez-matrix-bundle
EzMatrix 字段类型,适用于 eZ Publish 平台
0.2.1
2019-03-12 11:33 UTC
Requires
- php: ^5.6 | ^7.0
- ezsystems/ezpublish-kernel: ~5.3.11 | ~5.4.12 | ~6.7.8 | ~6.13.4 | ^7.2.5
Requires (Dev)
- phpunit/phpunit: ^5.7
Replaces
- blend/ez-matrix-bundle: *
This package is auto-updated.
Last update: 2024-08-29 04:26:12 UTC
README
该组件为 eZ Publish 平台 5.x 及更高版本提供 ezmatrix 字段类型
⛔️ 状态:已废弃: 从 2.5 版本开始,现在已包含一个来自 eZ 的新版本,该版本提供全面支持、迁移、UI 编辑等功能。⛔️
此组件可以在早期版本中使用,但不会在 1.x 或 2.x UI 或完整 API 支持下提供支持,因此 UI 编辑仅限于通过旧版桥接/组件进行使用。
安装
在已安装 eZ Publish 平台 根目录下使用已安装的 Composer
php -d memory_limit=-1 composer.phar require --prefer-dist ezsystems/ez-matrix-bundle:dev-master
在您的 app/AppKernel.php
文件中添加以下内容:
public function registerBundles() { ... $bundles[] = new EzSystems\MatrixBundle\EzSystemsMatrixBundle(); return $bundles; }
如何程序化更新内容
以下是一个如何更新内容项矩阵字段值的示例。该字段有两个列,我们正在创建两行内容
$repository = $this->getContainer()->get( 'ezpublish.api.repository' ); $contentService = $repository->getContentService(); // This example for setting a current user is valid for 5.x and early versions of 6.x installs // This is deprecated from 6.6, and you should use PermissionResolver::setCurrentUserReference() instead $repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) ); $contentId = 26926; $newTitle = 'My updated title 2'; try { // create a content draft from the current published version $contentInfo = $contentService->loadContentInfo( $contentId ); $contentDraft = $contentService->createContentDraft( $contentInfo ); // instantiate a content update struct and set the new fields $contentUpdateStruct = $contentService->newContentUpdateStruct(); $contentUpdateStruct->initialLanguageCode = 'eng-US'; // set language for new version $matrixValue = new \EzSystems\MatrixBundle\FieldType\Matrix\Value( array( new \EzSystems\MatrixBundle\FieldType\Matrix\Row( array( 'col1' => 'row1col1', 'col2' => 'row1col2' ) ), new \EzSystems\MatrixBundle\FieldType\Matrix\Row( array( 'col1' => 'row2col2', 'col2' => 'row2col2' ) ), ), array( new \EzSystems\MatrixBundle\FieldType\Matrix\Column( array( 'name' => 'Column 1', 'id' => 'col1', 'num' => 0 ) ), new \EzSystems\MatrixBundle\FieldType\Matrix\Column( array( 'name' => 'Column 2', 'id' => 'col2', 'num' => 1 ) ), ) ); $contentUpdateStruct->setField( 'title', $newTitle ); $contentUpdateStruct->setField( 'matrix', $matrixValue ); // update and publish draft $contentDraft = $contentService->updateContent( $contentDraft->versionInfo, $contentUpdateStruct ); $content = $contentService->publishVersion( $contentDraft->versionInfo ); } catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e ) { $output->writeln( $e->getMessage() ); } catch( \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e ) { $output->writeln( $e->getMessage() ); } catch( \eZ\Publish\API\Repository\Exceptions\ContentValidationException $e ) { $output->writeln( $e->getMessage() ); }
许可证 & 版权
请参阅 LICENSE 文件。
贡献者
https://github.com/ezcommunity/EzMatrixFieldTypeBundle/graphs/contributors