* @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ App::uses('AppHelper', 'View/Helper'); /** * FormInputHelper * * @package NetCommons\NetCommons\View\Helper */ class FormInputHelper extends AppHelper { /** * 使用するHelpers * * - [FormHelper](http://book.cakephp.org/2.0/ja/core-libraries/helpers/form.html) * - [HtmlHelper](http://book.cakephp.org/2.0/ja/core-libraries/helpers/html.html) * - [NetCommons.NetCommonsFormHelper](../../NetCommons/classes/NetCommonsFormHelper.html) * * @var array */ public $helpers = array( 'Form', 'Html', 'NetCommons.NetCommonsForm', 'Users.DisplayUser', ); /** * $optionsの中身をarray('div' => css文字列)をarray('div' => ['class' => css文字列])に変換して出力する * * @param string $type inputのタイプ * @param array $options inputのオプション配列 * @param string $key オプションキー * @param mixed $default デフォルト値 * @return array $options divオプション */ public function getDivOption($type, $options, $key, $default = array()) { $divOption = Hash::get($options, $key, $default); if (is_string($divOption)) { $divOption = array('class' => $divOption); } $outer = Hash::get($options, 'outer', false); if ($outer && in_array($type, ['radio', 'checkbox'], true)) { if (! $divOption) { $divOption = array(); } $divOption['class'] = Hash::get($divOption, 'class', ''); $divOption['class'] .= ' form-' . $type . '-outer'; $divOption['class'] = trim($divOption['class']); } return $divOption; } /** * ラジオボタンを出力する * * #### サンプル * - 入力 * ``` * ``` * - 出力 * ``` * ``` * * @param string $fieldName フィールド名("Modelname.fieldname"形式) * @param array $options radioのオプション配列 * @param array $attributes HTML属性オプション配列 * @return string * @see http://book.cakephp.org/2.0/ja/core-libraries/helpers/form.html#FormHelper::radio FormHelper::radio() * @see http://book.cakephp.org/2.0/ja/core-libraries/helpers/form.html#select-checkbox-radio checkbox, radio に関するオプション */ public function radio($fieldName, $options = array(), $attributes = array()) { $defaultAttributes = array( 'error' => false, 'div' => false, 'label' => false, 'legend' => false, ); $divOption = $this->getDivOption('radio', $attributes, 'div', array()); $attributes = Hash::merge($defaultAttributes, $attributes); $attributes = Hash::insert($attributes, 'div', false); //後で消すかも if ($divOption && strpos(Hash::get($divOption, 'class', ''), 'form-inline') !== false) { $attributes = Hash::insert($attributes, 'inline', true); } $radioClass = 'radio'; if (Hash::get($attributes, 'inline')) { $radioClass .= ' radio-inline'; $attributes = Hash::remove($attributes, 'inline'); } $input = ''; $befor = Hash::get($attributes, 'before', ''); $separator = Hash::get($attributes, 'separator', ''); $separator = '' . $separator . '