Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: possibility of per-field rendering callback functions #1236

Open
max-novikov opened this issue Jun 20, 2024 · 0 comments
Open

Comments

@max-novikov
Copy link

Version

  • Carbon Fields: 3.6.3
  • WordPress: 6.5.4
  • PHP: 8.3

Feature Request/Suggestion

The actual request is to make it possible to use Gutenberg blocks in complex fields. If I understand correctly, this would require the functionality of set_render_callback to be applied on the field level, right? Something like code below:

Block::make('sample_grid', 'Grid Layout')
	->add_tab('Tiles', [
		Field::make('complex', 'grid_tiles', 'Grid Tiles')
			->add_fields([])
			->set_min(2)
			->set_collapsed(true)
			->set_inner_blocks(true)
			->set_render_callback(function ($value, $attributes, $inner_blocks) {
				print '<div class="tile">' . $inner_blocks . '</div>';
			})
		])
	->add_tab('Options', [
		Field::make('text', 'columns_count', 'Number of columns per row')
			->set_default_value(2)
			->set_attribute('min', 2)
			->set_attribute('max', 6),
		Field::make('text', 'grid_gap', 'Gap (in pixels) between columns and rows')
			->set_attribute('min', 0)
			->set_default_value(24),
		])
	->set_description("Grid block")
	->set_render_callback(function ($fields, $attributes) {
		$classes = ['grid','cols-'.$fields['columns_count']];			
		print '<div class="'.implode(' ',$classes).'" style="--gap: '.$fields['grid_gap'].'px">';
		foreach($fields['grid_tiles'] as $item {
			print crb_render_field($item); // new function to present rendered field
		}
		print '</div>';
	});

I really hope it makes sense. Thank you for your awesome plugin anyways!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant