Add additional Area Bricks
Area bricks are principally implemented the same way as described in the Pimcore documentation.
The only difference is that the area brick class needs to extend the Pimcore\Bundle\PortalEngineBundle\Document\AbstractAreaBrick
class. As soon as a service with this parent class is registered in the service container with the tag pimcore.area.brick,
the area brick will be provided on portal and content pages.
# a service.yml file defining services
services:
# needs to extend Pimcore\Bundle\PortalEngineBundle\Document\AbstractAreaBrick
AppBundle\Document\Areabrick\TestArea:
tags:
- { name: pimcore.area.brick, id: testarea }
Targeting one frontend only
Portals run either the legacy frontend or the Studio frontend, chosen per portal by the Portal type setting on the portal page (see Styling Settings and Frontend Build). The two frontends render the same stored content but ship different markup and stylesheets, so a brick written for one of them will usually not look right in the other.
Which frontends a brick is offered to is decided by getAllowedPlaces():
| Place | Frontend |
|---|---|
AreabrickPlace::PORTAL | the legacy frontend |
AreabrickPlace::PORTAL_STUDIO | the Studio frontend |
AbstractAreabrick returns both by default, so a brick that does not override the method
behaves as it always has and is available everywhere. Override it to narrow the brick to one
frontend:
use Pimcore\Bundle\PortalEngineBundle\Document\AbstractAreabrick;
use Pimcore\Bundle\PortalEngineBundle\Enum\Document\AreabrickPlace;
class StudioOnlyTeaser extends AbstractAreabrick
{
public function getName(): string
{
return 'Studio teaser';
}
public function getAllowedPlaces(): array
{
return [AreabrickPlace::PORTAL_STUDIO];
}
}
Two consequences are worth knowing:
- Portals on the other frontend are unaffected. Pimcore's areablock uses the resulting allowed list both for the editmode brick picker and for rendering, so a brick that is not allowed in a place is neither offered there nor rendered there. A studio-only brick placed on a page whose portal is later switched back to the legacy frontend simply does not appear, instead of emitting markup the legacy stylesheet cannot dress.
- The content itself is shared. Both frontends read the same editables from the same document. A brick restricted to one frontend hides the brick, not the data — switching a portal's type back and forth does not delete anything.
The editor follows the portal's saved Portal type: switch it and save, and the brick picker on that portal's pages offers the other frontend's bricks. An unsaved change in the dropdown still shows the previously saved frontend's bricks.