Tribe__Tickets__Editor__Blocks__Tickets::render( array $attributes = array() )
Since we are dealing with a Dynamic type of Block we need a PHP method to render it
Contents
Parameters
- $attributes
-
(array) (Optional)
Default value: array()
Return
(string)
Source
File: src/Tribe/Editor/Blocks/Tickets.php
public function render( $attributes = array() ) {
/** @var Tribe__Tickets__Editor__Template $template */
$template = tribe( 'tickets.editor.template' );
$args['post_id'] = $post_id = $template->get( 'post_id', null, false );
$args['attributes'] = $this->attributes( $attributes );
// Prevent the render when the ID of the post has not being set to a correct value
if ( $args['post_id'] === null ) {
return;
}
// Fetch the default provider
$provider = Tribe__Tickets__Tickets::get_event_ticket_provider( $post_id );
if ( ! class_exists( $provider ) ) {
return;
}
// If Provider is not active return
if ( ! array_key_exists( $provider, Tribe__Tickets__Tickets::modules() ) ) {
return;
}
$provider = call_user_func( array( $provider, 'get_instance' ) );
$provider_id = $this->get_provider_id( $provider );
$tickets = $this->get_tickets( $post_id );
$args['provider'] = $provider;
$args['provider_id'] = $provider_id;
$args['cart_url'] = 'tpp' !== $provider_id ? $provider->get_cart_url() : '';
$args['tickets_on_sale'] = $this->get_tickets_on_sale( $tickets );
$args['has_tickets_on_sale'] = ! empty( $args['tickets_on_sale'] );
$args['is_sale_past'] = $this->get_is_sale_past( $tickets );
// Add the rendering attributes into global context
$template->add_template_globals( $args );
// enqueue assets
tribe_asset_enqueue( 'tribe-tickets-gutenberg-tickets' );
tribe_asset_enqueue( 'tribe-tickets-gutenberg-block-tickets-style' );
return $template->template( array( 'blocks', $this->slug() ), $args, false );
}
Changelog
| Version | Description |
|---|---|
| 4.9 | Introduced. |