<commit_before><?php

App::uses('FormHelper', 'View/Helper');
App::uses('Hash', 'Utility');

class Bs3FormHelper extends FormHelper {

/**
 * Helpers
 *
 * @var array
 */
	public $helpers = array(
		'Bs3Html'
	);


/**
 * Available options.
 *
 * @var array
 */
	protected $_availableCustomOptions = array(
		'wrap',
		'externalWrap',
		'checkboxLabel',
		'beforeInput',
		'afterInput',
		'help',
		'errorClass',
		'showError',
		'errorMessage',
		'errorsAlwaysAsList',
		'inputGroup',
		'feedback',
		'renderErrorBlockAlways',
		'renderHelpBlockAlways',
		'submitDiv',
	);

/**
 * Default options for form.
 *
 * @var array
 */
	protected $_formDefaults = array(
		'role' => 'form'
	);

/**
 * Default options for inputs.
 * Used by default FormHelper class.
 *
 * @var array
 */
	protected $_predefinedInputDefaults = array(
		'all' => array(
			'div' => array(
				'class' => 'form-group'
			),
			'class' => 'form-control',
			'error' => array(
				'attributes' => array(
					'externalWrap' => 'div',
					'class' => 'help-block error-block'
				)
			),

			// Default custom options for all inputs
			'externalWrap' => false,
			'wrap' => false,
			'beforeInput' => false,
			'afterInput' => false,
			'checkboxLabel' => false,
			'help' => false,
			'errorClass' => 'has-error',
			'showError' => true, // Si mostrar o no error
			'errorMessage' => false, // Mensaje de error manual
			'errorsAlwaysAsList' => false,
			'inputGroup' => false,
			'feedback' => false,
			'renderErrorBlockAlways' => false,
			'renderHelpBlockAlways' => false,
			'submitDiv' => false
		),
		'default' => array(
			'label' => array(
				'class' => 'control-label'
			),
		),
		'horizontal' => array(
			'label' => array(
				'class' => 'col-sm-2 control-label'
			),
			'wrap' => 'col-sm-10',
			'submitDiv' => 'col-sm-10 col-sm-offset-2'
		),
		'inline' => array(
			'label' => array(
				'class' => 'sr-only'
			),
		),
	);

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customInputDefaults = array();

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customInputOptions = array();

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customFormOptions = array();

/**
 * Current input type
 *
 * @var string
 */
	protected $_inputType = null;

/**
 * Current field name
 *
 * @var string
 */
	protected $_fieldName = null;

/**
 * Current form type.
 * Can be 'horizontal', 'inline', 'default' or any type you configure.
 *
 * @var boolean
 */
	protected $_formStyle = null;

