-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNewVideo.php
More file actions
165 lines (151 loc) · 5.2 KB
/
NewVideo.php
File metadata and controls
165 lines (151 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Cloudinary\Cloudinary\Block\Adminhtml\Product\Edit;
use Cloudinary\Cloudinary\Core\ConfigurationBuilder;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\ProductVideo\Helper\Media;
/**
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class NewVideo extends \Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo
{
/**
* @var array|null
*/
protected $_cloudinaryConfig;
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var ConfigurationBuilder
*/
protected $_cloudinaryConfigurationBuilder;
/**
* @method __construct
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Media $mediaHelper
* @param EncoderInterface $jsonEncoder
* @param ConfigurationInterface $configuration
* @param ConfigurationBuilder $cloudinaryConfigurationBuilder
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Media $mediaHelper,
EncoderInterface $jsonEncoder,
ConfigurationInterface $configuration,
ConfigurationBuilder $cloudinaryConfigurationBuilder,
array $data = []
) {
parent::__construct(
$context,
$registry,
$formFactory,
$mediaHelper,
$jsonEncoder,
$data
);
$this->configuration = $configuration;
$this->_cloudinaryConfigurationBuilder = $cloudinaryConfigurationBuilder;
}
protected function getCloudinaryConfig()
{
if (is_null($this->_cloudinaryConfig)) {
$this->_cloudinaryConfig = $this->_cloudinaryConfigurationBuilder->build();
if (!$this->_cloudinaryConfig['cloud']['api_key'] || !$this->_cloudinaryConfig['cloud']['api_secret'] || !$this->_cloudinaryConfig['cloud']['cloud_name']) {
$this->_cloudinaryConfig = false;
} else {
$this->_cloudinaryConfig['cloud']['api_url'] = "https://api.cloudinary.com/v1_1/{$this->_cloudinaryConfig['cloud']['cloud_name']}/";
}
}
return $this->_cloudinaryConfig['cloud'];
}
/**
* Get widget options
*
* @return string
*/
public function getWidgetOptions()
{
return $this->jsonEncoder->encode(
[
'saveVideoUrl' => $this->getUrl('catalog/product_gallery/upload'),
'saveRemoteVideoUrl' => $this->getUrl('product_video/product_gallery/retrieveImage'),
'htmlId' => $this->getHtmlId(),
'youTubeApiKey' => $this->mediaHelper->getYouTubeApiKey(),
'videoSelector' => $this->videoSelector,
'cloudinaryPlaceholder' => $this->getPlaceholderUrl(),
]
);
}
/**
* Get note for video url
*
* @return \Magento\Framework\Phrase
*/
protected function getNoteVideoUrl()
{
if (!$this->configuration->isModuleEnabled()) {
return parent::getNoteVideoUrl();
}
$result = __('Supported: Vimeo');
$messages = "";
if ($this->mediaHelper->getYouTubeApiKey() === null) {
$messages .= __('<br>*To add YouTube video, please <a href="%1">enter YouTube API Key</a> first.', $this->getConfigApiKeyUrl());
} else {
$result .= __(', YouTube');
}
if (!$this->getCloudinaryConfig()) {
$messages .= __('<br>*To add Cloudinary video, please <a href="%1">enter your Cloudinary Account Credentials</a> first.', $this->getCloudinaryConfigUrl());
} else {
$result .= __(', Cloudinary');
}
return $result . $messages;
}
/**
* Get url for Cloudinary config params
*
* @return string
*/
protected function getCloudinaryConfigUrl()
{
return $this->urlBuilder->getUrl(
'adminhtml/system_config/edit',
[
'section' => 'cloudinary'
]
);
}
/**
* @return string
*/
protected function getPlaceholderUrl()
{
$storeManager = $this->configuration->getStoreManager();
$configPaths = [
'catalog/placeholder/image_placeholder',
'catalog/placeholder/small_image_placeholder',
'catalog/placeholder/thumbnail_placeholder',
];
foreach ($configPaths as $configPath) {
if (($path = $storeManager->getStore()->getConfig($configPath))) {
return $storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/placeholder/' . $path;
break;
}
}
return $this->getViewFileUrl('Cloudinary_Cloudinary::images/cloudinary_cloud_glyph_blue.png');
}
}