CQ5-How to add rte plugin in custom widget - aem

I have added richtext in the custom widget but i dont know how to add aditinal plugins for richtext.
Please help how we can achieve the same.
I am trying to add superscript/subscript in the richtext but not able to achieve the same.

Here is a code snippet that I've used to add this functionality to a richtext field.
<text
jcr:primaryType="cq:Widget"
hideLabel="{Boolean}true"
name="./text"
xtype="richtext">
<rtePlugins jcr:primaryType="nt:unstructured">
<subsuperscript
jcr:primaryType="nt:unstructured"
features="*"/>
</rtePlugins>
</text>
This snippet belongs in the dialog.xml of your custom component.
please have a look at the documentation for configuring the rich text editor for more information.

Related

cq:showOnCreate not working with RTE on Page properties

We are using an RTE field in the page properties. The issue here is, this field doesn't render in the page properties when author is creating the page. Is this a known issue with AEM? Is there any workaround for this?
<bannerText
cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/richtext"
fieldLabel="Banner text"
fieldDescription="This text describes the banner message."
required="true"
name="./bannerText"
useFixedInlineToolbar="{Boolean}true">
<rtePlugins jcr:primaryType="nt:unstructured">
<format
....
<bannerText?>
PS: We are using AEM 6.5
Thanks in advance!

AEM 6.5 Pre-populate fileUpload image field in cq dialog

New to AEM, I am trying to programatically populate an fileUpload image dropzone, and silently triggered its drop event as if user had manually drop an image asset to it. Is there a way to do this?
Say I have a cq_dialog with two fileUpload image fields (set to no upload, only droppable from asset allowed), one was already populated prior, the other is empty. Upon dialog load, I want to populate the empty one with the image asset from the populated one as a default.
The snippets of the cq_dialog looks like this:
<imageontopWrap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container"
class="layout-showhide-targets"
showhidetargetvalue="imageontop">
<items jcr:primaryType="nt:unstructured">
<image1
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/fileupload"
autoStart="{Boolean}false"
allowUpload="{Boolean}false"
class="cq-droptarget"
fieldLabel="Image Asset"
fileReferenceParameter="./myImageTopPath"
mimeTypes="[image]"
multiple="{Boolean}false"
name="./myImageTop"
title="Upload Image Asset"
useHTML5="{Boolean}true"/>
<altText1
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="Alt Text"
name="./myImageTopAltText"/>
</items>
</imageontopWrap>
<imageonleftWrap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container"
class="layout-showhide-targets"
showhidetargetvalue="imageonleft">
<items jcr:primaryType="nt:unstructured">
<image2
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/fileupload"
autoStart="{Boolean}false"
allowUpload="{Boolean}false"
class="cq-droptarget"
fieldLabel="Image Asset"
fileReferenceParameter="./myImageLeftPath"
mimeTypes="[image]"
multiple="{Boolean}false"
name="./myImageLeft"
title="Upload Image Asset"
useHTML5="{Boolean}true"/>
<altText2
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="Alt Text"
name="./myImageLeftAltText"/>
</items>
</imageonleftWrap>
I had created a clientLib for this cq_dialog, just wasn't sure the js codes to copy the image reference and trigger the drop using script.
Any help is much appreciated.
Here is the mechanism through you can achive what you require I hope. I am not sure about the exact js code though for which you have to do some googling on listners.
On dialog load, store the reference of the first image drop container in a js variable.
Then find the path of the image that is being stored/authored in the first image container.
Populate the same path in the second image drop path.
As I said, above is just a mechanism to help how you can achive your requirement.

Update RTE component to use Block Quotes in AEM

