How to create a custom area with marking for images only

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';
});
?>

but this only hides blocks that are not an image.

You could use area permissions provided you don’t give the super user to your editor.

  • You create a user or user group that has editing duties (it could even be the administrators group)
  • You click on the area and select permissions
  • you click on “add block to area” from the permission list
  • you add your user or user group
  • you click on the “details” tab and you select the blocks allowed for that user/user group in that area.

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.

I didn’t test it so I can’t say. It would seem wrong, but it wouldn’t be the first time something like that happens.

Perhaps this is a ‘feature’ of Advanced Permissions. I’ll spin up a new instance and check it out.

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.