diff --git a/app/code/Magento/CustomAdminLogo/Model/AdminLogo.php b/app/code/Magento/CustomAdminLogo/Model/AdminLogo.php new file mode 100644 index 00000000000..2192979569b --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/Model/AdminLogo.php @@ -0,0 +1,64 @@ +moduleConfig->getAdminLoginLogoFileName()) { + return null; + } + + return $this->fileDriver->getAbsolutePath( + $this->urlBuilder->getBaseUrl() . DirectoryList::MEDIA . DIRECTORY_SEPARATOR, + AdminLoginLogo::UPLOAD_DIR . DIRECTORY_SEPARATOR . $logoFileName + ); + } + + /** + * Get custom admin menu logo src + * + * @return string|null + */ + public function getCustomAdminMenuLogoSrc(): ?string + { + if (!$logoFileName = $this->moduleConfig->getAdminMenuLogoFileName()) { + return null; + } + + return $this->fileDriver->getAbsolutePath( + $this->urlBuilder->getBaseUrl() . DirectoryList::MEDIA . DIRECTORY_SEPARATOR, + AdminMenuLogo::UPLOAD_DIR . DIRECTORY_SEPARATOR . $logoFileName + ); + } +} diff --git a/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminLoginLogo.php b/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminLoginLogo.php new file mode 100644 index 00000000000..9f89ac083bf --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminLoginLogo.php @@ -0,0 +1,31 @@ +_mediaDirectory->getAbsolutePath(self::UPLOAD_DIR); + } + + /** + * @inheritDoc + */ + protected function _addWhetherScopeInfo(): bool + { + return false; + } +} diff --git a/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminMenuLogo.php b/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminMenuLogo.php new file mode 100644 index 00000000000..4af9b688cfb --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/Model/Config/Backend/AdminMenuLogo.php @@ -0,0 +1,31 @@ +_mediaDirectory->getAbsolutePath(self::UPLOAD_DIR); + } + + /** + * @inheritDoc + */ + protected function _addWhetherScopeInfo(): bool + { + return false; + } +} diff --git a/app/code/Magento/CustomAdminLogo/README.md b/app/code/Magento/CustomAdminLogo/README.md new file mode 100644 index 00000000000..42524dfb7c9 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/README.md @@ -0,0 +1,80 @@ +
+ + + +
+ +

element119 | Custom Admin Logo

