ezsystems/ez-matrix-bundle

EzMatrix 字段类型,适用于 eZ Publish 平台

安装数量: 57,516

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 12

分支: 14

开放问题: 0

类型:ezplatform-bundle

0.2.1 2019-03-12 11:33 UTC

This package is auto-updated.

Last update: 2024-08-29 04:26:12 UTC


README

Build Status Downloads Latest version License

该组件为 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