Skip to content
Merged
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
27 changes: 20 additions & 7 deletions src/Block/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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';
}
Expand All @@ -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;
}

/**
Expand Down
20 changes: 6 additions & 14 deletions src/Console/Command/Dev/InspectorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +20,6 @@
*/
class InspectorCommand extends AbstractCommand
{
private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled';
private const ARGUMENT_ACTION = 'action';

/**
Expand Down Expand Up @@ -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(),
};
}

Expand All @@ -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!');
Expand All @@ -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.');
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Model/Config/Inspector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace OpenForgeProject\MageForge\Model\Config;

class Inspector
{
public const XML_PATH_ENABLED = 'dev/mageforge_inspector/enabled';
public const XML_PATH_SHOW_BUTTON_LABELS = 'mageforge/inspector/show_button_labels';
public const XML_PATH_THEME = 'mageforge/inspector/theme';
public const XML_PATH_POSITION = 'mageforge/inspector/position';
public const DEFAULT_THEME = 'dark';
public const DEFAULT_POSITION = 'bottom-left';
}
25 changes: 25 additions & 0 deletions src/Model/Config/Source/ToolbarPosition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace OpenForgeProject\MageForge\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;

class ToolbarPosition implements OptionSourceInterface
{
/**
* Return available toolbar positions as options.
*
* @return array<int, array<string, string>>
*/
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')],
];
}
}
10 changes: 7 additions & 3 deletions src/Model/TemplateEngine/Plugin/InspectorHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -20,8 +21,6 @@
*/
class InspectorHints
{
private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled';

/**
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 10 additions & 4 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@
<resource>OpenForgeProject_MageForge::config_inspector</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General Toolbar Settings</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Toolbar</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>dev/mageforge_inspector/enabled</config_path>
<comment>Enable or disable the MageForge Toolbar. Default: Yes.</comment>
<comment>Enable or disable the MageForge Toolbar. Default: No.</comment>
</field>
<field id="theme" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="theme" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Theme</label>
<source_model>OpenForgeProject\MageForge\Model\Config\Source\InspectorTheme</source_model>
<config_path>mageforge/inspector/theme</config_path>
<comment>Choose between Dark, Light, or Auto (System Preference) theme.</comment>
</field>
<field id="show_button_labels" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="show_button_labels" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Button Labels</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>mageforge/inspector/show_button_labels</config_path>
<comment>Show text labels on the Toolbar and Inspector buttons. Default: Yes.</comment>
</field>
<field id="position" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Toolbar Position</label>
<source_model>OpenForgeProject\MageForge\Model\Config\Source\ToolbarPosition</source_model>
<config_path>mageforge/inspector/position</config_path>
<comment>Position of the MageForge Toolbar on the page. Default: Bottom Left.</comment>
</field>
Comment thread
dermatz marked this conversation as resolved.
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions src/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<inspector>
<theme>dark</theme>
<show_button_labels>1</show_button_labels>
<position>bottom-left</position>
</inspector>
</mageforge>
</default>
Expand Down
18 changes: 18 additions & 0 deletions src/i18n/de_DE.csv
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions src/i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -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"
Comment thread
dermatz marked this conversation as resolved.
"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"
1 change: 1 addition & 0 deletions src/view/frontend/templates/inspector.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ JS;
<div class="mageforge-toolbar-root"
x-data="mageforgeToolbar"
data-theme="<?= $escaper->escapeHtmlAttr($block->getTheme()) ?>"
data-position="<?= $escaper->escapeHtmlAttr($block->getPosition()) ?>"
data-show-labels="<?= (int) $block->getShowButtonLabels() ?>"></div>

<!-- MageForge Inspector Component Wrapper -->
Expand Down
59 changes: 59 additions & 0 deletions src/view/frontend/web/css/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
dermatz marked this conversation as resolved.

@starting-style {
transform: translateY(-8px);
}
}
Comment thread
dermatz marked this conversation as resolved.

/* Menu anchors to right edge for right positions */
.mageforge-toolbar[data-position$="right"] .mageforge-toolbar-menu {
left: auto;
right: 0;
}

/* ============================================================================
Theme Overrides
========================================================================== */
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/view/frontend/web/js/toolbar/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Loading