Skip to content

Commit

Permalink
Merge pull request #634 from magento-dragons/product-video-PR1
Browse files Browse the repository at this point in the history
[EPAM] ProductVideo Sprint #1
  • Loading branch information
Miniailo, Igor(iminiailo) committed Sep 30, 2015
2 parents 5597840 + b8ef9bb commit 26be84a
Show file tree
Hide file tree
Showing 71 changed files with 5,738 additions and 1,154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface ProductAttributeMediaGalleryEntryInterface extends ExtensibleDataInter
const POSITION = 'position';
const DISABLED = 'disabled';
const TYPES = 'types';
const MEDIA_TYPE = 'media_type';
const FILE = 'file';
const CONTENT = 'content';

Expand All @@ -37,6 +38,21 @@ public function getId();
*/
public function setId($id);

/**
* Get media type
*
* @return string
*/
public function getMediaType();

/**
* Set media type
*
* @param string $mediaType
* @return $this
*/
public function setMediaType($mediaType);

/**
* Retrieve gallery entry alternative text
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function remove($sku, $entryId);
* Return information about gallery entry
*
* @param string $sku
* @param int $imageId
* @param int $entryId
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface
*/
public function get($sku, $imageId);
public function get($sku, $entryId);

/**
* Retrieve the list of gallery entries associated with given product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,42 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Helper\Form;

/**
* Class BaseImage
*/
class BaseImage extends \Magento\Framework\Data\Form\Element\AbstractElement
{
/**
* Element output template
*/
const ELEMENT_OUTPUT_TEMPLATE = 'Magento_Catalog::product/edit/base_image.phtml';

/**
* Model Url instance
*
* @var \Magento\Backend\Model\UrlInterface
*/
protected $_url;
protected $url;

/**
* @var \Magento\Catalog\Helper\Data
*/
protected $_catalogHelperData;
protected $catalogHelperData;

/**
* @var \Magento\Framework\File\Size
*/
protected $_fileConfig;
protected $fileConfig;

/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $_assetRepo;
protected $assetRepo;

/**
* @var \Magento\Framework\View\LayoutInterface
*/
protected $layout;

/**
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
Expand All @@ -43,6 +56,7 @@ class BaseImage extends \Magento\Framework\Data\Form\Element\AbstractElement
* @param \Magento\Backend\Model\UrlFactory $backendUrlFactory
* @param \Magento\Catalog\Helper\Data $catalogData
* @param \Magento\Framework\File\Size $fileConfig
* @param \Magento\Framework\View\LayoutInterface $layout
* @param array $data
*/
public function __construct(
Expand All @@ -53,15 +67,17 @@ public function __construct(
\Magento\Backend\Model\UrlFactory $backendUrlFactory,
\Magento\Catalog\Helper\Data $catalogData,
\Magento\Framework\File\Size $fileConfig,
\Magento\Framework\View\LayoutInterface $layout,
array $data = []
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);

$this->_assetRepo = $assetRepo;
$this->_url = $backendUrlFactory->create();
$this->_catalogHelperData = $catalogData;
$this->_fileConfig = $fileConfig;
$this->_maxFileSize = $this->_getFileMaxSize();
$this->assetRepo = $assetRepo;
$this->url = $backendUrlFactory->create();
$this->catalogHelperData = $catalogData;
$this->fileConfig = $fileConfig;
$this->maxFileSize = $this->getFileMaxSize();
$this->layout = $layout;
}

/**
Expand All @@ -71,7 +87,7 @@ public function __construct(
*/
public function getLabel()
{
return __('Images');
return __('Images and Videos');
}

/**
Expand All @@ -81,66 +97,46 @@ public function getLabel()
*/
public function getElementHtml()
{
$htmlId = $this->_escaper->escapeHtml($this->getHtmlId());
$uploadUrl = $this->_escaper->escapeHtml($this->_getUploadUrl());
$spacerImage = $this->_assetRepo->getUrl('images/spacer.gif');
$imagePlaceholderText = __('Click here or drag and drop to add images.');
$deleteImageText = __('Delete image');
$makeBaseText = __('Make Base');
$hiddenText = __('Hidden');
$imageManagementText = __('Image Management');
/** @var $product \Magento\Catalog\Model\Product */
$html = <<<HTML
<div id="{$htmlId}-container" class="images"
data-mage-init='{"baseImage":{}}'
data-max-file-size="{$this->_getFileMaxSize()}"
>
<div class="image image-placeholder">
<input type="file" name="image" data-url="{$uploadUrl}" multiple="multiple" />
<img class="spacer" src="{$spacerImage}"/>
<p class="image-placeholder-text">{$imagePlaceholderText}</p>
</div>
<script id="{$htmlId}-template" data-template="image" type="text/x-magento-template">
<div class="image">
<img class="spacer" src="{$spacerImage}"/>
<img
class="product-image"
src="<%- data.url %>"
data-position="<%- data.position %>"
alt="<%- data.label %>" />
<div class="actions">
<button type="button" class="action-delete" data-role="delete-button" title="{$deleteImageText}">
<span>{$deleteImageText}</span>
</button>
<button type="button" class="action-make-base" data-role="make-base-button" title="{$makeBaseText}">
<span>{$makeBaseText}</span>
</button>
<div class="draggable-handle"></div>
</div>
<div class="image-label"></div>
<div class="image-fade"><span>{$hiddenText}</span></div>
</div>
</script>
</div>
<span class="action-manage-images" data-activate-tab="image-management">
<span>{$imageManagementText}</span>
</span>
<script>
require([
'jquery'
],function($){
'use strict';
$('[data-activate-tab=image-management]')
.on('click.toggleImageManagementTab', function() {
$('#product_info_tabs_image-management').trigger('click');
});
});
</script>
HTML;
return $html;
$block = $this->createElementHtmlOutputBlock();
$this->assignBlockVariables($block);
return $block->toHtml();
}

/**
* @param \Magento\Framework\View\Element\Template $block
* @return \Magento\Framework\View\Element\Template
*/
public function assignBlockVariables(\Magento\Framework\View\Element\Template $block)
{
$block->assign([
'htmlId' => $this->_escaper->escapeHtml($this->getHtmlId()),
'fileMaxSize' => $this->maxFileSize,
'uploadUrl' => $this->_escaper->escapeHtml($this->_getUploadUrl()),
'spacerImage' => $this->assetRepo->getUrl('images/spacer.gif'),
'imagePlaceholderText' => __('Click here or drag and drop to add images.'),
'deleteImageText' => __('Delete image'),
'makeBaseText' => __('Make Base'),
'hiddenText' => __('Hidden'),
'imageManagementText' => __('Images and Videos'),
]);

return $block;
}


/**
* @return \Magento\Framework\View\Element\Template
*/
public function createElementHtmlOutputBlock()
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(
'Magento\Framework\View\Element\Template',
'product.details.form.base.image.element'
);
$block->setTemplate(self::ELEMENT_OUTPUT_TEMPLATE);

return $block;
}

/**
Expand All @@ -150,16 +146,16 @@ class="product-image"
*/
protected function _getUploadUrl()
{
return $this->_url->getUrl('catalog/product_gallery/upload');
return $this->url->getUrl('catalog/product_gallery/upload');
}

/**
* Get maximum file size to upload in bytes
*
* @return int
*/
protected function _getFileMaxSize()
protected function getFileMaxSize()
{
return $this->_fileConfig->getMaxFileSize();
return $this->fileConfig->getMaxFileSize();
}
}
Loading

0 comments on commit 26be84a

Please sign in to comment.