/** * Constructor * * @param $name * @param array $options * @param array $attributes */ public function __construct($name, $options = null, $attributes = null) { if (!isset($attributes['value'])) { /** * @var CoreLanguages $defaultLanguage */ $defaultLanguage = CoreLanguages::findFirst('is_default = 1'); $attributes['value'] = $defaultLanguage->language_code; } $attributes['using'] = ['language_code', 'title']; $options = CoreLanguages::find(['order' => 'title ASC']); parent::__construct($name, $options, $attributes); }
/** * @param string $name * @param array $options * @param array $attributes */ public function __construct($name, $options = null, $attributes = null) { if (!is_array($options)) { $options = []; } $optionsData = !empty($options['options']) ? $options['options'] : null; unset($options['options']); if (!is_array($attributes)) { $attributes = []; } $options = array_merge($options, $attributes); parent::__construct($name, $optionsData, $options); }
public function __construct($name, $options = null, $attributes = null) { $empty = isset($attributes['allowEmpty']) ? $attributes['allowEmpty'] : false; if ($options instanceof ChoiceList) { $this->addValidator(new Validator\InclusionIn(array('message' => 'invalid value selected', 'domain' => $options->getValues(), 'allowEmpty' => $empty))); // if choices are multidimensional, need to send a plain array to phalcon $choices = $options->getChoices(); if (count($choices) != count($choices, COUNT_RECURSIVE) && !isset($attributes['using'])) { $options = $options->getChoices(); } else { $attributes['using'] = array('key', 'value'); } } else { if ($options instanceof Resultset) { $this->addValidator(new EveValidator\ModelIn(array('message' => 'invalid value selected', 'domain' => $options, 'using' => reset($attributes['using']), 'allowEmpty' => $empty))); } } return parent::__construct($name, $options, $attributes); }
/** * @param string $name The element name * @param array $attributes The attributes (see below) * * The following attributes can be specified: * * 'key': * the types that will be used as the POST value (pref.code|ja|en|ja.kana) * 'display': * the types that are going to be displayed as select options (pref.code|ja|en|ja.kana) * * If the above are not specified, ja or en will be chosen based on the current locale. * * About the available types: * pref.code: prefecture code as in 'ISO 3166-2:JP' (JP-00 is used for overseas) * ja: prefecture names in japanese (kanji) * ja.kana: prefecutre names in japanese (hiragana) * en: prefecture name in english * * 'with_overseas': * Another field that represents overseas is added to the options. (JP-00|海外|Overseas|かいがい) * * 'noValidation': * Skip checking for valid values */ public function __construct($name, $attributes = array()) { if (!array_key_exists('elements', $attributes)) { $options = array('' => ''); } else { $options = $attributes['elements']; unset($attributes['elements']); } $key = empty($attributes['key']) ? NULL : $attributes['key']; $value = empty($attributes['display']) ? NULL : $attributes['display']; foreach (self::$prefectures as $row) { if (empty($attributes['with_overseas']) && $row['pref.code'] == 'JP-00') { continue; } $options[self::resolve($row['pref.code'], $key)] = self::resolve($row['pref.code'], $value); } unset($attributes['key']); unset($attributes['display']); parent::__construct($name, $options, $attributes); if (empty($attributes['noValidation'])) { $this->addValidator(new InclusionIn(['domain' => array_keys($options)])); } }
/** * \Phalcon\Forms\Element constructor * * @param string $name * @param object|array $options * @param array $attributes * @param string $transPrefix translation table prefix */ public function __construct($name, $options = null, $attributes = null, $transPrefix = '') { $this->transPrefix = strval($transPrefix); return parent::__construct($name, $options, $attributes); }