diff --git a/src/Block/Inspector.php b/src/Block/Inspector.php index 6c3b3c05..d833aa5a 100644 --- a/src/Block/Inspector.php +++ b/src/Block/Inspector.php @@ -9,6 +9,8 @@ use Magento\Framework\App\State; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; +use Magento\Store\Model\ScopeInterface; +use OpenForgeProject\MageForge\Model\Config\Inspector as InspectorConfig; /** * Block for MageForge Inspector @@ -17,9 +19,6 @@ */ class Inspector extends Template { - private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled'; - private const XML_PATH_SHOW_BUTTON_LABELS = 'mageforge/inspector/show_button_labels'; - /** * @param Context $context * @param State $state @@ -51,7 +50,7 @@ public function shouldRender(): bool } // Check if inspector is enabled in configuration - if (!$this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED)) { + if (!$this->scopeConfig->isSetFlag(InspectorConfig::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE)) { return false; } @@ -110,7 +109,10 @@ public function getToolbarJsUrl(): string */ public function getShowButtonLabels(): bool { - $value = $this->scopeConfig->getValue(self::XML_PATH_SHOW_BUTTON_LABELS); + $value = $this->scopeConfig->getValue( + InspectorConfig::XML_PATH_SHOW_BUTTON_LABELS, + ScopeInterface::SCOPE_STORE + ); // Default to true when not explicitly set to '0' return !is_string($value) || $value !== '0'; } @@ -122,8 +124,19 @@ public function getShowButtonLabels(): bool */ public function getTheme(): string { - $value = $this->scopeConfig->getValue('mageforge/inspector/theme'); - return is_string($value) && $value !== '' ? $value : 'dark'; + $value = $this->scopeConfig->getValue(InspectorConfig::XML_PATH_THEME, ScopeInterface::SCOPE_STORE); + return is_string($value) && $value !== '' ? $value : InspectorConfig::DEFAULT_THEME; + } + + /** + * Get configured toolbar position + * + * @return string + */ + public function getPosition(): string + { + $value = $this->scopeConfig->getValue(InspectorConfig::XML_PATH_POSITION, ScopeInterface::SCOPE_STORE); + return is_string($value) && $value !== '' ? $value : InspectorConfig::DEFAULT_POSITION; } /** diff --git a/src/Console/Command/Dev/InspectorCommand.php b/src/Console/Command/Dev/InspectorCommand.php index 5b1e4f30..d531fae3 100644 --- a/src/Console/Command/Dev/InspectorCommand.php +++ b/src/Console/Command/Dev/InspectorCommand.php @@ -10,6 +10,7 @@ use Magento\Framework\App\State; use Magento\Framework\Console\Cli; use OpenForgeProject\MageForge\Console\Command\AbstractCommand; +use OpenForgeProject\MageForge\Model\Config\Inspector as InspectorConfig; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +20,6 @@ */ class InspectorCommand extends AbstractCommand { - private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled'; private const ARGUMENT_ACTION = 'action'; /** @@ -106,7 +106,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output return match ($action) { 'enable' => $this->enableInspector(), 'disable' => $this->disableInspector(), - 'status' => $this->showStatus(), + default => $this->showStatus(), }; } @@ -117,7 +117,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output */ private function enableInspector(): int { - $this->configWriter->save(self::XML_PATH_INSPECTOR_ENABLED, '1'); + $this->configWriter->save(InspectorConfig::XML_PATH_ENABLED, '1'); $this->cleanCache(); $this->io->success('MageForge Inspector has been enabled!'); @@ -142,7 +142,7 @@ private function enableInspector(): int */ private function disableInspector(): int { - $this->configWriter->save(self::XML_PATH_INSPECTOR_ENABLED, '0'); + $this->configWriter->save(InspectorConfig::XML_PATH_ENABLED, '0'); $this->cleanCache(); $this->io->success('MageForge Inspector has been disabled.'); @@ -193,11 +193,7 @@ private function showStatus(): int */ private function isDeveloperMode(): bool { - try { - return $this->state->getMode() === State::MODE_DEVELOPER; - } catch (\Exception $e) { - return false; - } + return $this->state->getMode() === State::MODE_DEVELOPER; } /** @@ -207,11 +203,7 @@ private function isDeveloperMode(): bool */ private function isInspectorEnabled(): bool { - try { - return $this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED); - } catch (\Exception $e) { - return false; - } + return $this->scopeConfig->isSetFlag(InspectorConfig::XML_PATH_ENABLED); } /** diff --git a/src/Model/Config/Inspector.php b/src/Model/Config/Inspector.php new file mode 100644 index 00000000..d1aab7d1 --- /dev/null +++ b/src/Model/Config/Inspector.php @@ -0,0 +1,15 @@ +> + */ + public function toOptionArray(): array + { + return [ + ['value' => 'bottom-left', 'label' => (string) __('Bottom Left')], + ['value' => 'bottom-right', 'label' => (string) __('Bottom Right')], + ['value' => 'top-left', 'label' => (string) __('Top Left')], + ['value' => 'top-right', 'label' => (string) __('Top Right')], + ]; + } +} diff --git a/src/Model/TemplateEngine/Plugin/InspectorHints.php b/src/Model/TemplateEngine/Plugin/InspectorHints.php index cbe07ee9..b2c6b6af 100644 --- a/src/Model/TemplateEngine/Plugin/InspectorHints.php +++ b/src/Model/TemplateEngine/Plugin/InspectorHints.php @@ -11,6 +11,7 @@ use Magento\Framework\View\TemplateEngineInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; +use OpenForgeProject\MageForge\Model\Config\Inspector as InspectorConfig; use OpenForgeProject\MageForge\Model\TemplateEngine\Decorator\InspectorHintsFactory; /** @@ -20,8 +21,6 @@ */ class InspectorHints { - private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled'; - /** * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager @@ -57,7 +56,12 @@ public function afterCreate( // Check if inspector is enabled in configuration $storeCode = $this->storeManager->getStore()->getCode(); - if (!$this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED, ScopeInterface::SCOPE_STORE, $storeCode)) { + $isEnabled = $this->scopeConfig->isSetFlag( + InspectorConfig::XML_PATH_ENABLED, + ScopeInterface::SCOPE_STORE, + $storeCode + ); + if (!$isEnabled) { return $invocationResult; } diff --git a/src/etc/adminhtml/system.xml b/src/etc/adminhtml/system.xml index 4de1c0d1..697ba9dd 100644 --- a/src/etc/adminhtml/system.xml +++ b/src/etc/adminhtml/system.xml @@ -10,24 +10,30 @@ OpenForgeProject_MageForge::config_inspector - + Magento\Config\Model\Config\Source\Yesno dev/mageforge_inspector/enabled - Enable or disable the MageForge Toolbar. Default: Yes. + Enable or disable the MageForge Toolbar. Default: No. - + OpenForgeProject\MageForge\Model\Config\Source\InspectorTheme mageforge/inspector/theme Choose between Dark, Light, or Auto (System Preference) theme. - + Magento\Config\Model\Config\Source\Yesno mageforge/inspector/show_button_labels Show text labels on the Toolbar and Inspector buttons. Default: Yes. + + + OpenForgeProject\MageForge\Model\Config\Source\ToolbarPosition + mageforge/inspector/position + Position of the MageForge Toolbar on the page. Default: Bottom Left. + diff --git a/src/etc/config.xml b/src/etc/config.xml index 037f5b60..01c0a907 100644 --- a/src/etc/config.xml +++ b/src/etc/config.xml @@ -11,6 +11,7 @@ dark 1 + bottom-left diff --git a/src/i18n/de_DE.csv b/src/i18n/de_DE.csv new file mode 100644 index 00000000..3ab18754 --- /dev/null +++ b/src/i18n/de_DE.csv @@ -0,0 +1,18 @@ +"MageForge","MageForge" +"Toolbar","Toolbar" +"General Toolbar Settings","Allgemeine Toolbar-Einstellungen" +"Show Toolbar","Toolbar anzeigen" +"Enable or disable the MageForge Toolbar. Default: No.","MageForge Toolbar aktivieren oder deaktivieren. Standard: Nein." +"Theme","Design" +"Choose between Dark, Light, or Auto (System Preference) theme.","Wähle zwischen Dunkel, Hell oder Auto (Systemeinstellung)." +"Show Button Labels","Schaltflächenbeschriftungen anzeigen" +"Show text labels on the Toolbar and Inspector buttons. Default: Yes.","Textbeschriftungen auf Toolbar- und Inspector-Schaltflächen anzeigen. Standard: Ja." +"Toolbar Position","Toolbar-Position" +"Position of the MageForge Toolbar on the page. Default: Bottom Left.","Position der MageForge Toolbar auf der Seite. Standard: Unten links." +"Dark","Dunkel" +"Light","Hell" +"Auto (System Preference)","Auto (Systemeinstellung)" +"Bottom Left","Unten links" +"Bottom Right","Unten rechts" +"Top Left","Oben links" +"Top Right","Oben rechts" diff --git a/src/i18n/en_US.csv b/src/i18n/en_US.csv new file mode 100644 index 00000000..959513c4 --- /dev/null +++ b/src/i18n/en_US.csv @@ -0,0 +1,18 @@ +"MageForge","MageForge" +"Toolbar","Toolbar" +"General Toolbar Settings","General Toolbar Settings" +"Show Toolbar","Show Toolbar" +"Enable or disable the MageForge Toolbar. Default: No.","Enable or disable the MageForge Toolbar. Default: No." +"Theme","Theme" +"Choose between Dark, Light, or Auto (System Preference) theme.","Choose between Dark, Light, or Auto (System Preference) theme." +"Show Button Labels","Show Button Labels" +"Show text labels on the Toolbar and Inspector buttons. Default: Yes.","Show text labels on the Toolbar and Inspector buttons. Default: Yes." +"Toolbar Position","Toolbar Position" +"Position of the MageForge Toolbar on the page. Default: Bottom Left.","Position of the MageForge Toolbar on the page. Default: Bottom Left." +"Dark","Dark" +"Light","Light" +"Auto (System Preference)","Auto (System Preference)" +"Bottom Left","Bottom Left" +"Bottom Right","Bottom Right" +"Top Left","Top Left" +"Top Right","Top Right" diff --git a/src/view/frontend/templates/inspector.phtml b/src/view/frontend/templates/inspector.phtml index 1301d9a4..07c93b8e 100644 --- a/src/view/frontend/templates/inspector.phtml +++ b/src/view/frontend/templates/inspector.phtml @@ -68,6 +68,7 @@ JS;
diff --git a/src/view/frontend/web/css/toolbar.css b/src/view/frontend/web/css/toolbar.css index 35959ff9..c15246e0 100644 --- a/src/view/frontend/web/css/toolbar.css +++ b/src/view/frontend/web/css/toolbar.css @@ -568,6 +568,50 @@ color: var(--mageforge-color-blue); } +/* ============================================================================ + Position Variants + ========================================================================== */ + +.mageforge-toolbar[data-position="bottom-right"] { + bottom: 16px; + left: auto; + right: 16px; +} + +.mageforge-toolbar[data-position="top-left"] { + bottom: auto; + top: 16px; + left: 16px; +} + +.mageforge-toolbar[data-position="top-right"] { + bottom: auto; + top: 16px; + left: auto; + right: 16px; +} + +/* Menu opens downward for top positions */ +.mageforge-toolbar[data-position^="top"] .mageforge-toolbar-menu { + bottom: auto; + top: calc(100% + 8px); + transform: translateY(-8px); +} + +.mageforge-toolbar[data-position^="top"] .mageforge-toolbar-menu.mageforge-menu-open { + transform: translateY(0); + + @starting-style { + transform: translateY(-8px); + } +} + +/* Menu anchors to right edge for right positions */ +.mageforge-toolbar[data-position$="right"] .mageforge-toolbar-menu { + left: auto; + right: 0; +} + /* ============================================================================ Theme Overrides ========================================================================== */ @@ -625,6 +669,21 @@ bottom: 10px; left: 10px; } + .mageforge-toolbar[data-position="bottom-right"] { + left: auto; + right: 10px; + } + .mageforge-toolbar[data-position="top-left"] { + bottom: auto; + left: 10px; + top: 10px; + } + .mageforge-toolbar[data-position="top-right"] { + bottom: auto; + left: auto; + right: 10px; + top: 10px; + } .mageforge-toolbar-menu { min-width: 300px; max-height: calc(100vh - 60px); diff --git a/src/view/frontend/web/js/toolbar/ui.js b/src/view/frontend/web/js/toolbar/ui.js index 9bb45bc7..d11887c4 100644 --- a/src/view/frontend/web/js/toolbar/ui.js +++ b/src/view/frontend/web/js/toolbar/ui.js @@ -11,6 +11,10 @@ export const uiMethods = { this.container.setAttribute('data-theme', this.$el.getAttribute('data-theme')); } + if (this.$el && this.$el.hasAttribute('data-position')) { + this.container.setAttribute('data-position', this.$el.getAttribute('data-position')); + } + if (this.$el && this.$el.getAttribute('data-show-labels') === '0') { this.container.classList.add('mageforge-toolbar--no-labels'); }