Profile Tabs

The header contains a link to display the current user’s profile in a widget. The default implementation displays two tabs in the widget: Profile and Looking Glass.

../../../_images/default-profile-tabs.svg

You can add custom tabs to the profile widget by extending the ProfilePanelTab class. The following example creates a My Articles profile tab that lists the current user’s 10 most recently published articles.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package profiletabs;

import com.psddev.dari.util.PaginatedResult;
import content.article.Article;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class MySummaryTab extends ProfilePanelTab {

    @Override
    public void writeHtml(ToolPageContext page) throws IOException, ServletException {

        UUID uuid = page.getUser().getId();

        PaginatedResult<Article> articles = Query.from(Article.class)
                .where("cms.content.publishUser = ?", uuid)
                .sortDescending("cms.content.publishDate")
                .select(0, 10);

        List<Article> myArticles = articles.getItems();

        page.writeStart("div",
                "class", "p-tud-lg tabbed",
                "data-tab", "My Articles");
            page.writeStart("h1");
                page.writeHtml("My Articles");
            page.writeEnd();
            page.writeStart("h2");
                page.writeHtml("The following table lists your 10 most recently published articles.");
            page.writeEnd();
            page.writeStart("table");
                page.writeStart("tr");
                    page.writeStart("th");
                        page.writeHtml("Headline");
                    page.writeEnd(); /* th */
                    page.writeStart("th");
                        page.writeHtml("Date Activity");
                    page.writeEnd(); /* th */
                page.writeEnd(); /* tr */

                for (Article article : myArticles) {
                    page.writeStart("tr");
                        page.writeStart("td");
                            page.writeHtml(article.getHeadline());
                        page.writeEnd(); /* td */
                        page.writeStart("td");
                            page.writeHtml(article.getPublishDate());
                        page.writeEnd(); /* td */
                    page.writeEnd(); /* tr */
                }

            page.writeEnd(); /* table */
        page.writeEnd(); /* div */
    }
}

In the previous snippet—

  • Line 11 declares a class that extends from ProfilePanelTab—the class that outputs to a custom profile widget.
  • Lines 13–57 override the method writeHtml, which directs output to the custom tab.
  • Lines 18–21 retrieve the current user’s 10 most recently published articles.
  • Lines 25–27 create the new tab with the label My Articles. Any nested page.write statements write to this tab.
  • Lines 44–53 loop through the found articles and output the headline and date published for each.
../../../_images/custom-profile-tab.png

See also: