Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magenizr committed Jun 25, 2021
0 parents commit a397883
Show file tree
Hide file tree
Showing 17 changed files with 651 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Block/Adminhtml/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Magenizr AdminBranding
*
* @category Magenizr
* @package Magenizr_AdminBranding
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminBranding\Block\Adminhtml;

/**
* Class Dashboard
*/
class Login extends \Magento\Framework\View\Element\Template
{
/**
* Base constructor.
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magenizr\AdminBranding\Helper\Data $helper
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magenizr\AdminBranding\Helper\Data $helper
) {
$this->helper = $helper;

parent::__construct($context);
}

/**
* Return helper
*
* @return \Magenizr\AdminBranding\Helper\Data
*/
public function getHelper()
{
return $this->helper;
}

/**
* Check if additional text is enabled
*
* @return mixed
*/
public function isAdditionalTextEnabled()
{
return $this->getHelper()->isSetFlag('magento_adminlogin_additional_text_enabled');
}

/**
* Return additional text
*
* @return mixed
*/
public function getAdditionalText()
{
return $this->getHelper()->getScopeConfig('magento_adminlogin_additional_text');
}
}
138 changes: 138 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Magenizr AdminBranding
*
* @category Magenizr
* @package Magenizr_AdminBranding
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminBranding\Helper;

use \Magento\Framework\App\Request\Http;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/* Section in core config data */
const SECTION = 'admin/magenizr_adminbranding';

/* Name of upload directory in ./media/ */
const UPLOAD_DIR = 'magenizr_adminbranding';

/**
* @var \Magento\Framework\App\Filesystem\DirectoryList
*/
private $directoryList;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
private $fileSystem;

/**
* Data constructor.
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\Helper\Context $context
*/
public function __construct(
\Magento\Framework\Filesystem\Driver\File $fileSystem,
\Magento\Framework\App\Filesystem\DirectoryList $directoryList,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Helper\Context $context
) {
$this->fileSystem = $fileSystem;
$this->directoryList = $directoryList;
$this->storeManager = $storeManager;

parent::__construct($context);
}

/**
* @param $image
* @param $enabled
* @param $file
* @return bool|string
*/
public function getAdminLogoSrc($image, $enabled, $file)
{
// Return default image if not enabled
if (!$this->isSetFlag($enabled) || !$this->isEnabled()) {
return $image;
}

// Path to media folder ( e.g /var/www/src/[project]/pub/media )
$mediaPath = $this->directoryList->getPath('media');

// Uploaded image file via system.xml
$file = explode(',', $this->getScopeConfig($file));

if (isset($file[0])) {
// Absolute path to image file
$mediaPathAbsolute = implode('/', [
$mediaPath, // e.g /var/www/src/[project]/pub/media
self::UPLOAD_DIR, // e.g magenizr_adminbranding/default/
$file[0] // e.g magento_branding.png
]);

// Check if image file actually exists on the filesystem
if ($this->fileSystem->isReadable($mediaPathAbsolute)) {
$mediaPathRelative = '../../../../../../media';

$image = implode('/', [
$mediaPathRelative,
self::UPLOAD_DIR, // e.g magenizr_adminbranding/default/
$file[0] // e.g magento_branding.png
]);

return $image;
}
}

return $image;
}

/**
* Return status of the module
*
* @return mixed
*/
public function isEnabled()
{
return $this->isSetFlag('enabled');
}

