observe_rsc_update/3

An updated resource is about to be persisted. Observe this notification to change the resource properties before they are persisted.

The props are the resource’s props before the update, but after filtering and sanitization. The folded value is {ok, UpdateProps} for the update itself.

Type:

foldr

Return:

{ok, UpdateProps} or {error, term()}

#rsc_update{} properties:

  • action: insert|update
  • id: m_rsc:resource_id()
  • props: m_rsc:props()

An updated resource is about to be persisted. Observe this notification to change the resource properties before they are persisted.

Arguments

#rsc_update

action

Either insert or update.

id

Id of the resource.

props

Map with resource properties.

{ok, UpdateProps} | {error, Reason}

And/remove resource properties before the update is persisted.

Context

Site context

Example

Add a property before the resource is persisted:

observe_rsc_update(#rsc_update{action = insert, id = Id}, {ok, Props}, Context) ->
    %% Set an extra property
    {ok, Props#{ <<"extra_property">> => <<"special value!">> }}.
observe_rsc_update(#rsc_update{action = insert, id = Id}, {error, _} = Error, Context) ->
    Error.

Edit on GitHub

Observed by

Modules

mod_admin_identity

Provides identity management in the admin - for example the storage of usernames and passwords.

Modules

mod_menu

Create nested navigation menus for your site.

Modules

mod_video_embed

This module, if activated, checks the pasted URLs in the create media / page dialog of the admin. It will show an embed option for Youtube and Vimeo URLs. It…

Modules

mod_oembed

Makes media resources from embeddable URLs through the OEmbed protocol.

Modules

mod_admin_predicate

Add support for editing predicates in the admin, by presenting a list of all defined predicates on http://yoursite.com/admin/predicate .