	protected $_hasFeedback = false;

/**
 * Redefine el metodo padre para aceptar configuraciones globales de forms, definidas en
 * bootstrap.php o por ej. en beforeRender de helper de app.
 * Configs. disponibles:
 * - Form.formDefaults
 * - Form.inputDefaults
 *
 * TODO: configs separadas por tipo de form
 *
 * @param mixed $model
 * @param array $options An array of html attributes and options.
 * @return string An formatted opening FORM tag.
 */
	public function create($model = null, $options = array()) {
		// Get form style
		$options = $this->_detectFormStyle($options);

		// Generate global input defaults
		$globalInputDefaults = Hash::merge($this->_predefinedInputDefaults, Configure::read('Bs3Form.inputDefaults'));
		// Generate form style defaults
		$styleInputDefaults = Hash::merge($globalInputDefaults['all'], $globalInputDefaults[$this->_formStyle]);
		// Merge with passed inputDefaults if any
		$passedInputDefaults = $this->_extractOption('inputDefaults', $options, array());
		// Set helper inputDefaults
		$inputDefaults = Hash::merge($styleInputDefaults, $passedInputDefaults);

		// Process custom input defaults and remove keys from passed options
		$this->_customInputDefaults = array();
		foreach ($this->_availableCustomOptions as $name) {
			if (isset($inputDefaults[$name])) {
				$this->_customInputDefaults[$name] = $inputDefaults[$name];
			}
			unset($inputDefaults[$name]);
		}
		$options['inputDefaults'] = $inputDefaults;
		$this->_baseInputDefaults = $inputDefaults;

		// Process form defaults
		$formDefaults = Hash::merge($this->_formDefaults, Configure::read('Bs3Form.formDefaults'));
		$options = Hash::merge($formDefaults, $options);
		$this->_customFormOptions = $options;

		$out = parent::create($model, $options);
		return $out;
	}

/**
 * Overrides parent method to add
 *
 * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
 * input fields where appropriate.
 *
 * If $options is set a form submit button will be created. Options can be either a string or an array.
 *
 * {{{
 * array usage:
 *
 * array('label' => 'save'); value="save"
 * array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
 * array('name' => 'Whatever'); value="Submit" name="Whatever"
 * array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
 * array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
 * }}}
 *
 * @param string|array $options as a string will use $options as the value of button,
 * @return string a closing FORM tag optional submit button.
 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#closing-the-form
 */
	public function end($options = null) {
		$wrap = false;
		if ($this->_formStyle == 'horizontal' && !isset($options['div'])) {
			if (is_string($options)) {
				$options = array('label' => $options);
			}
			$options['div'] = $this->_customInputDefaults['submitDiv'];
			$wrap = true;
		}
		$out = parent::end($options);

		if ($wrap) {
			$out = $this->Html->tag('div', $out, array('class' => 'form-group'));
		}

		$this->_customInputOptions = null;
		$this->_inputOptions = null;
		$this->_formStyle = null;
		return $out;
	}
<commit_msg>Updated end() method params for compatibility<commit_after><?php

App::uses('FormHelper', 'View/Helper');
App::uses('Hash', 'Utility');

class Bs3FormHelper extends FormHelper {

/**
 * Helpers
 *
 * @var array
 */
	public $helpers = array(
		'Bs3Html'
	);


/**
 * Available options.
 *
 * @var array
 */
	protected $_availableCustomOptions = array(
		'wrap',
		'externalWrap',
		'checkboxLabel',
		'beforeInput',
		'afterInput',
		'help',
		'errorClass',
		'showError',
		'errorMessage',
		'errorsAlwaysAsList',
		'inputGroup',
		'feedback',
		'renderErrorBlockAlways',
		'renderHelpBlockAlways',
		'submitDiv',
	);

/**
 * Default options for form.
 *
 * @var array
 */
	protected $_formDefaults = array(
		'role' => 'form'
	);

/**
 * Default options for inputs.
 * Used by default FormHelper class.
 *
 * @var array
 */
	protected $_predefinedInputDefaults = array(
		'all' => array(
			'div' => array(
				'class' => 'form-group'
			),
			'class' => 'form-control',
			'error' => array(
				'attributes' => array(
					'externalWrap' => 'div',
					'class' => 'help-block error-block'
				)
			),

			// Default custom options for all inputs
			'externalWrap' => false,
			'wrap' => false,
			'beforeInput' => false,
			'afterInput' => false,
			'checkboxLabel' => false,
			'help' => false,
			'errorClass' => 'has-error',
			'showError' => true, // Si mostrar o no error
			'errorMessage' => false, // Mensaje de error manual
			'errorsAlwaysAsList' => false,
			'inputGroup' => false,
			'feedback' => false,
			'renderErrorBlockAlways' => false,
			'renderHelpBlockAlways' => false,
			'submitDiv' => false
		),
		'default' => array(
			'label' => array(
				'class' => 'control-label'
			),
		),
		'horizontal' => array(
			'label' => array(
				'class' => 'col-sm-2 control-label'
			),
			'wrap' => 'col-sm-10',
			'submitDiv' => 'col-sm-10 col-sm-offset-2'
		),
		'inline' => array(
			'label' => array(
				'class' => 'sr-only'
			),
		),
	);

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customInputDefaults = array();

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customInputOptions = array();

/**
 * Handles custom options for current input.
 *
 * @var string
 */
	protected $_customFormOptions = array();

/**
 * Current input type
 *
 * @var string
 */
	protected $_inputType = null;

/**
 * Current field name
 *
 * @var string
 */
	protected $_fieldName = null;

/**
 * Current form type.
 * Can be 'horizontal', 'inline', 'default' or any type you configure.
 *
 * @var boolean
 */
	protected $_formStyle = null;

