Beispiel #1
0
	/**
	 * Retrieve the label text
	 *
	 * @access public
	 * @return void
	 */
	public function label($utf8 = FALSE)
	{
		$label = ($label = $this->_field->get('label'))
			? $label
			: $this->_field->alias();

		// Translate if needed
		return (Formo::config($this->_field, 'translate') === TRUE)
			? __($label)
			: $label;
	}
Beispiel #2
0
 protected function _add_input_rules()
 {
     // Grab the rules from the formo config
     $rules = Formo::config($this->_field, 'input_rules.' . $this->get_type());
     if ($rules) {
         // Attach rules to the field's parent
         $this->_field->parent()->rules($this->_field->alias(), $rules);
     }
     if ($bindings = Formo::config($this->_field, 'formo.html5_bindings.' . $this->get_type())) {
         $this->_field->set('bindings', $bindings);
     }
 }
Beispiel #3
0
 public function translate($str)
 {
     $new_str = $str;
     if (Formo::config($this->_field, 'use_messages') === TRUE) {
         $msg_file = Formo::config($this->_field, 'message_file');
         $new_str = Kohana::message($msg_file, $str, $str);
     }
     if (Formo::config($this->_field, 'translate') === TRUE) {
         $new_str = __($new_str);
     }
     return $new_str;
 }
Beispiel #4
0
 public function message_file()
 {
     return Formo::config($this, 'message_file');
 }
Beispiel #5
0
 protected function _get_view_prefix($prefix = NULL)
 {
     // If the specified prefix is FALSE, no prefix
     if ($prefix === FALSE) {
         return FALSE;
     }
     // If the prefix was specified, use it
     if ($prefix !== NULL) {
         return rtrim($prefix, '/');
     }
     // Find the appropriate view_prefix
     $prefix = $this->_field->get('view_prefix', NULL);
     if ($prefix === NULL) {
         $prefix = ($parent = $this->_field->parent()) ? $parent->get('view_prefix', NULL) : NULL;
         // Set the view prefix so children can use it
         $this->_field->set('view_prefix', $prefix);
     }
     // If prefix is still set to NULL and config file has one defined, use the config prefix
     if ($prefix === NULL and $_prefix = Formo::config($this->_field, 'view_prefix')) {
         $prefix = $_prefix;
     }
     return $prefix;
 }
Beispiel #6
0
	protected function _get_message_file($file)
	{
		if ($file === NULL)
		{
			$file = Formo::config($this, 'message_file');
		}
		
		return $file;
	}
Beispiel #7
0
	/**
	 * Add options for relational fields (checkboxes, radios, select options)
	 *
	 * @access protected
	 * @param mixed ORM $query
	 * @param mixed array & $options
	 * @return void
	 */
	protected function _add_options($alias, ORM $query, array & $options)
	{
		// First check to see if there are any query options to limit the records
		if ($limit = $this->_form->$alias->get('records'))
		{
			$query = $limit($query);
		}

		// Create the array
		$opts = array();
		foreach ($query->find_all() as $row)
		{
			$primary_key = $row->primary_key();

			$primary_val = Formo::config($this->_form->$alias, 'orm_primary_val');

			// Use the primary value
			$opts[$row->{$primary_val}] = $row->{$primary_key};
		}

		// Add the options to the field
		$options['options'] = $opts;
	}
Beispiel #8
0
 /**
  * Load an orm driver instance
  *
  * @access public
  * @param mixed $save_instance. (default: FALSE)
  * @return Formo_ORM object
  */
 public function orm_driver($save_instance = TRUE)
 {
     if (!$this instanceof Formo_Form) {
         return $this->parent()->orm_driver(TRUE);
     }
     if ($instance = $this->get('orm_driver_instance')) {
         // If the instance exists, return it
         return $instance;
     }
     // Get the driver neame
     $driver = Formo::config($this, 'orm_driver');
     // Create the new instance
     $instance = new $driver($this);
     if ($save_instance === TRUE) {
         // Save the instance if asked to
         $this->set('orm_driver_instance', $instance);
     }
     $this->_loaded['orm'] = TRUE;
     // REturn the new orm driver instance
     return $instance;
 }
Beispiel #9
0
 public function close()
 {
     $singletag = in_array($this->_vars['tag'], $this->_singles);
     // Let the config file determine whether to close the tags
     $closetag = Formo::config($this->_field, 'close_single_html_tags') === TRUE ? '/' : NULL;
     if ($singletag === TRUE) {
         return $closetag . '>' . "\n";
     } else {
         return '</' . $this->_vars['tag'] . '>' . "\n";
     }
 }
Beispiel #10
0
	/**
	 * Renders the form according to the config file's "render" setting
	 *
	 * @access public
	 * @return void
	 */
	public function __toString()
	{
		// Render as the default render type
		return $this->render(Formo::config($this, 'render_type'));
	}
Beispiel #11
0
 /**
  * Renders the form according to the config file's "render" setting
  *
  * @access public
  * @return void
  */
 public function __toString()
 {
     // Render as the default render type
     try {
         return $this->render(Formo::config($this, 'render_type'));
     } catch (Exception $e) {
         return "Error rendering form:" . $e->getMessage();
     }
 }