welcome
admittedly, this is my first contact with cms and this part of building a website, so please understand. so…
I wanted to build a custom area that would only allow me to put an image in it. I created a field as a template:
<?php
$imageArea = new Area('Image');
$imageArea->setBlockLimit(1);
$imageArea->display($c);
?>
Based on the information I found, I found the $imageArea->setBlockLimit(1) property; which allows me to limit this area to the insertion of one block. Is it possible to similarly define the field to only accept the data-accepts-block-types = image property ?
maybe instead of changing the code of the site it is possible to set something identical from the GUI ?
I have been looking for a solution for x days and cannot find anything sensible.
Thank you very much for your help as well as any advice
P.S
I managed to create a solution on principle:
<?php
$imageArea = new Area('Obraz');
$imageArea->setBlockLimit(1); // Jeden blok w obszarze
$imageArea->setCustomTemplate('image', ''); // Opcjonalny szablon
$imageArea->display($c, function($blockType) {
return $blockType->getBlockTypeHandle() === 'image';
});
?>
Correct me if I’m wrong but I just fought with this and found that I needed to also visit Dashboard->Stacks & Blocks->Blocks & Stack Permissions and add permissions in there for the user otherwise zero blocks would show in the “Blocks” section when editing a page.
Even with Simple permissions, you need to visit Dashboard → Stacks & Blocks → Blocks & Stacks Permissions and add ‘Editors’ to the Add Block permission or else the ‘Add Block’ option doesn’t even show up when an Editor tries to edit a page. You can limit the blocks on this dashboard page BUT that means the Editors have permission to add these blocks wherever they can edit a page. It appears you need to turn on Advanced Permissions to apply more granular permission to specific Editable Areas.