Events¶
All event constants live in Drupal\frontend_editing\Event\FrontendEditingEvents. Each constant is
the event class name, so subscribing works with the class-name-as-event-name convention.
use Drupal\frontend_editing\Event\FrontendEditingEvents;
public static function getSubscribedEvents(): array {
return [
FrontendEditingEvents::FE_ENTITY_REFERENCE_DELETE_ACCESS => 'onDeleteAccess',
];
}
Access control events¶
Four events let a module decide whether an operation on an entity reference item is allowed. They run in addition to the permission and the host entity's update access, so a subscriber can only narrow what is already permitted in a meaningful way.
| Constant | Class | Dispatched before |
|---|---|---|
FE_ENTITY_REFERENCE_ADD_ACCESS |
EntityReferenceAddAccess |
Adding an item |
FE_ENTITY_REFERENCE_MOVE_ACCESS |
EntityReferenceMoveAccess |
Moving an item |
FE_ENTITY_REFERENCE_DELETE_ACCESS |
EntityReferenceDeleteAccess |
Deleting an item |
FE_ENTITY_REFERENCE_DUPLICATE_ACCESS |
EntityReferenceDuplicateAccess |
Duplicating an item |
All four extend EntityReferenceOperationsAccessBase and use AccessResultTrait:
| Method | Returns |
|---|---|
getParentEntity() |
The host entity holding the reference field |
getFieldName() |
The reference field's machine name |
getAccessResult() |
The access result so far |
setAccessResult(AccessResult $result) |
Replaces it |
public function onDeleteAccess(EntityReferenceDeleteAccess $event): void {
$parent = $event->getParentEntity();
if ($parent->getEntityTypeId() === 'node' && $parent->isPublished()) {
$event->setAccessResult(AccessResult::forbidden('Published pages are locked.'));
}
}
Rendering pipeline events¶
Three events exist for modules that render entities in a way the base module's own scan cannot follow. Read Rendering pipelines before using them.
| Constant | Class | Dispatched when |
|---|---|---|
FE_COLLECT_FIELD_RENDER_ELEMENTS |
CollectFieldRenderElementsEvent |
Once per entity render, after the top-level scan, so a subscriber can report where fields actually ended up |
FE_RESOLVE_FIELD_ACTIONS |
ResolveFieldActionsEvent |
The extra field is built directly, with no field render array to read the formatter settings from |
FE_RENDER_FIELD_CONTENT |
RenderFieldContentEvent |
A single field has to be re-rendered for an AJAX swap and the normal per-field render returns empty |
For FE_RENDER_FIELD_CONTENT, the first subscriber to call setContent() wins. A subscriber that
builds content here must also attach the action callbacks to what it built, or the operations stop
working after the first AJAX update.
Other events¶
| Constant | Class | Purpose |
|---|---|---|
FE_ENTITY_FORM_BUILD |
EntityFormBuild |
Fires while the sidebar form is built. Carries the entity and the form operation. |
FE_DATA_ADMIN_UI |
DataAdminUI |
Lets a subscriber replace the URL behind the sidebar's "Open in Admin UI" control. Carries the entity, the query parameters, and a settable URL. |