Наследование: extends Cake\View\Helper\HtmlHelper, use trait BootstrapTrait
Пример #1
0
 public function link($title, $url = null, array $options = [])
 {
     $default = ['iconDirection' => 'left', 'class' => '', 'preserveUrl' => false];
     $options = \Cake\Utility\Hash::merge($default, $options);
     if ($options['preserveUrl'] === true) {
         if (is_array($url)) {
             if (count($this->request->query)) {
                 $url = array_merge(['?' => $this->request->query], $url);
             }
         }
     }
     if (!isset($options['icon'])) {
         if (isset($url['action'])) {
             switch ($url['action']) {
                 case 'add':
                     $title = $this->iconDirection($title, 'save', $options['iconDirection']);
                     $options['class'] .= ' btn-success ';
                     break;
                 case 'edit':
                     $title = $this->iconDirection($title, 'pencil', $options['iconDirection']);
                     $options['class'] .= ' btn-warning ';
                     break;
                 case 'list':
                     $title = $this->iconDirection($title, 'search', $options['iconDirection']);
                     $options['class'] .= ' btn-primary ';
                     break;
                 case 'view':
                     $title = $this->iconDirection($title, 'list', $options['iconDirection']);
                     $options['class'] .= ' btn-info ';
                     break;
                 default:
                     break;
             }
         }
         if (isset($options['onclick'])) {
             if ($url === '#') {
                 $title = $this->iconDirection($title, 'trash-o', $options['iconDirection']);
                 $options['class'] .= ' btn-danger ';
             }
         }
         $options['escape'] = false;
         $options['class'] .= ' btn btn-xs ';
     }
     if (isset($options['icon']) and $options['icon'] !== false) {
         $title = $this->iconDirection($title, $options['icon'], $options['iconDirection']);
         $options['escape'] = false;
         unset($options['icon']);
     }
     if (empty($options['title'])) {
         if (!empty($url['action'])) {
             $options['title'] = __(\Cake\Utility\Inflector::camelize($url['action']));
         }
     }
     return parent::link($title, $url, $options);
 }