Exemple #1
0
 /**
  * Initializes the object and returns an instance holding the HTML code for
  * a link tag.
  *
  * @param mixed $name link target.
  * @param array $options link options.
  * @param callable $block closure that generates the content to be surrounding to.
  */
 public function __construct($name, $options = [], callable $block = null)
 {
     $html = '';
     $num_args = $this->get_function_num_args(func_get_args());
     $block = is_callable(func_get_arg($num_args - 1)) ? func_get_arg($num_args - 1) : null;
     if (Base::get_dropdown_link()) {
         $html = $this->build_dropdown_link($num_args, $name, $options, $block);
     } elseif (Base::get_nav_link()) {
         $html = $this->build_nav_link($num_args, $name, $options, $block);
     } else {
         $html = $this->build_standard_link($num_args, $name, $options, $block);
     }
     $this->set_html_object($html->get_html_object());
 }
Exemple #2
0
 /**
  * Returns the Divider object built.
  *
  * @return mixed a ContentTag instance or null.
  */
 private function build_divider()
 {
     return Base::get_dropdown_link() ? new ContentTag('li', '', ['class' => 'divider']) : null;
 }
Exemple #3
0
 /**
  * Builds a standard Dropdown that is rendered within a Nav, so the Button
  * is not going to be generated instead a LinkTo is generated to trigger the
  * dropdown menu.
  *
  * @param array $options Dropdown's options.
  * @param mixed $yield Dropdown's content.
  * @return ContentTag a ContentTag instance that represents a Dropdown within a Nav.
  */
 private function build_standard_dropdown_into_nav($options, $yield)
 {
     return new ContentTag('li', ['class' => 'dropdown'], function () use($options, $yield) {
         $nav_link_status = Base::get_nav_link();
         $dropdown_link_status = Base::get_dropdown_link();
         Base::set_dropdown_link(false);
         Base::set_nav_link(false);
         $link = new LinkTo(['href' => '#', 'class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'], function () use($options) {
             return [$options['caption'], new ContentTag('span', '', ['class' => 'caret'])];
         });
         Base::set_nav_link($nav_link_status);
         Base::set_dropdown_link($dropdown_link_status);
         return [$link, new ContentTag('ul', $yield, ['class' => $options['list_class'], 'role' => 'menu', 'aria-labelledby' => $options['id']])];
     });
 }