Author: jablko
Date: Fri Sep  4 12:12:56 2009
New Revision: 3173

Log:
Move widget help texts from sfWidgetFormSchema to sfWidgetForm, like widget 
labels. Add default help text to sfWidgetFormInputFile, 
http://trac.symfony-project.org/ticket/7108

Modified:
   trunk/lib/vendor/symfony/lib/widget/sfWidgetForm.class.php
   trunk/lib/vendor/symfony/lib/widget/sfWidgetFormInputFile.class.php
   trunk/lib/vendor/symfony/lib/widget/sfWidgetFormSchema.class.php

Modified: trunk/lib/vendor/symfony/lib/widget/sfWidgetForm.class.php
==============================================================================
--- trunk/lib/vendor/symfony/lib/widget/sfWidgetForm.class.php  Fri Sep  4 
10:40:33 2009        (r3172)
+++ trunk/lib/vendor/symfony/lib/widget/sfWidgetForm.class.php  Fri Sep  4 
12:12:56 2009        (r3173)
@@ -86,6 +86,26 @@
   }
 
   /**
+   * Sets the help for the widget.
+   *
+   * @param string $value The help
+   */
+  public function setHelp($value)
+  {
+    $this->setOption('help', $value);
+  }
+
+  /**
+   * Returns the help for the widget.
+   *
+   * @return string The help
+   */
+  public function getHelp()
+  {
+    return $this->getOption('help');
+  }
+
+  /**
    * Sets the format for HTML id attributes.
    *
    * @param string $format  The format string (must contain a %s for the id 
placeholder)

Modified: trunk/lib/vendor/symfony/lib/widget/sfWidgetFormInputFile.class.php
==============================================================================
--- trunk/lib/vendor/symfony/lib/widget/sfWidgetFormInputFile.class.php Fri Sep 
 4 10:40:33 2009        (r3172)
+++ trunk/lib/vendor/symfony/lib/widget/sfWidgetFormInputFile.class.php Fri Sep 
 4 12:12:56 2009        (r3173)
@@ -31,4 +31,43 @@
     $this->setOption('type', 'file');
     $this->setOption('needs_multipart', true);
   }
+
+  protected function getBytes($value)
+  {
+    $value = trim($value);
+    switch (strtolower($value[strlen($value) - 1]))
+    {
+      // The 'G' modifier is available since PHP 5.1.0
+      case 'g':
+        $value *= 1024;
+      case 'm':
+        $value *= 1024;
+      case 'k':
+        $value *= 1024;
+    }
+
+    return $value;
+  }
+
+  public function getHelp()
+  {
+    if ($this->hasOption('help'))
+    {
+      return $this->getOption('help');
+    }
+
+    $size = min($this->getBytes(ini_get('post_max_size')), 
$this->getBytes(ini_get('upload_max_filesize')));
+    foreach (array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') as 
$unit)
+    {
+      // 0.9# if > 1000, ### if < 1000
+      if (1000 > $size)
+      {
+        break;
+      }
+
+      $size /= 1024;
+    }
+
+    return 'The maximum size of file uploads is '.round($size, 2).' 
'.$unit.'.';
+  }
 }

Modified: trunk/lib/vendor/symfony/lib/widget/sfWidgetFormSchema.class.php
==============================================================================
--- trunk/lib/vendor/symfony/lib/widget/sfWidgetFormSchema.class.php    Fri Sep 
 4 10:40:33 2009        (r3172)
+++ trunk/lib/vendor/symfony/lib/widget/sfWidgetFormSchema.class.php    Fri Sep 
 4 12:12:56 2009        (r3173)
@@ -34,8 +34,7 @@
     $formFormatters = array(),
     $options        = array(),
     $fields         = array(),
-    $positions      = array(),
-    $helps          = array();
+    $positions      = array();
 
   /**
    * Constructor.
@@ -80,7 +79,7 @@
     }
 
     $this->setLabels($labels);
-    $this->helps = $helps;
+    $this->setHelps($helps);
   }
 
   /**
@@ -359,40 +358,83 @@
    */
   public function setHelps(array $helps)
   {
-    $this->helps = $helps;
+    foreach ($this->fields as $name => $widget)
+    {
+      if (array_key_exists($name, $helps))
+      {
+        $widget->setHelp($helps[$name]);
+      }
+    }
   }
 
   /**
-   * Sets the help texts.
+   * Gets the help texts.
    *
    * @return array An array of help texts
    */
   public function getHelps()
   {
-    return $this->helps;
+    $helps = array();
+
+    foreach ($this->fields as $name => $widget)
+    {
+      $helps[$name] = $widget->getHelp();
+    }
+
+    return $helps;
   }
 
   /**
    * Sets a help text.
    *
    * @param string $name The field name
-   * @param string $help The help text
+   * @param string $value The help name (required - the default value is here 
because PHP do not allow signature changes with inheritance)
+   *
+   * @throws InvalidArgumentException when you try to set a help on a none 
existing widget
    */
-  public function setHelp($name, $help)
+  public function setHelp($name, $value = null)
   {
-    $this->helps[$name] = $help;
+    if (2 == func_num_args())
+    {
+      if (!isset($this->fields[$name]))
+      {
+        throw new InvalidArgumentException(sprintf('Unable to set the help on 
an unexistant widget ("%s").', $name));
+      }
+
+      $this->fields[$name]->setHelp($value);
+    }
+    else
+    {
+      // set the help for this widget schema
+      parent::setHelp($name);
+    }
   }
 
   /**
-   * Gets a text help by field name.
+   * Gets a help text by field name.
    *
-   * @param string $name The field name
+   * @param string $name The field name (required - the default value is here 
because PHP do not allow signature changes with inheritance)
    *
    * @return string The help text or an empty string if it is not defined
+   *
+   * @throws InvalidArgumentException when you try to get a help for a none 
existing widget
    */
-  public function getHelp($name)
+  public function getHelp($name = null)
   {
-    return array_key_exists($name, $this->helps) ? $this->helps[$name] : '';
+    if (1 == func_num_args())
+    {
+      if (!isset($this->fields[$name]))
+      {
+        throw new InvalidArgumentException(sprintf('Unable to get the help on 
an unexistant widget ("%s").', $name));
+      }
+
+      return $this->fields[$name]->getHelp();
+    }
+    else
+    {
+      // help for this widget schema
+      return parent::getHelp();
+    }
   }
 
   /**

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to