Front-office editing buttons are visible only from the front.
Front-edition tools can only be integrated on non-cacheable pages
Front-edition tools and scripts are loaded and visible only to users with "Site modification" rights.
The different modification modes
There are 2 ways of integrating front-edition tools:
wiki mode: modifications made from the front are directly online (working on the Live version)
edit mode: modifications made from the front only impact the draft version (working on the default version) In this mode, you need to add a "switch to edit mode" button to switch to the draft version, and a "Publish" button to validate modifications online.
In addition to these 2 modes, there are also 2 content modification modes:
simple mode: fields are modified individually field by field (default mode)
full mode: all fields can be modified on a single form
Loading the necessary scripts
plugin provides a XSL file containing the XSL templates to be called for each action (add page, add content, etc.) It is therefore necessary to import this file first:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Puis pour chaque page intégrant des outils de front-edition, il est nécessaire de faire appel au template XSL "ametys-front-edition-head" dans la section <head> du template. Ce template XSL permet de charger les scripts JS nécessaires au fonctionnement des outils front-edition.
Its parameters are as follows:
start Indicates whether to directly load javascript files required for editing (default: start)
false: only loads the bare minimum, page loading is not affected. You'll need to insert a button to start the front-edition modification. This button must call AmetysFrontEdition.start(); and only after this call will the modification be possible.
start: Load files on first modification action. Page loading will be little affected by front-edition, but the first modification will be slow.
load: Load files as soon as the page is loaded. Page loading will be slowed down, but the first modification will be immediate.
debug: Do not use (only for plugin front-edition development)
edition-mode-only: Edition is limited to edition mode (default: 'true'). Set to false() to activate wiki mode (modifications automatically online)
editActionId: identifier of the workflow action used for field-by-field editing (default: 2). Note that if wiki mode is used (edition-mode-only=false), the edit workflow action must also validate the content.
insertAttachmentActionId: workflow action identifier to be used when uploading content attachments (default: 12)
theme [from 1.6.0]: ExtJS theme loaded as a path to a folder (optional)
js-loading-html [from 1.6.0]: advanced parameter to customize the HTML code used for the front-edition loading screen. Defaults to <div id="front-edition-js-loading-div" class="front-edition-js-loading|front-edition-js-loaded">
start-callback [from 1.6.1]: optional callback function to be called after front-edition initialization
For example:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Note Buttons will only be displayed if you have the necessary rights linked to the functionality (e.g. the right to add a page) in addition to the right to modify online(Front_Edition_Access_Right).
Switch to edit mode
To insert a button to switch to edit mode (and vice versa), call the template "ametys -front-edition-insert-toggle-edition-mode-button ". The parameters are as follows:
class: css class to be added to the button. Default front-edition-toggle-edition-mode
For example:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
As a reminder, there are 2 editing modes: wiki mode, which works on the validated version of the site, and edition mode, which works on the draft version of the site. This button is only required when you wish to use edition mode.
Content modification
To enable content fields to be modified, simply add a "data-ametys-metadata" attribute to the html element displaying the field.
The "data-ametys-metadata" attribute contains the content identifier and the metadata path, separated by a semicolon;
At the end of front-edition loading, a "modify" button will be automatically added to editable fields (taking into account the rights of the logged-in user) to enable them to be modified.
The css class "ametys-front-edition-possible" is automatically added to all html elements with the "data-ametys-metadata" attribute for which modification is possible. The "ametys-front-edition-hover" class is also added. A <button class="ametys-front-edition-button">Modifier</button> is added to the element.
To make this button visible only on hover, simply add the following rule css :
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Copy to clipboard failed. Open the code and copy it manually.
<div class="content-title rs-editable__pseudo-text ametys-front-edition-possible" data-ametys-metadata="content://a0a38c54-e6d4-48ec-a519-0f60cc5e7a8b;title">
<button class="ametys-front-edition-button">
<span class="ametys-front-edition-button-text">Modifier</span>
</button>
Titre du contenu
</div>
<div class="content-title rs-editable__pseudo-text ametys-front-edition-possible" data-ametys-metadata="content://a0a38c54-e6d4-48ec-a519-0f60cc5e7a8b;title">
<button class="ametys-front-edition-button">
<span class="ametys-front-edition-button-text">Modifier</span>
</button>
Titre du contenu
</div>
<div class="content-title rs-editable__pseudo-text ametys-front-edition-possible" data-ametys-metadata="content://a0a38c54-e6d4-48ec-a519-0f60cc5e7a8b;title">
<button class="ametys-front-edition-button">
<span class="ametys-front-edition-button-text">Modifier</span>
</button>
Titre du contenu
</div>
How do I authorize the modification of empty fields?
Only one displayed field can be modified.
To be able to modify an empty field, you need to add a "placeholder", only for users authorized to modify this field.
To do so,
if in edit mode (working on the draft version): placeholders are displayed regardless of the current user's rights. This solution is easy to implement.
For example:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
if in wiki mode (working on the validated version): placeholders are always present but hidden in the HTML code and must be displayed in javascript for users with access rights.
Example of implementation from version 1.6.1+.
Oops!
Copy to clipboard failed. Open the code and copy it manually.
The plugin must be loaded by specifying a callback function to the existing call. This JS function will make visible the "placeholder" containing the edit button (identified by the css class "ametys-front-edition-button").
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Note importante La taille du champ du formulaire permettant la modification de la donnée sera la même que la taille de l'élément html portant l'attribut "data-ametys-metadata". Il est donc conseillé d'ajouter cet attribut sur des éléments <div> plutôt que des <span> et de prévoir une largeur minimun (et une hauteur minimun pour les champs de type texte riche ou texte multiligne).
To date, the types supported by the front-office modification are as follows:
STRING
DATE
DATETIME
RICH_TEXT
CONTENT
FILE
Since version 1.11 (Ametys 4.6), an image widget has been available as a default for FILE types with the "image" filter enabled. This widget has a "shape" parameter which can take: - the value "circle" if the widget is to be displayed as a circle, for a profile photo for example. - the value "square" if the widget is to be forced as a square image - the default value "rectangle" for an image without forced size
Widget and parameters
Since version 1.11 (Ametys 4.6), it is possible to specify a widget with the attribute "data-ametys-widget" to replace the default value. Only widgets provided by plugin Front Edition are available.
Since version 1.11 (Ametys 4.6), it has been possible to specify widget parameters with the attribute "data-ametys-widget-params" in the form of a JSON. Be careful to escape braces within XSL .
Oops!
Copy to clipboard failed. Open the code and copy it manually.
There's nothing more to do to use this editing mode. Content fields are edited individually, and changes are saved each time they are made.
Modify all fields simultaneously
In this mode, add a general "Modify" button and hide the individual "Modify" buttons.
The "ametys -front-edition-edit-content-button " template displays a button for modifying all visible content fields in a single form, and displays a toolbar with workflow actions that can be performed.
The parameters are as follows.
content-id: identifier of the content to be modified
workflow-ids list of workflow actions to make available. Default [2]
Given a list of integers [2, 4, 5], the button names will be the names of the actions defined in the workflow
Il est aussi possible de surcharger les noms d'actions : [{id:2,text:'<xsl:value-of select="$workflow-2-text" />'}, 42]. Le texte doit être décodé dans la balise (voir exemple ci dessous)
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Default front-edition-edit-content
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Example with a text overload for the modify action
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To hide individual edit buttons, simply add a rule css:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
.ametys-front-edition-button { display: none; }
.ametys-front-edition-button { display: none; }
.ametys-front-edition-button { display: none; }
Content workflow
For content for which you wish to authorize modification from the front-office, it is strongly recommended that you add an action to the workflow allowing :
automatically validate content each time it is modified, if the current version is the validated version
keep the content in draft form if the current version is a draft version
Here's an example of an action with a conditional result, assuming that "1" is the draft state and "3" the released state:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
Important The tools described in this chapter must not be called up from the content view, as this view is cached and can cause serious side effects (see https://issues.ametys.org/browse/FRONTEDIT-78 ).
To call them, put your code in zone-item-before or zone-item-after of your template (see Writing a template).
Adding content to a page
To insert a button for adding content, use the template "ametys-front-edition-add-content-button " with the following parameters:
page-id: page identifier
content-types: type(s) of content to be created. If several types are to be declared for the same content, separate them with semicolons ;
zone-name: name of zone in which to add content. Default: default
content-title: default content title
init-workflow-action-id: identifier of the initialization workflow action. Default: 1
workflow-name: name of the workflow linked to this content. Default: content
local: content language
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Default front-edition-add-content
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Example of a button to create a new article:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To insert a button to perform a workflow action on content, use the template "ametys -front-edition-content-workflow-button " with the following parameters:
content-id: identifier of the content on which to execute the workflow action
workflow-id: identifier of the workflow action to be executed
workflow-text: text to be displayed (by default, the action label defined in the workflow)
title-i18n : i18n key to be used as button title
class: css class to be added to the button. Default front-edition-workflow-action
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Example of adding 2 buttons to unpublish or publish content depending on its current status:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To insert a button for moving content within its zone, use the template "ametys -front-edition-move-content-button " with the following parameters:
zone-item-id: identifier of the zoneItem to be moved
zone-name: name of parent zone to which to move content
offset: -1 to go up a level, 1 to go down a level
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Defaults to front-edition-move-content-up or front-edition-move-content-down depending on offset direction.
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Recover the current workflow state of a content item
To retrieve a content's workflow state identifier, use the template "ametys-front-edition-get-content-workflow-step " with the following parameters:
content-id: content identifier
prefix: text prefixing the return (optional)
Returns the workflow state identifier for this content, prefixed by prefix
Retrieve content status
To retrieve content status, use the template "ametys -front-edition-get-content-validation-status " with the following parameters:
content-id: content identifier
prefix: text that will prefix the return
Returns "[prefix]validated" if the content is validated or "[prefix]draft" otherwise.
For example:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
There's no need to re-declare everything: if a single parameter needs to be changed, simply pass it to the conf (a merge of the passed conf and the default conf is performed).
Prior to Ametys 4.3, it was sufficient to specify "force":true to display only the card of choice for the page title. Now you must explicitly specify the set of cards to be hidden, the list being: show-card-type, show-card-content, show-card-tags. force is used to force the application of default values, in most cases it is useful to set it when hiding cards.
Example 1: creation of a News page and content with label selection from a restricted list
Oops!
Copy to clipboard failed. Open the code and copy it manually.
The type of content to be created is imposed (news)
The wizard will consist of 2 pages: one to define the title of the page to be created, a second to select labels from a list of daughter labels of the "NEWS_CATEGORIES" label and from a list of labels of the "org.ametys.plugins.workspaces.categories.CategoryTagProvider" label provider.
Deleting a page
To insert a button for deleting a page, use the template XSL "ametys-front-edition-insert-delete-page-button". The parameters are as follows:
page-id: identifier of the page to be deleted
page-title: page title to be specified in the dialog box
button-text: button text
title-i18n: i18n key to be used for the button tooltip
class: css class to add to the button. Default front-edition-delete-page
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
If the page contains content, it will be automatically deleted unless it is shared.
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To insert a button to move a page in the tree to a target page, use the template XSL "ametys-front-edition-insert-move-page-button". The parameters are as follows:
page-id: identifier of the page to be moved
page-parent-id: identifier of the new parent page
page-new-pos: position of the page in its new parent (integer)
button-text: button text/html
class: css class to be added to the button
link-title-i18n : i18n key to be used as button title
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
This template is only to be used to change parents; for a move within the same parent (re-ordering), we recommend using the 2 templates below.
Move a page up or down
To insert a button to move a page up or down while preserving its parent, use the template XSL "ametys-front-edition-insert-move-page-up-button " and "ametys-front-edition-insert-move-page-down-button " respectively.
The parameters are as follows:
page-id: identifier of the page to be moved
page-parent-id: parent page identifier
page-pos: current page position (used to validate whether or not the button is displayed, and to calculate future position) (page count starts at 1, not zero)
number-of-pages: number of child pages under the parent page
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Default front-edition-move-page-up
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Example: In the example below, a "Move" menu includes 2 items for moving the page up or down
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To retrieve the status of a page's contents, use the template XSL "ametys-front-edition-get-page-status".
The parameters are as follows:
page-id: page identifier
prefix: prefix to be added at the beginning of the string (optional)
This template returns [prefix]validated|draft|mixed according to the page content status:
validated: all page content is validated
draft: all page contents are drafts
mixed: the page contains validated content and drafts
"": nothing is returned if no content is found.
Scheduled publication of a page
Available from front-edition 1.7 onwards
To insert a button for scheduled publication of a page, use the template XSL "ametys-front-edition-insert-schedule-publication-button". The only parameter is :
page-id: identifier of the page to be programmed (default: identifier of the current page)
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Default front-edition-schedule-publication
Example
Oops!
Copy to clipboard failed. Open the code and copy it manually.
To insert a button for deleting content or a service on a page (zoneitem), call the template "ametys -front-edition-remove-zoneitem-button " with the following parameters:
page-id: page identifier
zone-name: name of the zone in which a zoneItem will be deleted
zone-item-id: identifier of the zoneitem to be deleted
button-text: button text/html
title-i18n : i18n key to be used for the button tooltip
class: css class to be added to the button. Default front-edition-remove-content
edition-mode-only: false() to authorize the button even when not in edition mode (default is true())
Example:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
The class org.ametys.plugins.frontedition.AmetysFrontEditionHelper provides a few methods for retrieving template arguments, which can also be used during integration to decide whether or not to call certain templates (essentially hasFrontEditionRight).
hasFrontEditionRight
Two possible signatures:
boolean hasFrontEditionRight(String rightId, String pageId, boolean editionModeOnly) Enables you to check whether a right is accessible to the user (to verify whether the user can modify a page or content, for example).
boolean hasFrontEditionRight() Checks only if the user has Front_Edition_Access_Right rights in the general context
Checks that the user can perform a workflow action (can also check if in edit mode)
getPageStatus
String getPageStatus(String pageId)
Returns page content status (draft/validated or mixed if both)
getZoneItemPosition
long getZoneItemPosition(String zoneItemId, String pageId)
Retrieves the position of a zoneItem in a page
getZoneSize
long getZoneSize(String zoneName, String pageId)
Retrieves the number of zoneItems in a zone
getContentWorkflowId
long getContentWorkflowId(String contentId)
Retrieves workflow step id for a content
getContentStatus
String getContentStatus(String contentId)
Retrieves "validated" or "draft" depending on whether the content has a validated (Live) version or not.
isContentLive
boolean isContentLive(String contentId)
As above, but returns true if the content has a validated version (Live).
AmetysXSLTHelper
The org.ametys.web.transformation.xslt.AmetysXSLTHelper class provides a useful method for using front-edition.
isEditionMode
boolean isEditionMode()
Linked to use of template ametys-front-edition-insert-toggle-edition-mode-button which switches betweennormal mode (uses LIVE from the front) and edition mode (uses workspace DEFAULT, and therefore allows access to draft content and empty pages). This function returns TRUE if in front AND in edition mode. (in preview mode, false will always be returned).
Advanced integration
Override HTML rendering of all buttons
Each template manages its display through the template ametys-front-edition-insert-button-simple which is passed the following parameters :
button-text
javascript-function
class
title-i18n
Here's the current template code, which can be rewritten to customize the general display of all buttons
Oops!
Copy to clipboard failed. Open the code and copy it manually.
All the templates listed above are the ones to call, but for modularity's sake, each of these templates calls an intermediate one so that a skin can rewrite it to modify the graphic rendering if necessary.
Apart from ametys-front-edition-move-content-buttonall templates with names ending in -button have an intermediate template with the same name, but ending in -.button-simple.
For ametys-front-edition-move-content-button, there are 2 intermediate levels. The templates to be rewritten if necessary are ametys-front-edition-move-content-button-up-simple and ametys-front-edition-move-content-button-down-simple.
All these intermediate templates require the same parameters:
button-text
javascript-function
title-i18n
class
And they call the final button display template: ametys-front-edition-insert-button-simple (passing it these same parameters)
Customize paragraph styles in the rich text editor
From version 1.7.0
The list of paragraph styles is automatically formatted by copying the following styles from the rich editor's CSS :
Oops!
Copy to clipboard failed. Open the code and copy it manually.