HtmlHelper encloses all methods needed while working with HTML pages.
Наследование: extends Cake\View\Helper, use trait Cake\View\Helper\StringTemplateTrait
Пример #1
0
 /**
  * Generate a link if the target url is authorized for the logged in user
  *
  * @param string $title link's title.
  * @param string|array|null $url url that the user is making request.
  * @param array $options Array with option data.
  * @return string
  */
 public function link($title, $url = null, array $options = [])
 {
     if ($this->isAuthorized($url)) {
         $linkOptions = $options;
         unset($linkOptions['before'], $linkOptions['after']);
         return Hash::get($options, 'before') . parent::link($title, $url, $linkOptions) . Hash::get($options, 'after');
     }
     return false;
 }
Пример #2
0
 /**
  * Keep query string params for pagination/filter for this link,
  * e.g. after edit action.
  *
  * ### Options
  *
  * - `escape` Set to false to disable escaping of title and attributes.
  * - `escapeTitle` Set to false to disable escaping of title. Takes precedence
  *   over value of `escape`)
  * - `confirm` JavaScript confirmation message.
  *
  * @param string $title The content to be wrapped by <a> tags.
  * @param string|array|null $url URL or array of URL parameters, or
  *   external URL (starts with http://)
  * @param array $options Array of options and HTML attributes.
  * @return string An `<a />` element.
  * @return string Link
  */
 public function completeLink($title, $url = null, array $options = [])
 {
     if (is_array($url)) {
         // Add query strings
         if (!isset($url['?'])) {
             $url['?'] = [];
         }
         $url['?'] += $this->request->query;
     }
     return parent::link($title, $url, $options);
 }
Пример #3
0
 /**
  * @param string $label
  * @param \Cake\View\Helper\HtmlHelper $htmlHelper
  *
  * In order to make a trail of breadcrumbs we must:
  * 1. Emit any number of trail elements, in a view, using $htmlHelper->addCrumb().
  * 2. Emit the beginning of the trail in a layout, using $thmlHelper->getCrumbs().
  * 3. addCrumbs and getCrumbs provide the necessary information so that when the time
  *    comes to actually render the trail, the Cake software can do this.
  *
  * The problem with this plan is that some views can be reached via more than one path.
  * How can the view know which path led to it?  The basic answer is to save a path
  * in the session, with each step towards a particular view, and use that path to
  * generate the trail using a suitable number of invocations of addCrumb.  Each view's
  * url is added to the session trail, as well as a suitable label to be used in the trail.
  */
 public function makeTrail($label, $htmlHelper)
 {
     // 1. Read the present trail or init if none.
     $sessionVar = 'breadcrumbs';
     //$this->request->session()->delete($sessionVar);
     $sessionCrumbs = $this->request->session()->read($sessionVar);
     if (is_null($sessionCrumbs)) {
         $sessionCrumbs = [];
     }
     // 2. Get the present url and parse into a parameter array
     $requestUrl = $this->request->url;
     $requestUrlParams = \Cake\Routing\Router::parse($requestUrl);
     // 3. Build a new trail array by looking for the existing
     // url in the existing trail array.  This effectively removes
     // any elements of the existing trail array, that are after the
     // present url.
     $newArray = [];
     foreach ($sessionCrumbs as $key => $crumb) {
         if ($key == $requestUrl) {
             break;
         } else {
             $newArray[$key] = $crumb;
         }
     }
     // 3.1 Whether this is new or the last item matched, add it here
     $newArray[$requestUrl] = ['label' => $label, 'params' => $requestUrlParams];
     // 4. Save the trail to the session
     $this->request->session()->write($sessionVar, $newArray);
     // 5. Now add the crumbs the ordinary way
     foreach ($newArray as $key => $crumb) {
         if ($key == $requestUrl) {
             break;
         }
         // no crumb for this url
         $htmlHelper->addCrumb($crumb['label'], $crumb['params']);
     }
 }
Пример #4
0
 public function __construct(View $View, array $config = array())
 {
     $this->_defaultConfig['jquery_variable'] = '$';
     $this->_defaultConfig['jquery_js'] = 'Alaxos.jquery/jquery-1.11.1.min';
     $this->_defaultConfig['alaxos_js'] = 'Alaxos.alaxos/alaxos';
     $this->_defaultConfig['alaxos_encode'] = 'Alaxos.alaxos/encode';
     $this->_defaultConfig['bootstrap_js'] = 'Alaxos.bootstrap/bootstrap.min';
     $this->_defaultConfig['bootstrap_datepicker_js'] = 'Alaxos.bootstrap/datepicker/bootstrap-datepicker.min';
     $this->_defaultConfig['textarea_autosize_js'] = 'Alaxos.jquery/jquery.autosize.min';
     $this->_defaultConfig['alaxos_css'] = 'Alaxos.alaxos';
     $this->_defaultConfig['bootstrap_min_css'] = 'Alaxos.bootstrap/bootstrap.min';
     $this->_defaultConfig['bootstrap_theme_css'] = 'Alaxos.bootstrap/bootstrap-theme.min';
     $this->_defaultConfig['bootstrap_datepicker_css'] = 'Alaxos.bootstrap/bootstrap-datepicker3.standalone';
     parent::__construct($View, $config);
 }
 /**
  * Overloaded Html->image() method
  * change image src for using AdaptiveImages plugin
  *
  * @param string $path Path to the image file, relative to the app/webroot/img/ directory.
  * @param array $options Array of HTML attributes. See above for special options.
  * @return string completed img tag with chenged src
  */
 public function image($path, array $options = [])
 {
     // if ($path[0] == '/') { //absolute
     //     $path = substr($path, 1);
     //     $file = new File(WWW_ROOT . $path);
     // } else { //relative
     //     $file = new File(WWW_ROOT . 'img' . DS . $path);
     // }
     // return dirname($file->path);
     if ($path[0] != '/') {
         $path = '/img/' . $path;
     }
     $path = '/adaptive_images' . '?path=' . $path;
     if (isset($options['semanticType'])) {
         $path .= '&semanticType=' . $options['semanticType'];
     }
     return parent::image($path, $options);
 }
 /**
  *
  * Get crumb lists in a HTML list, with bootstrap like style.
  *
  * @param $options Options for list
  * @param $startText Text to insert before list
  *
  * Unusable options:
  * 	- Separator
  **/
 public function getCrumbList(array $options = array(), $startText = false)
 {
     $options['separator'] = '';
     $options = $this->addClass($options, 'breadcrumb');
     return parent::getCrumbList($options, $startText);
 }
