General

  eZ Systems Website
  Editor documentation


  Developer documentation

  Back to the top

Skip to end of metadata
Go to start of metadata

Description

V1.2

A Landing Page has a customizable layout with multiple zones where you can place predefined blocks with content.

By default eZ Enterprise comes with a number of preset Landing Page blocks. You can, however, add custom blocks to your configuration.

Solution

Block configuration

In the Demo installation the layout configuration is stored in ezstudio-demo-bundle/Resources/config/default_layouts.yml:

Example default_layouts.yml

 

Creating a new block

Creating a class for the block

The class for the block must implement the BlockType interface:

Most methods are implemented in a universal way by using the AbstractBlockType abstract class:

If your block does not have specific attributes or a structure, you can extend the AbstractBlockType class, which contains simple generic converters designated for the block attributes.

For example:


Describing a class definition

A block must have a definition set using two classes:

BlockAttributeDefinition

The BlockAttributeDefinition class defines the attributes of a block:

AttributeTypeDefinition
$idstringblock attribute ID
$namestringblock attribute name
$typestringblock attribute type, available options are:
  • integer
  • string
  • url
  • text
  • embed
  • select
  • multiple
$regexstringblock attribute regex used for validation
$regexErrorMessagestringmessage displayed when regex does not match
$requiredboolTRUE if attribute is required
$inlineboolindicates whether block attribute input should be rendered inline in a form
$valuesarrayarray of chosen values
$optionsarrayarray of available options


BlockDefinition

The BlockDefinition class describes a block:

AttributeTypeDefinitionNote

$type

stringblock type 
$namestringblock name 
$categorystringblock category 
$thumbnailstringpath to block thumbnail image 
$templatesarrayarray of available paths of templates

Retrieved from the config file (default_layouts.yml)

$attributesarrayarray of block attributes (objects of  BlockAttributeDefinition  class) 


 

When extending AbstractBlockType you must implement at least 3 methods:

 createBlockDefinition()

This method must return an  EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockDefinition  object.

Example of a Gallery block:

 getTemplateParameters(BlockValue $blockValue)

This method returns an array of parameters to be displayed in rendered view of block. You can access them directly in a block template (e. g. via twig {{ title }} ).

 

When parameters are used in the template you call them directly without the parameters array name:

CorrectNot Correct
<h1>{{ title }}</h1> <h1>{{ parameters.title }}</h1>

 

Example of the getTemplateParameters() method implementation:

 

 checkAttributesStructure(array $attributes)

This method validates the input fields for a block. You can specify your own conditions to throw the InvalidBlockAttributeException exception.

This InvalidBlockAttributeException exception has the following parameters:

NameDescription
blockType name of a block
attribute name of the block's attribute which failed validation
message a short information about an error
previous previous exception, null by default

 

For example:

When the class is created make sure it is added to a container.

 

Adding the class to the container

 The services.yml file must contain info about your block class.

The description of your class must contain a tag which provides:

  • tag name: landing_page_field_type.block_type
  • tag alias: <name of a block>

 

For example:

Custom editing UI

If you want to add a custom editing UI to your new block, you need to provide the code for the custom popup UI in Javascript (see the code for eZS.ScheduleBlockView or eZS.TagBlockView for examples).

Once it is ready, create a plugin for eZS.LandingPageCreatorView that makes a use of the addBlock public method from eZS.LandingPageCreatorView, see the example below:

Upcoming feature - multiple block templates

The ability to configure different templates (views) for one Landing Page block is upcoming. See EZS-1008 to follow its progress.

 

Example

Block Class

TagBlock.php

V1.7

If you want to make sure that your block is only available in the Element menu in a specific situation, you can override the isAvailable method, which makes the block accessible by default:

 

service.yml configuration

services.yml

Block template

{{ block.attributes.content|raw }}