/**
* Use isSetFlag to check boolean fields
*
* @param $field
* @return mixed
*/
public function isSetFlag($field)
{
return $this->scopeConfig->isSetFlag(
self::SECTION . '/' . $field,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Get module configuration values from core_config_data
*
* @param $field
* @return mixed
*/
public function getScopeConfig($field)
{
return $this->scopeConfig->getValue(
self::SECTION . '/' . $field,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}
53 changes: 53 additions & 0 deletions Model/Config/Backend/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Magenizr AdminBranding
*
* @category Magenizr
* @package Magenizr_AdminBranding
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/

namespace Magenizr\AdminBranding\Model\Config\Backend;

/**
* Class Image
*
*/
class Image extends \Magento\Config\Model\Config\Backend\Image
{
// @codingStandardsIgnoreStart
/**
* Return path to directory for upload file
*
* @return string
* @throw \Magento\Framework\Exception\LocalizedException
*/
protected function _getUploadDir()
{
return $this->_mediaDirectory->getAbsolutePath(
$this->_appendScopeInfo(\Magenizr\AdminBranding\Helper\Data::UPLOAD_DIR)
);
}

/**
* Makes a decision about whether to add info about the scope.
*
* @return boolean
*/
protected function _addWhetherScopeInfo()
{
return true;
}

/**
* Getter for allowed extensions of uploaded files.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['jpg', 'jpeg', 'gif', 'png', 'svg'];
}
// @codingStandardsIgnoreEnd
}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Admin Branding
Create a unique Magento admin login by adding your company logo or a custom text ( HTML support ) underneath the login such as `Implemented by Your Company Ltd` or above the Magento navigation within the backend.

![Magenizr AdminBranding - Backend Login](https://images2.imgbox.com/5f/43/XpwjZvRQ_o.png)

## System Requirements
- Magento 2.3.x, 2.4.x
- PHP 5.6.x, 7.x

## Installation (Composer)

1. Update your composer.json `composer require "magenizr/magento2-adminbranding":"1.0.0" --no-update`
2. Install dependencies and update your composer.lock `composer update --lock`

```
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing magenizr/magento2-adminbranding (1.0.0): Downloading (100%)
Writing lock file
Generating autoload files
```

3. Enable the module and clear static content.

```
php bin/magento module:enable Magenizr_AdminBranding --clear-static-content
php bin/magento setup:upgrade
```

## Installation (Manually)
1. Download the code.
2. Extract the downloaded tar.gz file. Example: `tar -xzf Magenizr_AdminBranding_1.0.0.tar.gz`.
3. Copy the code into `./app/code/Magenizr/AdminBranding/`.
4. Enable the module and clear static content.

```
php bin/magento module:enable Magenizr_AdminBranding --clear-static-content
php bin/magento setup:upgrade
```

## Features
* Enable / Disable module
* Upload your logo for login form or above the navigation
* Add a custom text ( HTML support ) underneath the login form

## Usage
Go to `Stores > Configuration > Advanced > Admin > Admin Branding` and enable the module. Upload your company logo for the login form or above the sidebar. An additional text can be added and enabled below the login form.

## Support
If you experience any issues, don't hesitate to open an issue on [Github](https://github.com/magenizr/Magenizr_AdminBranding/issues). For a custom build, contact us on [Magento Marketplace](https://marketplace.magento.com/partner/magenizr).

## Purchase
This module is available for free on [GitHub](https://github.com/magenizr).

## Contact
Follow us on [GitHub](https://github.com/magenizr), [Twitter](https://twitter.com/magenizr) and [Facebook](https://www.facebook.com/magenizr).

## History
===== 1.0.0 =====
* Stable version

## License
[OSL - Open Software Licence 3.0](https://opensource.org/licenses/osl-3.0.php)
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "magenizr/magento2-adminbranding",
"description": "Admin Branding allows you to replace the Magento® logo on the admin login page as well as on the dashboard. In addition to that, you can display a custom text and link your clients directly to your issue tracking plattform like JIRA or Zendesk.",
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0"
],
"authors": [
{
"name": "Magenizr",
"email": "modules@magenizr.com",
"homepage": "https://www.magenizr.com"
}
],
"keywords": [
"Magento 2",
"Admin",
"Backend",
"Branding",
"Replace",
"Logo"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magenizr\\AdminBranding\\": ""
}
}
}
21 changes: 21 additions & 0 deletions etc/acl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Magenizr AdminBranding
*
* @category Magenizr
* @package Magenizr_AdminBranding
* @copyright Copyright (c) 2021 Magenizr (https://agency.magenizr.com)
* @license https://www.magenizr.com/license Magenizr EULA
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magenizr_AdminBranding::adminbranding" title="Admin Branding" sortOrder="1000" />
</resource>
</resources>
</acl>
</config>
Loading

0 comments on commit a397883

Please sign in to comment.