Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,46 @@ public function add(array $attributes = array())
/**
* Create new menu with dropdown.
*
* @param $title
* @param callable $callback
* @param array $attributes
* @param $title_or_properties can give all properties in one argument
* or give title as string title separately
*
* @param callable $callback callback to add submenu items
*
* @param int $order
*
* @param array $attributes
*
* @return $this
*/
public function dropdown($title, \Closure $callback, $order = null, array $attributes = array())

public function dropdown($title_or_properties, \Closure $callback, $order = null, array $attributes = array())
{
$properties = compact('title', 'order', 'attributes');
if (is_array($title_or_properties)) {

if (func_num_args() == 3) {
$arguments = func_get_args();
if (($title_or_properties['attributes']??null) === null)
{
$title_or_properties['attributes'] = [];
}

$properties = $title_or_properties;
}
else
{
$title = $title_or_properties;

$title = Arr::get($arguments, 0);
$attributes = Arr::get($arguments, 2);
// backwards compatible with previous code that assumes that
// if three args are passed in, third must be attributes

if (func_num_args() === 3 && is_array($order)) {
$attributes = $order;
$properties = compact('title', 'attributes');
}
else
{
$properties = compact('title', 'order', 'attributes');
}

$properties = compact('title', 'attributes');
$properties = compact('title', 'order', 'attributes');
}

$item = MenuItem::make($properties);
Expand Down
39 changes: 30 additions & 9 deletions src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,43 @@ public function child($attributes)
/**
* Register new child menu with dropdown.
*
* @param $title
* @param callable $callback
* @param $title_or_properties can give all properties in one argument
* or give title as string title separately
*
* @param callable $callback callback to add submenu items
*
* @param int $order
*
* @param array $attributes
*
* @return $this
*/
public function dropdown($title, \Closure $callback, $order = 0, array $attributes = array())
public function dropdown($title_or_properties, \Closure $callback, $order = 0, array $attributes = array())
{
$properties = compact('title', 'order', 'attributes');
if (is_array($title_or_properties)) {

if (func_num_args() === 3) {
$arguments = func_get_args();
if (($title_or_properties['attributes']??null) === null)
{
$title_or_properties['attributes'] = [];
}

$properties = $title_or_properties;
}
else
{
$title = $title_or_properties;

$title = Arr::get($arguments, 0);
$attributes = Arr::get($arguments, 2);
// backwards compatible with previous code that assumes that
// if three args are passed in, third must be attributes

$properties = compact('title', 'attributes');
if (func_num_args() === 3 && is_array($order)) {
$attributes = $order;
$properties = compact('title', 'attributes');
}
else
{
$properties = compact('title', 'order', 'attributes');
}
}

$child = static::make($properties);
Expand Down