/**
  * Build the navigation.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getNavigation() as $link) {
         $controlPanel->addNavigationLink($this->factory->make($link));
     }
 }
 /**
  * Build the buttons.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getButtons() as $button) {
         if (($button = $this->factory->make($button)) && $button->isEnabled()) {
             $controlPanel->addButton($button);
         }
     }
 }
 /**
  * Build the sections and push them to the control_panel.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getSections() as $section) {
         if (!$this->authorizer->authorize($section['permission'])) {
             continue;
         }
         $controlPanel->addSection($this->factory->make($section));
     }
 }
 /**
  * Handle the command.
  *
  * @param Request              $request
  * @param Authorizer           $authorizer
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Request $request, Authorizer $authorizer, BreadcrumbCollection $breadcrumbs)
 {
     $controlPanel = $this->builder->getControlPanel();
     $sections = $controlPanel->getSections();
     /*
      * If we already have an active section
      * then we don't need to do this.
      */
     if ($active = $sections->active()) {
         return;
     }
     /* @var SectionInterface $section */
     foreach ($sections as $section) {
         if (($matcher = $section->getMatcher()) && str_is($matcher, $request->path())) {
             $active = $section;
         }
         /*
          * Get the HREF for both the active
          * and loop iteration section.
          */
         $href = $section->getPermalink() ?: array_get($section->getAttributes(), 'href');
         $activeHref = '';
         if ($active && $active instanceof SectionInterface) {
             $activeHref = $active->getPermalink() ?: array_get($active->getAttributes(), 'href');
         }
         /*
          * If the request URL does not even
          * contain the HREF then skip it.
          */
         if (!str_contains($request->url(), $href)) {
             continue;
         }
         /*
          * Compare the length of the active HREF
          * and loop iteration HREF. The longer the
          * HREF the more detailed and exact it is and
          * the more likely it is the active HREF and
          * therefore the active section.
          */
         $hrefLength = strlen($href);
         $activeHrefLength = strlen($activeHref);
         if ($hrefLength > $activeHrefLength) {
             $active = $section;
         }
     }
     /**
      * If we have an active section determined
      * then mark it as such.
      *
      * @var SectionInterface $active
      * @var SectionInterface $section
      */
     if ($active) {
         if ($active->getParent()) {
             $active->setActive(true);
             $section = $sections->get($active->getParent(), $sections->first());
             $section->setHighlighted(true);
             $breadcrumbs->put($section->getBreadcrumb() ?: $section->getTitle(), $section->getHref());
         } else {
             $active->setActive(true)->setHighlighted(true);
         }
     } elseif ($active = $sections->first()) {
         $active->setActive(true)->setHighlighted(true);
     }
     // No active section!
     if (!$active) {
         return;
     }
     // Authorize the active section.
     if (!$authorizer->authorize($active->getPermission())) {
         abort(403);
     }
     // Add the bread crumb.
     if (($breadcrumb = $active->getBreadcrumb()) !== false) {
         $breadcrumbs->put($breadcrumb ?: $active->getTitle(), $active->getHref());
     }
 }