Your Privacy

This site uses cookies to enhance your browsing experience and deliver personalized content. By continuing to use this site, you consent to our use of cookies.
COOKIE POLICY

AEM 6.2:  Customizing Social Components

AEM 6.2:  Customizing Social Components
Back to insights

Adobe Experience Manager (AEM) is a web content management system used by Fortune 500 companies to build responsive websites. A benefit of AEM is out-of-the-box support for social communities. With AEM 6.2, website designers can simply drag and drop a social component onto a web page, publish the page, and the social functionality is pushed to the live site.

If your website is using AEM social components, it is likely that you will want to add new functionality to the default components at some point. There are two different ways to customize the social components – via overlaying and extension. Customizing a social component via overlay adds the customizations to the default instance of the component. Customizing a social component via extension creates a new instance of the component and leaves the default instance unchanged. This article will show how to add new functionality to a social component’s controller by building off Adobe’s tutorial for extending AEM 6.2’s comment system.

Begin by navigating to this link and following the tutorial for extending the comments system. Stop after you have completed the step named “Comments Clientlibs on Sample Page.” Your included clientlibs should look like the screenshot below, and not like the screenshot in the tutorial. The reason for this deviation from the tutorial is that you need to include your extended component on the page where you are using it.

Continue through Adobe’s tutorial, but stop before completing the “Alter the Appearance” steps. Instead, let’s add new functionality to the comment system’s controller

1. Change your comments.hbs file so that it contains this code:

<div id="div-commentsystem" class="scf-commentsystem scf translation-commentsystem" data-component-id="{{id}}" data-scf-component=

