Skip to content
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

Menu::make method and public getItems for faster prototyping menus and micro menus rendering. #109

Open
wants to merge 10 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
10 changes: 10 additions & 0 deletions src/Models/MenuGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ protected function add(array $properties = []): MenuItem
return $item;
}

/**
* Returns an array of menu items to be used without render.
*
* @return \Illuminate\Support\Collection
*/
public function getItems(): Collection
{
return $this->items;
}

/**
* Create new menu with dropdown.
*
Expand Down
38 changes: 30 additions & 8 deletions src/Models/MenuManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ public function register($name, Closure $callback): void
}

/**
* Render the menu tag by given name.
* Initializes the menu tag by given name without rendering.
*
* @param string $name
* @param string $presenter
* @param array $bindings
* @param bool $specialSidebar
* @param string $name
* @param string|null $presenter
* @param array $bindings
* @param bool $specialSidebar
*
* @return string|null
* @return MenuGenerator|null
*/
public function render(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?string
public function make(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?MenuGenerator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unused parameters such as '$presenter'.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unused parameters such as '$specialSidebar'.

{
if ($this->has($name)) {
$instance = $this->instance($name);
Expand All @@ -137,7 +137,29 @@ public function render(string $name, string $presenter = null, array $bindings =
$params ? $callback($instance, ...$params) : $callback($instance);
});

return $instance->setBindings($bindings)->render($presenter, $specialSidebar);
return $instance->setBindings($bindings);
}

return null;
}

/**
* Render the menu tag by given name.
*
* @param string $name
* @param string|null $presenter
* @param array $bindings
* @param bool $specialSidebar
*
* @return string|null
*/
public function render(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?string
{
if ($this->has($name)) {
$instance = $this->make($name, $presenter, $bindings, $specialSidebar);
if ($instance) {
return $instance->render($presenter, $specialSidebar);
}
}

return null;
Expand Down