I'm currently using Rich Text Editor (RTE) in my AEM 6.2 project. I would like to configure RTE to use blockquote tag. How can achieve this?
<blockquote>
Component code:
<paraformat jcr:primaryType="nt:unstructured" features="*">
<formats jcr:primaryType="cq:WidgetCollection">
<p jcr:primaryType="nt:unstructured" description="Paragraph" tag="p"/>
<h1 jcr:primaryType="nt:unstructured" description="Heading 1" tag="h1"/>
<h2 jcr:primaryType="nt:unstructured" description="Heading 2" tag="h2"/>
<h3 jcr:primaryType="nt:unstructured" description="Heading 3" tag="h3"/>
<h4 jcr:primaryType="nt:unstructured" description="Heading 4" tag="h4"/>
<h5 jcr:primaryType="nt:unstructured" description="Heading 5" tag="h5"/>
<blockquote jcr:primaryType="nt:unstructured" description="Block Quote" tag="blockquote"/>
</formats>
</paraformat>
Reference:
RTE in JCR
Dialog View
Thanks.
You can add a new block element by following the instructions at official documents:
Adding custom paragraph formats to RTE
Basically, you overlay the RTE and extend the paraformat plugin by introducing the new elements. Summary steps are:
Overlay your RTE
Create cq:EditConfig/inplaceEditing/paraformat/format node under your RTE control.
Create a node for your style, name it blockquote and give it the following properties -> Description: Block Quote & Tag: blockquote
Make sure you add all other default formats like p, H1, H2 etc.
That's it. You should see your new paragraph style available in the paragraph styles dropdown.
This is a summary as all the pictures will make this post too long but a detailed post can be found at: http://www.aemcq5tutorials.com/tutorials/configure-rte-plugin-in-touch-ui/
Optionally, you will need to check if blockquote element is allowed by inspecting your /libs/cq/xssprotection/config.xml file. The file is self explanatory with lots of comments but in general you should check under <tag-rules> to ensure that your tag is supported. OOTB AEM 6.2 allows blockquote element but some upgrades might have lost it.

How to use richtext in multifield (in CQ5 dialog)? (prevent "this.el.dom is undefined" error)

I have created a custom component, and try to use RTE (xtype="richtext") inside the multifiled in my dialog.
Now, when I try to delete item, or after dialog was closed & reopened add another one the dialog will neither close, nor save the data with OK button.
dialog.xml:
<myField
jcr:primaryType="cq:Widget"
name="./myField"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="richtext">
</fieldConfig>
</myField>
Sham HC posted 2 solutions at AEM FAQ's:
Use textfield instead of a richtext Or try not to use a richtext in a multifield.
If richtext in a multifield is required then follow below and verify in your development envirnoment.
Overlay /libs/cq/ui/widgets/source/widgets/form/RichText.js
At the overlayed file for the method syncValue (Line 910) replace [1] with [2].
[1] this.el.dom.value = html;
[2] if(this.el.dom){this.el.dom.value = html;}
The problem is that I would like to use make it without changing Adobe's code.
I have found a workaround, that does not require changing CQ widget's code.
You need to set richtext's destroy event handler, to create dummy this.el.dom:
<myField
jcr:primaryType="cq:Widget"
name="./myField"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="richtext">
<listeners
jcr:primaryType="nt:unstructured"
destroy="function() {this.el.dom={};}"/>
</fieldConfig>
</myField>
<fieldConfig
jcr:primaryType="cq:Widget"
height="{Long}100"
xtype="richtext">
<listeners
jcr:primaryType="nt:unstructured"
destroy="function() {this.el.dom={};}"/>
</fieldConfig>

Can multiple smartimage xtypes appear on one dialog tab in AEM?

The out of the box (OOTB) page properties dialog in Adobe Experience Manager (AEM) (CQ5) provides an Image tab. I would like to add a couple more images to the dialog, but I don't want to create a separate tab for each one.
For instance, is there a way to include an image on the "Advanced" tab within a dialogfielset? I tried this, but it does not seem to render properly.
One thing I am considering is to extend the slideshow xtype and each image would be a separate "slide"
Are there better approaches?
It's possible to have multiple smartimage xtypes on a tab!
Widgets API document for smartimage:
Note that the component is mainly designed for use on a separate
dialog tab. You may use the component inside a
CQ.Ext.layout.FormLayout optionally if you provide a suitable height
setting.
Here are codes for dialog:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
height="{Long}600"
title="dialog"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<panel
jcr:primaryType="cq:Panel"
title="Panel with two Images">
<items jcr:primaryType="cq:WidgetCollection">
<firstimage
jcr:primaryType="cq:Widget"
cropParameter="./firstimage/imageCrop"
ddGroups="[media]"
fieldLabel="first image field"
fileNameParameter="./firstimage/fileName"
fileReferenceParameter="./firstimage/fileReference"
height="{Long}200"
name="./firstimage/file"
rotateParameter="./firstimage/imageRotate"
title="First Image"
width="{Long}200"
xtype="html5smartimage"/>
<secondimage
jcr:primaryType="cq:Widget"
cropParameter="./secondimage/imageCrop"
ddGroups="[media]"
fieldLabel="second image field"
fileNameParameter="./secondimage/fileName"
fileReferenceParameter="./secondimage/fileReference"
height="{Long}200"
name="./secondimage/file"
rotateParameter="./secondimage/imageRotate"
title="secondimage"
width="{Long}200"
xtype="html5smartimage"/>
</items>
</panel>
</items>
</items>
</jcr:root>
And the following is the result: