novactive/ezextrabundle

Novactive eZ Platform Extra Bundle

v4.0.1 2022-01-21 19:04 UTC

README

这个仓库是我们所说的“子树分割”:主仓库中的一个目录的只读副本。它被Composer用于允许开发者依赖特定的包。

如果您想报告或贡献,您应该打开主仓库的问题: https://github.com/Novactive/Nova-eZPlatform-Bundles

文档可以通过此仓库中的.md文件获得,但也在此打包: https://novactive.github.io/Nova-eZPlatform-Bundles/master/ExtraBundle/README.md.html

Downloads Latest version License

安装

步骤 1:使用composer下载Nova eZExtra Bundle

将库添加到您的composer.json中,运行composer require novactive/ezextrabundle以刷新依赖项。

步骤 2:启用包

然后将在您的应用程序的bundles.php中注入该包。

    Novactive\Bundle\eZExtraBundle\NovaeZExtraBundle::class => [ 'all'=> true ],

步骤 3:添加默认路由

激活sroutes

_novaezextraRoutes:
    resource: "@NovaeZExtraBundle/Resources/config/routing/main.yml"

步骤 4:清除缓存并检查

php app|ezpublish/console cache:clear --env=dev

转到: /_novaezextra/dev/test

文档

Twig内容助手

eznova_parentcontent_by_contentinfo( content )

{% set content = eznova_parentcontent_by_contentinfo( content ) %}

注意:您在主要位置获取父内容

eznova_location_by_content( content )

{% set contentType = eznova_location_by_content( content ) %}

eznova_relationlist_field_to_content_list( fieldValue )

{% set content = eznova_relationlist_field_to_content_list( ez_field_value( content, 'internal_links' ) ) %}

注意:通过关系对象的字段类型返回直接链接的内容数组

eznova_is_rich_text_really_empty(richTextFieldValue)

{% set content = eznova_is_rich_text_really_empty( ez_field_value( content, 'description' ) ) %}

注意:如果富文本字段的值为空(不包括标签、空白和换行符),则返回true,否则返回false

Twig文本解析助手

ctaize

{% set ctaField | ctaize %}

注意:将类似于ezcontent://123或ezlocation://234的字符串转换为指定内容或位置的URL的过滤器

ezlinks

{% set richTextFieldValue | ezlinks %}

注意:修复打开/关闭div标签错误的过滤器,将类似于ezlocation://234的字符串转换为指定位置的URL

htmldecode

{% set stringValue | htmldecode %}

注意:将html_entity_decode php函数应用于指定变量的过滤器

Twig图像助手

get_image_tag(content, fieldIdentifier, variationAlias, params)

{{ get_image_tag(content, 'thumbnail', 'card_slider') }}

生成包含图像的HTML代码,包括在图像变体配置中指定的原始、视网膜和移动屏幕图像,如下所示

optimized_original:
    reference: ~
    filters:
        - { name: auto_rotate }
        - { name: strip }
        - { name: geometry/scaledownonly, params: [ 200,200 ] }
optimized_original_retina:
    reference: ~
    filters:
        - { name: auto_rotate }
        - { name: strip }
        - { name: geometry/scaledownonly, params: [ 400,400 ] }
optimized_original_mobile:
    reference: ~
    filters:
        - { name: auto_rotate }
        - { name: strip }
        - { name: geometry/scaledownonly, params: [ 50,50 ] }

如果指定了占位符尺寸且内容为空且变体为空,则将显示占位符图像

{{ get_image_tag(null, 'image', '', {placeholder: {width: 300, height: 100}}) }}

get_image_url(content, fieldIdentifier, variationAlias, params)

与前面相同,但仅返回图像URL而不是标签。

get_image_asset_content(field)

通过图像资产字段返回内容。需要指定eZ\Publish\API\Repository\Values\Content\Field。

重要:默认情况下启用了图像占位符,但可以通过设置ENABLE_IMAGE_PLACEHOLDER环境变量来禁用。

图片控制器

{{ render( controller( "eZNovaExtraBundle:Picture:alias", { "contentId": content.getField('picture').value.destinationContentId, "fieldIdentifier": "image", "alias": "large" })) }}

内容/位置助手

目标是模仿旧的Fetch Content List

public function contentTree( $parentLocationId, $typeIdentifiers = [], $sortClauses = [], $limit = null, $offset = 0, $additionnalCriterion );
public function contentList( $parentLocationId, $typeIdentifiers = [], $sortClauses = [], $limit = null, $offset = 0, $additionnalCriterion );
public function nextByAttribute( $locationId, $attributeIdentifier, $locale, $additionnalCriterions = [] );
public function nextByPriority( $locationId, $aditionnalCriterions = [] )
public function previousByAttribute( $locationId, $attributeIdentifier, $locale, $additionnalCriterion = [] )
public function previousByPriority( $locationId, $additionnalCriterion = [] )
public function getSelectionTextValue($content, $identifier)

返回结果数组

用法

    {% for child in children %}
        <h2>{{ ez_field_value( child.content, "title" ) }}</h2>
        {{ ez_render_field( child.content, "overview" ) }}
        <a href="{{ path( "ez_urlalias", { "locationId" : child.content.contentInfo.mainLocationId } ) }}">{{ "Learn more" | trans() }}</a>
    {% endfor %}

子项提供者

简单地注入子项(以及在视图全中可能的其他内容)

将您的提供者添加到您的包中的一个文件夹

Project\Bundle\GeneralBundle\ChildrenProvider\YOUCONTENTIDENTIFIERPROVIDERCLASS:
    tags:
        -  { name: novactive.ezextra.children.provider, contentTypeIdentifier: YOUCONTENTIDENTIFIER }

您的类YOUCONTENTIDENTIFIERPROVIDERCLASS必须扩展Novactive\Bundle\eZExtraBundle\EventListener\Type

之后,如果您想在模板中获取子项,则需要为每个显示的视图创建一个方法

namespace Yoochoose\Bundle\GeneralBundle\ChildrenProvider;
use Novactive\Bundle\eZExtraBundle\EventListener\Type;
use eZ\Publish\API\Repository\Values\Content\Query;
class PersonalizationEngine extends Type
{
    //its also use as default to get the full view children
    public function getChildren($viewParameters, SiteAccess $siteAccess = null)
    {
        return $this->contentHelper->contentList( $this->location->id, [ 'article' ], array( new Query\SortClause\Location\Priority( Query::SORT_ASC ) ), 10);
    }
    
    public function getLineChildren( $viewParameters )
    {
        ...
    }
}

RepositoryAware助手(特性)

    public function loadReverseRelations(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList

返回指定ContentInfo的反向关系列表(RelationList)

RouterAware助手(特质)

public function generateRouteLocation(Location $location): string
public function generateRouteContent(Content $content): string
public function generateRouteWrapper(Wrapper $wrapper): string

该特质允许通过位置、内容或包装对象获取路由。

视图匹配器

这允许您为同一内容类型指定不同的ez视图,但这些视图具有特定字段的不同值。

重要:默认情况下,字段名称设置为matcher,但可以通过在VIEW_MATCHER_FIELD_IDENTIFIER环境变量中指定它来重写。

例如,如果您将business值设置为用于标识视图的字段(默认为matcher),则可以在“Article”内容类型中定义另一个模板,使用以下配置

article_business:
    template: '@ezdesign/full/article_business.html.twig'
    match:
        Identifier\ContentType: [ 'article' ]
        '@Novactive\Bundle\eZExtraBundle\Core\ViewMatcher\ContentTypeField': 'business'