Reviewers: chabotc, lindner_apache.org,

Description:
Fix issue Shinidg-1262:
http://issues.apache.org/jira/browse/SHINDIG-1262

Please review this at http://codereview.appspot.com/217112/show

Affected files:
  php/src/gadgets/render/GadgetBaseRenderer.php


Index: php/src/gadgets/render/GadgetBaseRenderer.php
===================================================================
--- php/src/gadgets/render/GadgetBaseRenderer.php       (revision 915652)
+++ php/src/gadgets/render/GadgetBaseRenderer.php       (working copy)
@@ -331,6 +331,7 @@
     $script .= "\n";
$script .= $this->appendJsConfig($this->gadget, $sortedExternFeatures, $sortedInlineFeatures);
     $script .= $this->appendMessages($this->gadget);
+    $script .= $this->appendPreferences($this->gadget);
     $script .= $this->appendPreloads($this->gadget);
     if (count($this->dataInserts)) {
       foreach ($this->dataInserts as $data) {
@@ -467,14 +468,22 @@
    * @return string
    */
   private function appendMessages(Gadget $gadget) {
-    $msgs = '';
-    if (! empty($gadget->gadgetSpec->locales)) {
-      $msgs = json_encode($gadget->gadgetSpec->locales);
-    }
+    $msgs = json_encode($this->dataContext['Msg']);
     return "gadgets.Prefs.setMessages_($msgs);\n";
   }

   /**
+   * Injects the pre-defined user preferences into the javascript api
+   *
+   * @param Gadget $gadget
+   * @return string
+   */
+  private function appendPreferences(Gadget $gadget) {
+    $prefs = json_encode($this->dataContext['UserPrefs']);
+    return "gadgets.Prefs.setDefaultPrefs_($prefs);\n";
+  }
+
+  /**
    * Injects the preloaded content into the javascript api
    *
    * @param Gadget $gadget


Reply via email to