Skip to content

Commit

Permalink
Add theme favicons to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiphan committed Feb 17, 2019
1 parent f149c43 commit ec8bc93
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Model/Theme/Design/Backend/Favicon/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
namespace Thai\S3\Model\Theme\Design\Backend\Favicon;

use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\Theme\Model\Design\Backend\Favicon;
use Thai\S3\Helper\Data;

/**
* Plugin for Favicon.
*
* @see Favicon
*/
class Plugin
{
/**
* @var Data
*/
private $helper;

/**
* @var Database
*/
private $database;

/**
* @param Data $helper
* @param Database $database
*/
public function __construct(
Data $helper,
Database $database
)
{
$this->helper = $helper;
$this->database = $database;
}

/**
* @param Favicon $subject
* @param Favicon $result
* @return Favicon
*/
public function afterBeforeSave(Favicon $subject, Favicon $result)
{
if ($this->helper->checkS3Usage()) {
$imgFile = $subject::UPLOAD_DIR . '/' . $subject->getValue();
$relativeImgFile = $this->database->getMediaRelativePath($imgFile);
$this->database->getStorageDatabaseModel()->saveFile($relativeImgFile);
}

return $result;
}
}
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@
<type name="Magento\Theme\Model\Design\Backend\Logo">
<plugin name="thai_s3_model_theme_design_backend_logo_plugin" type="Thai\S3\Model\Theme\Design\Backend\Logo\Plugin" />
</type>
<type name="Magento\Theme\Model\Design\Backend\Favicon">
<plugin name="thai_s3_model_theme_design_backend_favicon_plugin" type="Thai\S3\Model\Theme\Design\Backend\Favicon\Plugin" />
</type>
</config>

0 comments on commit ec8bc93

Please sign in to comment.