Skip to main content

BlockRendererV1

This class inherits the methods and behavior of AbstractBlockRenderer.

In addition to AbstractBlockRenderer this extended class adds the following:

  • block_register: This abstract method must be implemented by the extended class.

Overview​

This class extends HighGround\Bulldozer\AbstractBlockRenderer

Methods​

NameReturn TypeSummary/Returns
add_class()voidAdd class to block classes.
add_css()stringAdd css to the compiled css. Returns: the compiled css
add_css_var()Add css variable with the value based on an acf field.
add_modifier_class()Add modifier class to block classes.
add_notification()Compose a notification to be shown in the backend.
create_inner_blocks()stringGenerate inner blocks appender. Returns: $inner_blocks the inner blocks appender
get_attribute()mixedGet block attribute. Returns: the attribute value
get_block_alignment()stringGet the block alignment.
get_block_id()stringGet the block id.
get_field()mixedget ACF field value. Returns: $field the field value
get_post_id()stringGet the block alignment.
is_full_width()boolCheck if the block is full width.
is_preview()boolCheck if the block is rendered in preview mode.
is_wide_width()boolCheck if the block is wide width.
set_alignment()voidSet the block alignment.
set_anchor()voidSet the block anchor.
set_attribute()voidSet a block attribute.
set_disabled()voidMark the renderer's block as disabled.

Class Methods​

add_class()​

Add class to block classes.

When an array is passed, it will merge the array with the existing classes.

since 5.2.0

add_class( string|array $class )

Returns: void

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$classstring or arraythe class or array of classes

PHP

public function block_context($context): array
{
$this->add_class(['section', 'has-background']);
return $context;
}

add_css()​

Add css to the compiled css.

since 5.5.1

add_css( string $css )

Returns: string the compiled css

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$cssstringthe css to add

add_css_var()​

Add css variable with the value based on an acf field.

since 1.8.0

add_css_var( string $field_name, string $css_var_name, false|string $selector = false )

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$field_namestringacf field name
$css_var_namestringthe css variable without the -- prefix
$selectorfalse or stringthe css selector where the css variable should be applied

PHP

public function block_context($context): array
{
$this->add_css_var('color_card_bg', 'card-base-background-color', '.crd');

return $context;
}

add_modifier_class()​

Add modifier class to block classes.

add_modifier_class( string $modifier )

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$modifierstringthe part after the -- from the BEM principle

PHP

public function block_context($context): array
{
if ($this->get_field('is_featured')) {
$this->add_modifier_class('featured');
}
return $context;
}

add_notification()​

Compose a notification to be shown in the backend.

add_notification( string $message, string $type )

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$messagestringthe message, translatable
$typestringtype of notification, can be notice, warning or error

PHP

public function block_context($context): array
{
$posts = Timber::get_posts([
'post_type' => 'post',
'posts_per_page' => 3,
])->to_array();
if (empty($posts)) {
$this->add_notification(__('Please add some posts.', 'wp-lemon-child'), 'warning');
}

create_inner_blocks()​

Generate inner blocks appender.

since 3.3.0

create_inner_blocks( array|false $allowed_blocks = false, array|false $template = false, false|string $classes = false, false|string $orientation = false, bool|string $templatelock = false )

Returns: string $inner_blocks the inner blocks appender

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$allowed_blocksarray or falsearray with allowed blocks or false
$templatearray or falsearray with template
$classesfalse or stringstring with classes
$orientationfalse or stringstring with orientation, can be 'horizontal' or 'vertical'
$templatelockbool or stringtrue or one of 'all' or 'insert'. True defaults to 'all'.

PHP

public function block_context($context): array
{
$args = [
'InnerBlocks' => self::create_inner_blocks($allowed_blocks, $template, 'row archive-content', 'horizontal'),
];
return array_merge($context, $args);
}

get_attribute()​

Get block attribute.

since 5.5.1

get_attribute( string $attribute_name )

Returns: mixed the attribute value

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$attribute_namestringthe attribute name

PHP

public function block_context($context): array
{
$align = $this->get_attribute('align');
return $context;
}

get_block_alignment()​

Get the block alignment.

since 5.5.1

Returns: string

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
$alignment = $this->get_block_alignment();
return $context;
}

get_block_id()​

Get the block id.

since 5.5.1

Returns: string

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
$block_id = $this->get_block_id();
return $context;
}

get_field()​

get ACF field value.

since 5.2.0

get_field( string $field_name )

Returns: mixed $field the field value

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$field_namestringthe field name

PHP

public function block_context($context): array
{
$is_featured = $this->get_field('is_featured');
return $context;
}

get_post_id()​

Get the block alignment.

since 5.9.1

Returns: string

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
$post_id = $this->get_post_id();
return $context;
}

is_full_width()​

Check if the block is full width.

since 5.5.1

Returns: bool

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
if ($this->is_full_width()) {
$this->add_class('has-background');
}
return $context;
}

is_preview()​

Check if the block is rendered in preview mode.

This is true when the block is rendered in the backend.

Use this method to conditionally load assets or change the rendering.

since 5.5.1

Returns: bool

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
if ($this->is_preview()) {
$this->add_notification(__('This is a preview mode.', 'wp-lemon-child'), 'notice');
}
return $context;
}

is_wide_width()​

Check if the block is wide width.

since 5.5.1

Returns: bool

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
{
if ($this->is_wide_width()) {
$this->add_class('has-background');
}
return $context;
}

set_alignment()​

Set the block alignment.

since 5.5.1

set_alignment( string $alignment )

Returns: void

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$alignmentstringthe alignment, can be wide or full

PHP

public function block_context($context): array
{
$this->set_alignment('full');
return $context;
}

set_anchor()​

Set the block anchor.

since 5.5.1

set_anchor( string $value )

Returns: void

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$valuestringthe anchor value

PHP

public function block_context($context): array
{
$this->set_anchor('my-custom-anchor');
return $context;
}

set_attribute()​

Set a block attribute.

since 5.5.1

set_attribute( string $attribute_name, mixed $value )

Returns: void

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

NameTypeDescription
$attribute_namestringthe attribute name
$valuemixedthe value to set

PHP

public function block_context($context): array
{
$this->set_attribute('align', 'full');
return $context;
}

set_disabled()​

Mark the renderer's block as disabled.

Sets the internal flag indicating the block is disabled so that subsequent rendering logic can treat this block as inactive or skip its output.

since 5.5.1

Returns: void

This method is inherited from \HighGround\Bulldozer\AbstractBlockRenderer.

PHP

public function block_context($context): array
if (empty($this->get_field('gallery'))) {
$this->add_notification(__('Add images to the slider', 'wp-lemon-child'), 'warning');
$this->set_disabled();
return $context;
}
return $context;
}