/** * Guess the sections title. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $sections = $builder->getSections(); foreach ($sections as &$section) { // If title is set then skip it. if (isset($section['title'])) { continue; } $module = $this->modules->active(); $title = $module->getNamespace('section.' . $section['slug'] . '.title'); if (!isset($section['title']) && $this->translator->has($title)) { $section['title'] = $title; } $title = $module->getNamespace('addon.section.' . $section['slug']); if (!isset($section['title']) && $this->translator->has($title)) { $section['title'] = $title; } if (!isset($section['title']) && $this->config->get('streams::system.lazy_translations')) { $section['title'] = ucwords($this->string->humanize($section['slug'])); } if (!isset($section['title'])) { $section['title'] = $title; } } $builder->setSections($sections); }
/** * Guess the sections title. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $module = $this->modules->active(); $sections = $builder->getSections(); foreach ($sections as &$section) { // If permission is set then skip it. if (isset($section['permission'])) { return; } $section['permission'] = $module->getNamespace($section['slug'] . '.*'); } $builder->setSections($sections); }
/** * Guess the sections description. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $sections = $builder->getSections(); foreach ($sections as &$section) { // If description is set then skip it. if (isset($section['description'])) { continue; } $module = $this->modules->active(); $description = $module->getNamespace('section.' . $section['slug'] . '.description'); if ($this->translator->has($description)) { $section['description'] = $description; } } $builder->setSections($sections); }
/** * Guess the sections HREF attribute. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $sections = $builder->getSections(); foreach ($sections as $index => &$section) { // If HREF is set then skip it. if (isset($section['attributes']['href'])) { continue; } $module = $this->modules->active(); $href = $this->url->to('admin/' . $module->getSlug()); if ($index !== 0 && $module->getSlug() !== $section['slug']) { $href .= '/' . $section['slug']; } $section['attributes']['href'] = $href; } $builder->setSections($sections); }
/** * Handle the sections. * * @param ControlPanelBuilder $builder */ public function handle(ControlPanelBuilder $builder) { /** * We have to have a module for * the default functionality. */ if (!($module = $this->modules->active())) { return; } /** * Default to the module's sections. */ $builder->setSections($sections = $module->getSections()); /** * If the module has a sections handler * let that HANDLE the sections. */ if (!$sections && class_exists($sections = get_class($module) . 'Sections')) { $this->resolver->resolve($sections . '@handle', compact('builder')); } }
/** * Parse the control panel sections. * * @param ControlPanelBuilder $builder */ public function parse(ControlPanelBuilder $builder) { $builder->setSections($this->parser->parse($builder->getSections())); }
/** * Normalize the section input. * * @param ControlPanelBuilder $builder */ public function normalize(ControlPanelBuilder $builder) { $sections = $builder->getSections(); /* * Loop over each section and make sense of the input * provided for the given module. */ foreach ($sections as $slug => &$section) { /* * If the slug is not valid and the section * is a string then use the section as the slug. */ if (is_numeric($slug) && is_string($section)) { $section = ['slug' => $section]; } /* * If the slug is a string and the title is not * set then use the slug as the slug. */ if (is_string($slug) && !isset($section['slug'])) { $section['slug'] = $slug; } /* * Make sure we have attributes. */ $section['attributes'] = array_get($section, 'attributes', []); /* * Move the HREF into attributes. */ if (isset($section['href'])) { $section['attributes']['href'] = array_pull($section, 'href'); } /* * Move all data-* keys * to attributes. */ foreach ($section as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($section, 'attributes.' . $attribute, array_pull($section, $attribute)); } } /* * Move the data-href into the permalink. * * @deprecated as of v3.2 */ if (!isset($section['permalink']) && isset($section['attributes']['data-href'])) { $section['permalink'] = array_pull($section, 'attributes.data-href'); } /* * Make sure the HREF and permalink are absolute. */ if (isset($section['attributes']['href']) && is_string($section['attributes']['href']) && !starts_with($section['attributes']['href'], 'http')) { $section['attributes']['href'] = url($section['attributes']['href']); } if (isset($section['permalink']) && is_string($section['permalink']) && !starts_with($section['permalink'], 'http')) { $section['permalink'] = url($section['permalink']); } /* * Move child sections into main array. */ if (isset($section['sections'])) { foreach ($section['sections'] as $key => &$child) { $child['parent'] = array_get($section, 'slug'); $child['slug'] = array_get($child, 'slug', $key); $sections[$key] = $child; } } } $builder->setSections(array_values($sections)); }
/** * Evaluate the control panel sections. * * @param ControlPanelBuilder $builder */ public function evaluate(ControlPanelBuilder $builder) { $builder->setSections($this->evaluator->evaluate($builder->getSections(), compact('builder'))); }