Пример #7
0
 /**
  * Returns breadcrumbs as a (x)html list
  *
  * This method uses HtmlHelper::tag() to generate list and its elements. Works
  * similar to HtmlHelper::getCrumbs(), so it uses options which every
  * crumb was added with.
  *
  * ### Options
  *
  * - `separator` Separator content to insert in between breadcrumbs, defaults to ''
  * - `firstClass` Class for wrapper tag on the first breadcrumb, defaults to 'first'
  * - `lastClass` Class for wrapper tag on current active page, defaults to 'last'
  *
  * @param array $options Array of HTML attributes to apply to the generated list elements.
  * @param string|array|bool $startText This will be the first crumb, if false it defaults to first crumb in
  *   array. Can also be an array, see `HtmlHelper::getCrumbs` for details.
  * @return string|null Breadcrumbs HTML list.
  * @link http://book.cakephp.org/3.0/en/views/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
  */
 public function getCrumbList(array $options = [], $startText = false)
 {
     $options += ['separator' => ''];
     return parent::getCrumbList($this->injectClasses('breadcrumb', $options), $startText);
 }
Пример #8
0
 /**
  * Creates a link to an external resource and handles basic meta tags.
  *
  * @param array|string $type
  * @param null $content
  * @param array $options
  * @return string
  */
 public function meta($type, $content = null, array $options = [])
 {
     return parent::meta($type, $content, $options) . $this->Document->eol;
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function para($class, $text, array $options = array())
 {
     if ('text' == $this->getType()) {
         return $this->_eol() . $this->_eol() . $text . $this->_eol() . $this->_eol();
     }
     return parent::para($class, $text, $this->_mergeAttributes($options, $this->config('attributes.para')));
 }
Пример #10
0
 /**
  * Create an html link.
  *
  * @param string $title
  * @param null $url
  * @param array $options
  * @return string
  */
 public function link($title, $url = null, array $options = [])
 {
     $options = $this->addClass($options, $this->getClass(__FUNCTION__));
     $options = Hash::merge(['escapeTitle' => false, 'title' => false, 'isClear' => false], $options);
     $isClear = $options['isClear'];
     unset($options['isClear']);
     if ($options['title'] == false) {
         unset($options['title']);
     }
     //  Set buttons
     if (!empty($options['button'])) {
         $button = [$this->_btnPrefix];
         if ($options['button'] !== true) {
             foreach ((array) $options['button'] as $btn) {
                 if ($btn !== true) {
                     $button[] = $this->_btnPrefix . '-' . $btn;
                 }
             }
         }
         unset($options['button']);
         $options = $this->addClass($options, implode(' ', $button));
     }
     //  Set title in html tag
     if ($options['escapeTitle'] == false && !empty($title) && !$isClear) {
         $title = $this->tag('span', $title, ['class' => $this->getClass(__FUNCTION__) . '-title']);
     }
     //  Set link icon
     if (isset($options['icon'])) {
         $_iconOptions = [];
         if (isset($options['iconClass'])) {
             $_iconOptions = $this->addClass($_iconOptions, $options['iconClass']);
             unset($options['iconClass']);
         }
         if (isset($options['iconInline'])) {
             $iconClass = $this->getClass('icon') . ' ' . $this->_iconPrefix . $options['icon'];
             $options = $this->addClass($options, $iconClass);
             unset($options['iconInline']);
         } else {
             $options['escape'] = false;
             $title = $this->icon($options['icon'], $_iconOptions) . PHP_EOL . $title;
         }
         unset($options['icon']);
     }
     //  Set uikit tooltip
     if (isset($options['tooltip'])) {
         $_toolTipPos = 'top';
         if (is_string($options['tooltip']) && !isset($options['title'])) {
             $options['title'] = $options['tooltip'];
         }
         if (isset($options['tooltipPosition'])) {
             $_toolTipPos = $options['tooltipPosition'];
             unset($options['tooltipPosition']);
         }
         $toolTipOptions = ['data-uk-tooltip' => "pos:'{$_toolTipPos}'", 'title' => !isset($options['title']) ? (string) $options['tooltip'] : $options['title']];
         unset($options['tooltip']);
         $options = Hash::merge($toolTipOptions, $options);
     }
     return parent::link($title, $url, $options);
 }
Пример #11
0
 /**
  * Returns a formatted block tag
  * @param string $name Tag name
  * @param string $text Tag content. If `null`, only a start tag will be
  *  printed
  * @param array $options Array of options and HTML attributes
  * @return string
  */
 public function tag($name, $text = null, array $options = [])
 {
     list($text, $options) = $this->addIconToText($text, $options);
     $options = $this->addTooltip($options);
     return parent::tag($name, is_null($text) ? '' : $text, $options);
 }