	protected $_hasFeedback = false;

/**
 * Redefine el metodo padre para aceptar configuraciones globales de forms, definidas en
 * bootstrap.php o por ej. en beforeRender de helper de app.
 * Configs. disponibles:
 * - Form.formDefaults
 * - Form.inputDefaults
 *
 * TODO: configs separadas por tipo de form
 *
 * @param mixed $model
 * @param array $options An array of html attributes and options.
 * @return string An formatted opening FORM tag.
 */
	public function create($model = null, $options = array()) {
		// Get form style
		$options = $this->_detectFormStyle($options);

		// Generate global input defaults
		$globalInputDefaults = Hash::merge($this->_predefinedInputDefaults, Configure::read('Bs3Form.inputDefaults'));
		// Generate form style defaults
		$styleInputDefaults = Hash::merge($globalInputDefaults['all'], $globalInputDefaults[$this->_formStyle]);
		// Merge with passed inputDefaults if any
		$passedInputDefaults = $this->_extractOption('inputDefaults', $options, array());
		// Set helper inputDefaults
		$inputDefaults = Hash::merge($styleInputDefaults, $passedInputDefaults);

		// Process custom input defaults and remove keys from passed options
		$this->_customInputDefaults = array();
		foreach ($this->_availableCustomOptions as $name) {
			if (isset($inputDefaults[$name])) {
				$this->_customInputDefaults[$name] = $inputDefaults[$name];
			}
			unset($inputDefaults[$name]);
		}
		$options['inputDefaults'] = $inputDefaults;
		$this->_baseInputDefaults = $inputDefaults;

		// Process form defaults
		$formDefaults = Hash::merge($this->_formDefaults, Configure::read('Bs3Form.formDefaults'));
		$options = Hash::merge($formDefaults, $options);
		$this->_customFormOptions = $options;

		$out = parent::create($model, $options);
		return $out;
	}

/**
 * Overrides parent method to add
 *
 * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
 * input fields where appropriate.
 *
 * If $options is set a form submit button will be created. Options can be either a string or an array.
 *
 * {{{
 * array usage:
 *
 * array('label' => 'save'); value="save"
 * array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever"
 * array('name' => 'Whatever'); value="Submit" name="Whatever"
 * array('label' => 'save', 'name' => 'Whatever', 'div' => 'good') <div class="good"> value="save" name="Whatever"
 * array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')); <div class="good"> value="save" name="Whatever"
 * }}}
 *
 * @param string|array $options as a string will use $options as the value of button,
 * @return string a closing FORM tag optional submit button.
 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#closing-the-form
 */
	public function end($options = null, $secureAttributes = array()) {
		$wrap = false;
		if ($this->_formStyle == 'horizontal' && !isset($options['div'])) {
			if (is_string($options)) {
				$options = array('label' => $options);
			}
			$options['div'] = $this->_customInputDefaults['submitDiv'];
			$wrap = true;
		}
		$out = parent::end($options);

		if ($wrap) {
			$out = $this->Html->tag('div', $out, array('class' => 'form-group'));
		}

		$this->_customInputOptions = null;
		$this->_inputOptions = null;
		$this->_formStyle = null;
		return $out;
	}

{'fraction_non_alphanumeric': 0.1698368416603263, 'fraction_numerical': 0.002028911995942176, 'mean_word_length': 3.8623099054665024, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2335191', 'n_tokens_mistral': 4147, 'n_tokens_neox': 3712, 'n_words': 993}