Exemple #1
0
 /**
  * Renders the element widget returning html
  *
  * @param array|null $attributes
  * @return string
  * @throws Exception
  */
 public function render($attributes = null)
 {
     if (is_array($attributes) === false && is_null($attributes) === false) {
         throw new Exception('Invalid parameter type.');
     }
     return Tag::checkField($this->prepareAttributes($attributes, true));
 }
Exemple #2
0
 /**
  * Registers common function in Twig
  *
  * @param \Phalcon\Mvc\ViewInterface $view
  * @param \Phalcon\DiInterface       $di
  * @param array                      $userFunctions
  */
 protected function registryFunctions($view, DiInterface $di, $userFunctions = array())
 {
     $options = array('is_safe' => array('html'));
     $functions = array(new \Twig_SimpleFunction('content', function () use($view) {
         return $view->getContent();
     }, $options), new \Twig_SimpleFunction('partial', function ($partialPath) use($view) {
         return $view->partial($partialPath);
     }, $options), new \Twig_SimpleFunction('linkTo', function ($parameters, $text = null) {
         return \Phalcon\Tag::linkTo($parameters, $text);
     }, $options), new \Twig_SimpleFunction('textField', function ($parameters) {
         return \Phalcon\Tag::textField($parameters);
     }, $options), new \Twig_SimpleFunction('passwordField', function ($parameters) {
         return \Phalcon\Tag::passwordField($parameters);
     }, $options), new \Twig_SimpleFunction('hiddenField', function ($parameters) {
         return \Phalcon\Tag::hiddenField($parameters);
     }, $options), new \Twig_SimpleFunction('fileField', function ($parameters) {
         return \Phalcon\Tag::fileField($parameters);
     }, $options), new \Twig_SimpleFunction('checkField', function ($parameters) {
         return \Phalcon\Tag::checkField($parameters);
     }, $options), new \Twig_SimpleFunction('radioField', function ($parameters) {
         return \Phalcon\Tag::radioField($parameters);
     }, $options), new \Twig_SimpleFunction('submitButton', function ($parameters) {
         return \Phalcon\Tag::submitButton($parameters);
     }, $options), new \Twig_SimpleFunction('selectStatic', function ($parameters, $data = array()) {
         return \Phalcon\Tag::selectStatic($parameters, $data);
     }, $options), new \Twig_SimpleFunction('select', function ($parameters, $data = array()) {
         return \Phalcon\Tag::select($parameters, $data);
     }, $options), new \Twig_SimpleFunction('textArea', function ($parameters) {
         return \Phalcon\Tag::textArea($parameters);
     }, $options), new \Twig_SimpleFunction('form', function ($parameters = array()) {
         return \Phalcon\Tag::form($parameters);
     }, $options), new \Twig_SimpleFunction('endForm', function () {
         return \Phalcon\Tag::endForm();
     }, $options), new \Twig_SimpleFunction('getTitle', function () {
         return \Phalcon\Tag::getTitle();
     }, $options), new \Twig_SimpleFunction('stylesheetLink', function ($parameters = null, $local = true) {
         return \Phalcon\Tag::stylesheetLink($parameters, $local);
     }, $options), new \Twig_SimpleFunction('javascriptInclude', function ($parameters = null, $local = true) {
         return \Phalcon\Tag::javascriptInclude($parameters, $local);
     }, $options), new \Twig_SimpleFunction('image', function ($parameters) {
         return \Phalcon\Tag::image($parameters);
     }, $options), new \Twig_SimpleFunction('friendlyTitle', function ($text, $separator = null, $lowercase = true) {
         return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase);
     }, $options), new \Twig_SimpleFunction('getDocType', function () {
         return \Phalcon\Tag::getDocType();
     }, $options), new \Twig_SimpleFunction('getSecurityToken', function () use($di) {
         return $di->get("security")->getToken();
     }, $options), new \Twig_SimpleFunction('getSecurityTokenKey', function () use($di) {
         return $di->get("security")->getTokenKey();
     }, $options), new \Twig_SimpleFunction('url', function ($route) use($di) {
         return $di->get("url")->get($route);
     }, $options));
     if (!empty($userFunctions)) {
         $functions = array_merge($functions, $userFunctions);
     }
     foreach ($functions as $function) {
         $this->twig->addFunction($function);
     }
 }
