Skip to content
Open
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
64 changes: 64 additions & 0 deletions app/code/Magento/CustomAdminLogo/Model/AdminLogo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See LICENCE.txt for licence details.
*/
declare(strict_types=1);

namespace Magento\CustomAdminLogo\Model;

use Magento\CustomAdminLogo\Model\Config\Backend\AdminLoginLogo;
use Magento\CustomAdminLogo\Model\Config\Backend\AdminMenuLogo;
use Magento\CustomAdminLogo\Scope\Config;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Driver\File as FileDriver;
use Magento\Framework\UrlInterface;

class AdminLogo
{
/**
* @param Config $moduleConfig
* @param FileDriver $fileDriver
* @param UrlInterface $urlBuilder
*/
public function __construct(
private readonly Config $moduleConfig,
private readonly FileDriver $fileDriver,
private readonly UrlInterface $urlBuilder
) {
}

/**
* Get custom admin login logo src
*
* @return string|null
*/
public function getCustomAdminLoginLogoSrc(): ?string
{
if (!$logoFileName = $this->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
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CustomAdminLogo\Model\Config\Backend;

use Magento\Config\Model\Config\Backend\Image;

class AdminLoginLogo extends Image
{
public const UPLOAD_DIR = 'admin/logo/custom/login';

/**
* @inheritDoc
*/
protected function _getUploadDir(): string
{
return $this->_mediaDirectory->getAbsolutePath(self::UPLOAD_DIR);
}

/**
* @inheritDoc
*/
protected function _addWhetherScopeInfo(): bool
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See LICENCE.txt for licence details.
*/
declare(strict_types=1);

namespace Magento\CustomAdminLogo\Model\Config\Backend;

use Magento\Config\Model\Config\Backend\Image;

class AdminMenuLogo extends Image
{
public const UPLOAD_DIR = 'admin/logo/custom/menu';

/**
* @inheritDoc
*/
protected function _getUploadDir(): string
{
return $this->_mediaDirectory->getAbsolutePath(self::UPLOAD_DIR);
}

/**
* @inheritDoc
*/
protected function _addWhetherScopeInfo(): bool
{
return false;
}
}
80 changes: 80 additions & 0 deletions app/code/Magento/CustomAdminLogo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<div align="center">

<!-- Module Image Here -->

</div>

<h1 align="center">element119 | Custom Admin Logo</h1>

## 📝 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

<br/>

## 🔌 Installation
Run the following command to *install* this module:
```bash
composer require element119/module-custom-admin-logo
php bin/magento setup:upgrade
```

<br/>

## ⏫ Updating
Run the following command to *update* this module:
```bash
composer update element119/module-custom-admin-logo
php bin/magento setup:upgrade
```

<br/>

## ❌ Uninstallation
Run the following command to *uninstall* this module:
```bash
composer remove element119/module-custom-admin-logo
php bin/magento setup:upgrade
```

<br/>

## 📚 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.

<br>

## 📸 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)
45 changes: 45 additions & 0 deletions app/code/Magento/CustomAdminLogo/Scope/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See LICENCE.txt for licence details.
*/
declare(strict_types=1);

namespace Magento\CustomAdminLogo\Scope;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Config
{
private const XML_PATH_LOGIN_LOGO = 'admin/e119_admin_logos/login';
private const XML_PATH_MENU_LOGO = 'admin/e119_admin_logos/menu';

/**
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
private readonly ScopeConfigInterface $scopeConfig
) {
}

/**
* Get admin login logo file from configuration
*
* @return string|null
*/
public function getAdminLoginLogoFileName(): ?string
{
return $this->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);
}
}
48 changes: 48 additions & 0 deletions app/code/Magento/CustomAdminLogo/ViewModel/AdminLogo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © element119. All rights reserved.
* See LICENCE.txt for licence details.
*/
declare(strict_types=1);

namespace Magento\CustomAdminLogo\ViewModel;

use Magento\CustomAdminLogo\Model\AdminLogo as AdminLogoModel;
use Magento\Framework\App\Area;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;

class AdminLogo implements ArgumentInterface
{
/**
* @param AdminLogoModel $adminLogo
* @param RequestInterface $request
*/
public function __construct(
private readonly AdminLogoModel $adminLogo,
private readonly RequestInterface $request
) {
}

/**
* Get admin logo model
*
* @return AdminLogoModel
*/
public function getAdminLogoModel(): AdminLogoModel
{
return $this->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';
}
}
24 changes: 24 additions & 0 deletions app/code/Magento/CustomAdminLogo/composer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
60 changes: 60 additions & 0 deletions app/code/Magento/CustomAdminLogo/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See LICENCE.txt for licence details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="admin">
<group id="e119_admin_logos"
translate="label"
sortOrder="100"
showInDefault="1"
showInWebsite="1"
showInStore="1">
<label>Admin Logos</label>
<field id="login"
translate="label comment"
type="image"
sortOrder="10"
showInDefault="1"
showInWebsite="0"
showInStore="0">
<label>Login Page</label>
<comment>
<![CDATA[
The logo displayed on the admin login page.
<br>
Supported file types: jpg, jpeg, gif, png
]]>
</comment>
<backend_model>Magento\CustomAdminLogo\Model\Config\Backend\AdminLoginLogo</backend_model>
<upload_dir config="system">admin/logo/custom/login</upload_dir>
<base_url type="media" scope_info="0">admin/logo/custom/login</base_url>
</field>
<field id="menu"
translate="label comment"
type="image"
sortOrder="20"
showInDefault="1"
showInWebsite="0"
showInStore="0">
<label>Menu</label>
<comment>
<![CDATA[
The logo displayed at the top of the admin navigation menu.
<br>
Supported file types: jpg, jpeg, gif, png
]]>
</comment>
<backend_model>Magento\CustomAdminLogo\Model\Config\Backend\AdminMenuLogo</backend_model>
<upload_dir config="system">admin/logo/custom/menu</upload_dir>
<base_url type="media" scope_info="0">admin/logo/custom/menu</base_url>
</field>
</group>
</section>
</system>
</config>
Loading
Loading