/var/www/vhosts/ihelp.ro/httpdocs/vendor/mirko-pagliai/me-tools/src/View/Helper
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/mirko-pagliai/me-tools/src/View/Helper/DropdownHelper.php (4092B)
* $this->Dropdown->start('My dropdown');
* $this->Dropdown->link('First link', '/first');
* $this->Dropdown->link('Second link', '/second');
* echo $this->Dropdown->end();
*
* @property \MeTools\View\Helper\HtmlHelper $Html
*/
class DropdownHelper extends Helper
{
/**
* Helpers
* @var array
*/
public $helpers = ['MeTools.Html'];
/**
* @var string
*/
protected string $_start;
/**
* @var string
*/
protected string $_id;
/**
* @var string[]
*/
protected array $_links = [];
/**
* Creates an HTML link for the dropdown.
*
* See the parent method for all available options.
* @param array|string $title The content to be wrapped by `
` tags. Can be an array if `$url` is `null`. If
* `$url` is `null`, `$title` will be used as both the URL and title
* @param array|string|null $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
* @param array $options Array of options and HTML attributes
* @return void
*/
public function link($title, $url = null, array $options = []): void
{
$options = $this->addClass($options, 'dropdown-item');
$this->_links[] = $this->Html->link($title, $url, $options);
}
/**
* Starts a dropdown.
*
* It will subsequently capture links created with the `link()` method until the `end()` method is called.
*
* `$title` and `$titleOptions` arguments are about the link that allows the opening of the dropdown menu.
* @param string $title Title for the opening link
* @param array $titleOptions HTML attributes and options for the opening link
* @return void
*/
public function start(string $title, array $titleOptions = []): void
{
$this->_id = uniqid('dropdown_');
$titleOptions += [
'aria-expanded' => 'false',
'data-bs-toggle' => 'dropdown',
'id' => $this->_id,
];
$titleOptions = $this->addClass($titleOptions, 'dropdown-toggle');
$this->_start = $this->Html->link($title, '#', $titleOptions);
}
/**
* Closes the dropdown and returns its entire code.
*
* `$ulOptions` argument is about the list of the dropdown menu.
* @param array $ulOptions HTML attributes and options for the wrapper `` element
* @return string
* @throws \ErrorException
*/
public function end(array $ulOptions = []): string
{
Exceptionist::isTrue(isset($this->_start), 'The `start()` method was not called before `end()`');
Exceptionist::isTrue($this->_links, 'The dropdown has no content. Perhaps the `link()` method was never called');
$ulOptions += ['aria-labelledby' => $this->_id];
$ulOptions = $this->addClass($ulOptions, 'dropdown-menu');
$list = $this->Html->ul($this->_links, $ulOptions);
$this->_id = '';
$this->_links = [];
return $this->_start . $list;
}
}