Exemple #3
0
 /**
  * Registers common function in Twig
  *
  * @param \Phalcon\Mvc\ViewInterface $view
  */
 private function registryFunctions($view)
 {
     $options = array('is_safe' => array('html'));
     $functions = array(new \Twig_SimpleFunction('content', function () use($view) {
         return $view->getContent();
     }, $options), new \Twig_SimpleFunction('partial', function ($partialPath) use($view) {
         return $view->partial($partialPath);
     }, $options), new \Twig_SimpleFunction('linkTo', function ($parameters, $text = null) {
         return \Phalcon\Tag::linkTo($parameters, $text);
     }, $options), new \Twig_SimpleFunction('textField', function ($parameters) {
         return \Phalcon\Tag::textField($parameters);
     }, $options), new \Twig_SimpleFunction('passwordField', function ($parameters) {
         return \Phalcon\Tag::passwordField($parameters);
     }, $options), new \Twig_SimpleFunction('hiddenField', function ($parameters) {
         return \Phalcon\Tag::hiddenField($parameters);
     }, $options), new \Twig_SimpleFunction('fileField', function ($parameters) {
         return \Phalcon\Tag::fileField($parameters);
     }, $options), new \Twig_SimpleFunction('checkField', function ($parameters) {
         return \Phalcon\Tag::checkField($parameters);
     }, $options), new \Twig_SimpleFunction('radioField', function ($parameters) {
         return \Phalcon\Tag::radioField($parameters);
     }, $options), new \Twig_SimpleFunction('submitButton', function ($parameters) {
         return \Phalcon\Tag::submitButton($parameters);
     }, $options), new \Twig_SimpleFunction('selectStatic', function ($parameters, $data = []) {
         return \Phalcon\Tag::selectStatic($parameters, $data);
     }, $options), new \Twig_SimpleFunction('select', function ($parameters, $data = []) {
         return \Phalcon\Tag::select($parameters, $data);
     }, $options), new \Twig_SimpleFunction('textArea', function ($parameters) {
         return \Phalcon\Tag::textArea($parameters);
     }, $options), new \Twig_SimpleFunction('form', function ($parameters = []) {
         return \Phalcon\Tag::form($parameters);
     }, $options), new \Twig_SimpleFunction('endForm', function () {
         return \Phalcon\Tag::endForm();
     }, $options), new \Twig_SimpleFunction('getTitle', function () {
         return \Phalcon\Tag::getTitle();
     }, $options), new \Twig_SimpleFunction('getTitle', function () {
         return \Phalcon\Tag::getTitle();
     }, $options), new \Twig_SimpleFunction('stylesheetLink', function ($parameters = null, $local = true) {
         return \Phalcon\Tag::stylesheetLink($parameters, $local);
     }, $options), new \Twig_SimpleFunction('javascriptInclude', function ($parameters = null, $local = true) {
         return \Phalcon\Tag::javascriptInclude($parameters, $local);
     }, $options), new \Twig_SimpleFunction('image', function ($parameters) {
         return \Phalcon\Tag::image($parameters);
     }, $options), new \Twig_SimpleFunction('friendlyTitle', function ($text, $separator = null, $lowercase = true) {
         return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase);
     }, $options), new \Twig_SimpleFunction('getDocType', function () {
         return \Phalcon\Tag::getDocType();
     }, $options));
     foreach ($functions as $function) {
         $this->_twig->addFunction($function);
     }
 }
Exemple #4
0
 public function getCheckboxes()
 {
     $value = $this->getValue();
     $checkboxes = array();
     if (!is_array($value)) {
         $value = array($value);
     }
     foreach ($this->_field_options as $check_key => $check_val) {
         $field_options = array($this->_name . '[]');
         $field_options['value'] = $check_key;
         $field_options['id'] = $this->_name . '_' . $check_key;
         if (in_array($check_key, $value)) {
             $field_options['checked'] = 'checked';
         }
         $checkbox_code = \Phalcon\Tag::checkField($field_options);
         $checkboxes[] = '<label>' . $checkbox_code . ' <span>' . $check_val . '</span></label>';
     }
     return $checkboxes;
 }
Exemple #5
0
 public static function checkField($parameters)
 {
     return parent::checkField($parameters);
 }
Exemple #6
0
 /**
  * Tests checkField with displayTo
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2012-10-26
  */
 public function testCheckFieldDisplayToElementNotPresentXHTML()
 {
     \Phalcon\Tag::setDoctype(\Phalcon\Tag::XHTML10_STRICT);
     $options = array('some_field_name', 'class' => 'some_class', 'size' => '10');
     \Phalcon\Tag::displayTo('some_field', 'some_default_value');
     $expected = '<input type="checkbox" id="some_field_name" name="some_field_name" value="" class="some_class" size="10" />';
     $actual = \Phalcon\Tag::checkField($options);
     \Phalcon\Tag::displayTo('some_field', '');
     \Phalcon\Tag::setDoctype('');
     $this->assertEquals($expected, $actual, sprintf($this->message, 'XHTML checkField with displayTo'));
 }
Exemple #7
0
 /**
  * Create checkfield with bootstrap style
  * @param string $attribute
  * @param array $params
  * @param string $text
  * @return string
  */
 public function checkField($attribute, $params = [], $text = '')
 {
     array_unshift($params, $attribute);
     $input = Tag::checkField($params);
     return $this->startDefault('checkbox') . "<label class='pull-left control-label'> {$input}  {$text} </label>" . $this->endDefault();
 }