"/apps/example/components/custom/comments">

    <header>

        <h4>

            <span data-attrib = "items-count">{{totalSize}}</span><span>&nbsp;{{i18n "Comments" }}</span>

            {{#if configuration.followingAllowed}}

                <span class="scf-cs-subscriptions-block">

                    {{include this.id path="subscriptions" resourceType="social/subscriptions/components/hbs/subscriptions"}}

                </span>

            {{/if}}

            <span style='display:none;' evt="click=translateAll" class='generic-translation-all-button scf-link' data-translation-parent-

box-class="translation-commentsystem"

data-translation-parent-id-attr="data-component-id" data-translation-parent-box-id="{{id}}" href='#' data-translation-show-

original-text="{{i18n "Show Original

Translations"}}">

             {{#if showingTranslationAll}}

                  {{i18n "Show Original"}}

               {{else}}

                 {{#if translateAllInProgress}}

                    {{i18n "Translating"}}

                  {{else}}

                    {{i18n "Translate All"}}

                  {{/if}}

                {{/if}}

            </span>

        </h4>

    </header>

    {{#if mayPost}}

        <div id="div-comments" class="scf-composer-block scf-is-collapsed scf-js-composer-block">

            <img class="scf-composer-avatar" src="{{loggedInUser.avatarUrl}}"></img>

            <form evt="submit=addComment" class="scf-composer">

                {{#if configuration.isRTEEnabled}}

                    <textarea class="scf-composer-msg scf-rte-placeholder" placeholder="{{i18n "Write a comment"}}" evt="click=expandComposer">

</textarea>

                    <div class="scf-rte-composer">

<textarea class="scf-composer-msg" data-attrib="message" data-field-type="rte" name="message" placeholder="{{i18n "Write a comment"}}"></textarea>

                    </div>

                {{else}}

                    <textarea class="scf-composer-msg" data-attrib="message" name="message" placeholder="{{i18n "Write a comment"}}" evt="

click=expandComposer"></textarea>

                {{/if}}

                <div class='scf-composer-toolbar'>

                    {{#if configuration.isAttachmentAllowed}}

                        <button class="scf-composer-action scf-composer-attach" evt="click=openAttachmentDialog">{{i18n "Attach"}}</button>

                        <input class="scf-comment-attachment-input scf-js-cmt-att-input" type="file" data-attrib='attachment' name="attachment"

multiple evt=

"change=renderAttachmentList" />

                    {{/if}}

                    <div class="scf-composer-actions">

                       <button type="reset" class="scf-composer-action" evt="click=cancelComposer">{{i18n "Cancel"}}</button>

                        <input type="submit" value="{{i18n "Edited Post Button"}}" evt="submit=addComment" />

                   </div>

                    {{#if configuration.isAttachmentAllowed}}

                        <div class="scf-composer-attachments">

                            <ul class="scf-attachment-list scf-js-composer-att"></ul>

                        </div>

                    {{/if}}

                </div>

            </form>

            <button evt="click=styleView" class="scf-composer-action button-style">{{i18n "Style"}}</button>

        </div>

    {{/if}}

    <ul id="ul-comments" class="scf-comments-list">

        {{#each items}}

            {{#if isVisible}}

                {{include this resourceType='/apps/example/components/custom/comments/comment'}}

            {{/if}}

        {{/each}}

    </ul>

    <div class="scf-pages">

        <ul class="scf-pages-list">

            {{#pages pageInfo}}

                <li class="scf-pages-list-item">

                    <a class="scf-page{{#if currentPage}} scf-currentPage{{/if}}" data-page-suffix="{{suffix}}" evt="click=navigate">

{{pageNumber}}</a>

                </li>

            {{/pages}}

        </ul>

    </div>

</div>

2. Change your css.txt file so that it contains this:

customcommentsystem.css

3. In the same folder as your css.txt file, create a file called customcommentsystem.css and put this in it:

.button-style {

margin: 10px 0px 10px 0px;

}

#div-comments .button-style-clicked {

      border-radius: 20px;

          background: #F79F79;

}

#div-commentsystem .div-comments-styled {

          margin: 10px 0px 10px 0px;

          border: 0px;

          border-radius: 20px;

          background: #F7D08A;

}

#ul-comments .li-comment-styled {

          border-radius: 20px;

          background: #F7D08A;

          margin: 10px 0px 10px 0px;

}

4. Change your customcommentsystem.js file so that it contains this code:

(function($CQ, _, Backbone, SCF) {

    "use strict";

    var Comment = SCF.Components["social/commons/components/hbs/comments/comment"].Model;

    var CommentView = SCF.Components["social/commons/components/hbs/comments/comment"].View;

    var CommentSystem = SCF.Components["social/commons/components/hbs/comments"].Model;

    var CommentSystemView = SCF.Components["social/commons/components/hbs/comments"].View;

    var CustomCommentSystemView = CommentSystemView.extend({

                styleView: function() {

                           console.log("Entering the style function in the view.");

                           //Find the style button and style it

                           this.$el.find('.button-style').addClass("button-style-clicked");

                           //Find the cancel button and style it

                           this.$el.find('[type=reset]').addClass("button-style-clicked");

                           //Find the post button and style it

                           this.$el.find('[type=submit]').addClass("button-style-clicked");

                           //Find the comments system and style it

                           this.$el.find('.scf-composer-block').addClass("div-comments-styled");                               

                           //Find the posts and style them

                           this.$el.find('.scf-comment').addClass("li-comment-styled");                               

                           console.log("Exiting the style function in the view.")

                }

    });

    SCF.registerComponent('/apps/example/components/custom/comments/comment', Comment, CommentView);

    SCF.registerComponent('/apps/example/components/custom/comments', CustomCommentSystem, CustomCommentSystemView);

    })($CQ, _, Backbone, SCF);

5. Save your changes

6. Run an activation tree on the updated comment system component to publish it

Once the component is published, you should be able to load the page where the component is located and see a new button called “Style” on the comment system. Clicking the button will cause the component’s style to change like in the screenshot below.

This article outlined the steps for adding new functionality to an AEM 6.2 social component’s controller and provided the necessary guidance for completing Adobe’s comment system extension tutorial. As you can see, AEM development is not always straightforward but UDig has a team of experienced developers that can get the job done.

About The Author

Cody Halbleib is a Senior Consultant on the Software team. His family is his partner, Jamie, and his Border Collie mix, Walter.

Digging In

  • Digital Products

    Unlocking Business Potential: The Power of Custom Application Development

    Like any savvy business leader, you’re likely always on the lookout for tools to give your company a competitive edge. And in doing so, you’ve undoubtedly considered investing in custom application development. But the question is, how do you ensure that such a major investment in a custom web application development provides a strong return on […]

  • Digital Products

    Mastering Legacy Application Modernization: Strategies for Success

    The ironic truth of the business world is that change is the only constant. But this means that failing to keep pace with the competition and its technologies will only end with you falling behind. That’s where legacy application modernization enters the fold. When you modernize legacy applications, your team gains access to new features […]

  • Digital Products

    CTO Confessions Podcast

    In this episode of CTO Confessions, Rob Phillips, the Vice President of Software Engineering at UDig, digs into his journey from a passionate technologist in his youth to a seasoned leader in the tech industry. He shares valuable lessons on transitioning to senior leadership, the importance of understanding and articulating company problems, and the art of empowering teams for high performance.

  • Digital Products

    Navigating the Challenges of On Premise to Cloud Migration

    In today’s rapidly evolving technological landscape, the shift from on premise solutions to cloud-based infrastructure has become a pivotal transformation for organizations seeking to modernize their IT operations. This transition holds the promise of increased agility, cost savings, and enhanced scalability. However, it is not without its set of formidable challenges that organizations must navigate. […]

  • Digital Products

    The Power of Transferrable Skills in Tech Projects

    Every project has its own unique elements that require flexibility to be effective and achieve success. This often requires picking up new pieces of a tech stack, learning a new programming language, or a new project methodology. Fortunately, there are also many transferrable skills that carry over from one project to the next. In my […]

  • Digital Products

    The Four Pillars of Effective Digital Product Development

    In 2020 alone, approximately two billion consumers purchased at least one digital product. From software licenses to mobile apps and tech tools, consumers are becoming increasingly active in the digital product market, a trend that has naturally spurred brands across a wide range of industries to reevaluate their digital product design and development process workflows. […]