<?php

add_action( 'acf/init', 'custom_block_registration' );

function custom_block_registration() {
	// If we have access to the new 'acf_register_block' function
	if( function_exists( 'acf_register_block' ) ) {
		// Register our custom block type
		acf_register_block( array(
			'name'				=> 'jf-gallery',
			'title'				=> 'Galerie',
			'description'		=> 'Affichage d\'une galerie de médias',
			'render_callback'	=> 'custom_block_render_callback',
			'category'			=> 'formatting',
			'icon'				=> 'images-alt2',
			'keywords'			=> array('media'),
		) );
	}
}

function custom_block_render_callback( $block ) {
	// Remove "acf/" from name so we can use a path-friendly slug
	$slug = str_replace( 'acf/', '', $block['name'] );
	
	// include a template part from within the "template-parts/block" folder
	if( file_exists( STYLESHEETPATH . "/blocks/templates/{$slug}.php" ) ) {
		include( STYLESHEETPATH . "/blocks/templates/{$slug}.php" );
	}
}