Skip to content

dropdown() bug fix and improvement - parent menu item can have link and other properties #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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