+ +## 📝 Features +✔️ Upload a custom logo for the admin login screen + +✔️ Upload a custom logo for the admin menu + +✔️ Maintains brand presence on the admin pages + +✔️ Easily revert to default logos + +✔️ Built in accordance with Magento best practises + +✔️ Dedicated module configuration group + +✔️ Seamless integration with Magento + +✔️ Built with developers and extensibility in mind to make customisations as easy as possible + +✔️ Installable via Composer + +
+ +## 🔌 Installation +Run the following command to *install* this module: +```bash +composer require element119/module-custom-admin-logo +php bin/magento setup:upgrade +``` + +
+ +## ⏫ Updating +Run the following command to *update* this module: +```bash +composer update element119/module-custom-admin-logo +php bin/magento setup:upgrade +``` + +
+ +## ❌ Uninstallation +Run the following command to *uninstall* this module: +```bash +composer remove element119/module-custom-admin-logo +php bin/magento setup:upgrade +``` + +
+ +## 📚 User Guide +Module configuration can be found by logging into the admin and navigating to `Stores -> Settings -> Configuration -> +Advanced -> Admin -> Admin Logos`. + +![admin-config](https://user-images.githubusercontent.com/40261741/212520570-fec863b2-8124-4e8b-af07-af1bc83801a5.png) + +### Login Page +The login page upload allows administrators to upload an image that will be displayed on the admin login page. + +Permitted files types include jpg, jpeg, gif, png. + +### Menu +The menu upload allows administrators to upload an image that will be displayed at the top of the admin menu. + +Permitted files types include jpg, jpeg, gif, png. + +
+ +## 📸 Screenshots & GIFs +### Custom Login Logo +![admin-login](https://user-images.githubusercontent.com/40261741/212521164-ae937f0b-bbd3-491a-9185-8e6fa4264ce8.png) + +### Custom Menu Logo +![admin-menu](https://user-images.githubusercontent.com/40261741/212521165-3a13ad0f-8de0-4fb3-a6c9-69663dbd6c23.png) diff --git a/app/code/Magento/CustomAdminLogo/Scope/Config.php b/app/code/Magento/CustomAdminLogo/Scope/Config.php new file mode 100644 index 00000000000..4ebd37ca431 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/Scope/Config.php @@ -0,0 +1,45 @@ +scopeConfig->getValue(self::XML_PATH_LOGIN_LOGO, ScopeInterface::SCOPE_STORE); + } + + /** + * Get admin menu logo file from configuration + * + * @return string|null + */ + public function getAdminMenuLogoFileName(): ?string + { + return $this->scopeConfig->getValue(self::XML_PATH_MENU_LOGO, ScopeInterface::SCOPE_STORE); + } +} diff --git a/app/code/Magento/CustomAdminLogo/ViewModel/AdminLogo.php b/app/code/Magento/CustomAdminLogo/ViewModel/AdminLogo.php new file mode 100644 index 00000000000..d4211e1d213 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/ViewModel/AdminLogo.php @@ -0,0 +1,48 @@ +adminLogo; + } + + /** + * Is admin login page + * + * @return bool + */ + public function isAdminLoginPage(): bool + { + return $this->request->getRouteName() === Area::AREA_ADMINHTML + && $this->request->getControllerName() === 'auth' + && $this->request->getActionName() === 'login'; + } +} diff --git a/app/code/Magento/CustomAdminLogo/composer.json b/app/code/Magento/CustomAdminLogo/composer.json new file mode 100644 index 00000000000..c4362ecfe2d --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/composer.json @@ -0,0 +1,24 @@ +{ + "name": "magento/module-custom-admin-logo", + "type": "magento2-module", + "description": "A Magento 2 module that allows admins to set the logo for their admin panel and login screen.", + "license": "MIT", + "authors": [ + { + "name": "Kiel Pykett", + "email": "pykettk@gmail.com" + } + ], + "require": { + "php": "~8.2.0||~8.3.0||~8.4.0", + "magento/module-config": "*" + }, + "autoload": { + "psr-4": { + "Magento\\CustomAdminLogo\\": "" + }, + "files": [ + "registration.php" + ] + } +} diff --git a/app/code/Magento/CustomAdminLogo/etc/adminhtml/system.xml b/app/code/Magento/CustomAdminLogo/etc/adminhtml/system.xml new file mode 100644 index 00000000000..c2765e5ce8a --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/etc/adminhtml/system.xml @@ -0,0 +1,60 @@ + + + + +
+ + + + + + + Supported file types: jpg, jpeg, gif, png + ]]> + + Magento\CustomAdminLogo\Model\Config\Backend\AdminLoginLogo + admin/logo/custom/login + admin/logo/custom/login + + + + + + Supported file types: jpg, jpeg, gif, png + ]]> + + Magento\CustomAdminLogo\Model\Config\Backend\AdminMenuLogo + admin/logo/custom/menu + admin/logo/custom/menu + + +
+
+
diff --git a/app/code/Magento/CustomAdminLogo/etc/module.xml b/app/code/Magento/CustomAdminLogo/etc/module.xml new file mode 100644 index 00000000000..75b72ca26b3 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/etc/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/app/code/Magento/CustomAdminLogo/registration.php b/app/code/Magento/CustomAdminLogo/registration.php new file mode 100644 index 00000000000..25a6822cd7e --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/registration.php @@ -0,0 +1,14 @@ + + + + + + + + + + + Magento\CustomAdminLogo\ViewModel\AdminLogo + + + + + diff --git a/app/code/Magento/CustomAdminLogo/view/adminhtml/templates/page/header.phtml b/app/code/Magento/CustomAdminLogo/view/adminhtml/templates/page/header.phtml new file mode 100644 index 00000000000..418aeb53ff9 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/view/adminhtml/templates/page/header.phtml @@ -0,0 +1,111 @@ +getShowPart(); + +/** @var AdminLogo $adminLogoViewModel */ +$adminLogoViewModel = $block->getData('admin_logo_view_model'); +?> + + + hasEdition()) { + $editionAttribute = 'data-edition="' . $escaper->escapeHtmlAttr($block->getEdition()) . '"'; + } + + $defaultLoginLogo = $block->getViewFileUrl('images/mage-os-logo.svg'); + $defaultMenuLogo = $block->getViewFileUrl('images/mage-os-icon.svg'); + + $logoSrc = $adminLogoViewModel->isAdminLoginPage() + ? ($adminLogoViewModel->getAdminLogoModel()->getCustomAdminLoginLogoSrc() ?: $defaultLoginLogo) + : ($adminLogoViewModel->getAdminLogoModel()->getCustomAdminMenuLogoSrc() ?: $defaultMenuLogo); + ?> + + class="logo" + > + <?= $escaper->escapeHtmlAttr(__('Mage-OS Admin Panel')) ?> + + + + +
+ + + + + + + +
+ + + + getChildHtml() ?> + + diff --git a/app/code/Magento/CustomAdminLogo/view/adminhtml/web/css/module.less b/app/code/Magento/CustomAdminLogo/view/adminhtml/web/css/module.less new file mode 100644 index 00000000000..6ba4daa8b43 --- /dev/null +++ b/app/code/Magento/CustomAdminLogo/view/adminhtml/web/css/module.less @@ -0,0 +1,12 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See LICENCE.txt for licence details. + */ +[id='admin_e119_admin_logos'] [id^='row_admin_e119_admin_logos_'] a { + display: block; + + img { + height: auto; + width: 25rem; + } +}