Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Delete Button in Editbar depending on Parsys

Tags:

aem

I have a CQ5 component with a delete button in the author mode's edit view. Now there are two possible ways to include this component in a page:

  1. Statically via a cq:include tag
  2. Dynamically via a parsys component

How do I configure CQ5.5 to only show the delete button in the editbar when the component is shown within a parsys. When the component is statically included via a cq:include the delete button should not be shown as it's not possible to delete the component from the page in that case.

Any ideas?

I only found the following CQ5 documentation how to generally remove the delete button from the editbar: http://dev.day.com/docs/en/cq/5-5/developing/components/edit_config.html#cq:actions

Also the delete button is correctly shown and hidden if I do NOT use the layout editbar :/

like image 838
Markus Peröbner Avatar asked Apr 30 '14 12:04

Markus Peröbner


1 Answers

There is no OOTB way to dynamically configure the editConfig depending on context, so the easiest solution would be to create a new component extending the original one which would override only the cq:editConfig node. So you end up with two flavours of the same component: one for the parsys, and another for static include, but without any code duplication, since the other one would be a 'shallow' override.

Copy the original component to a new one, remove all the files in the new component except .content.xml and _cq_editConfig.xml in which you need to remove DELETE from cq:actions.

For example, if your original component has a resourceType of /apps/mysite/myoriginalteaser, then in the new component you should set in .content.xml:

.content.xml:

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:Component"
    sling:resourceSuperType="mysite/myoriginalteaser"/>
                             ^^^^^^^^^^^^^^^^^^^^^^^
_cq_editConfig.xml:

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:EditConfig"
    cq:dialogMode="floating"
    cq:actions="[text:My Fixed Teaser,-,EDIT]"
    cq:layout="editbar">

NB: If you already have production content with the original resource type, then you will need to migrate the resource type for the component with the 'new' behaviour. This could be done (1) manually in CRXDELite, (2) using the Bulk Editor tool, or (3) via the Resource Type Updater from the ACS AEM Tools.

like image 163
ccpizza Avatar answered Nov 10 '22 18:11

ccpizza