Uploaded image for project: 'Magnolia Site Module'
  1. Magnolia Site Module
  2. MGNLSITE-38

Provide in SiteFunctions: Nested call to get theme and additonal null handling.

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Neutral Neutral
    • None
    • 1.0.2
    • api
    • None
    • Yes

      When you need the current configured theme you need to retrieve it with two calls:

      [#assign currentSite = sitefn.site(content)]
      [#assign currentTheme = sitefn.theme(currentSite)]
      
      //Clear, you can also do it in one line of code, but its still two calls:
      [#assign currentTheme = sitefn.theme(sitefn.site(content)))]
      

      Which is a bit confusing for beginners. And also its more error prone and less straight forward.

      It would be easy to provide it in one method fir getting the theme accepting Node, doing the nested call:

      [#assign currentTheme = sitefn.theme(content)]
      

      Would look like this:

      public Theme theme(Node content) {
          	if(content == null) return null;
          	Site site = this.site(content);
          	return (site == null) ? null : this.theme(site);
          }
      

      I included a patch containing the code, and also a version for ContentMap.

      Also I added into the patch some missing null handling in:

      public Theme theme(Site site) {
      // site.getTheme().getName(); will produce NPE
      

      And

      public Site site(ContentMap content) {
      // content.getJCRNode(); will produce NPE
      

        Acceptance criteria

              Unassigned Unassigned
              cringele Christian Ringele
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD