AbstractFieldArray with Image Upload
I have an issue with getting the AbstractFieldArray
class to work with an image upload for Magento Backend.
Basically I have a settings grid with 4 columns. 1 of them contains a dropdown field, the others are text only.
This is my code to create this LinksArray.php
:
namespace VendorModuleBlockSystemConfigFormField;
class LinksArray extends MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray {
protected $_columns = ;
protected $_showRenderer;
protected $_addAfter = true;
protected $_addButtonLabel;
protected function _construct() {
parent::_construct();
$this->_addButtonLabel = __('Add');
}
protected function getShowRenderer() {
if (!$this->_showRenderer) {
$this->_showRenderer = $this->getLayout()->createBlock(
'VendorModuleBlockAdminhtmlFormFieldShow', '', ['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_showRenderer;
}
protected function _prepareToRender() {
$this->addColumn('show', [ 'label' => __('Anzeigen'), 'renderer' => $this->getShowRenderer() ]);
$this->addColumn('label', [ 'label' => __('Label'), 'renderer' => false ]);
$this->addColumn('link_url', [ 'label' => __('Link URL'), 'renderer' => false ]);
$this->addColumn('icon_url', [ 'label' => __('Icon URL'), 'renderer' => false ]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
protected function _prepareArrayRow(MagentoFrameworkDataObject $row) {
$options = ;
$showPicker = $row->_data['show'];
if ($showPicker) {
$options['option_' . $this->getShowRenderer()->calcOptionHash($showPicker)] = 'selected="selected"';
}
$row->setData('option_extra_attrs', $options);
}
public function renderCellTemplate($columnName)
{
if ($columnName == "label") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-label';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "link_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-link_url';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "icon_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-icon_url';
$this->_columns[$columnName]['style'] = '';
}
return parent::renderCellTemplate($columnName);
}
}
The "Show" Class from the getShowRenderer() function is defined in this file Show.php
:
namespace `VendorModuleBlockAdminhtmlFormField`;
class Show extends `MagentoFrameworkViewElementHtmlSelect` {
/**
* methodList
*
* @var array
*/
protected $groupfactory;
/**
* Constructor
*
* @param MagentoFrameworkViewElementContext $context
* @param MagentoBraintreeModelSystemConfigSourceCountry $countrySource
* @param MagentoDirectoryModelResourceModelCountryCollectionFactory $countryCollectionFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementContext $context, MagentoCustomerModelGroupFactory $groupfactory, array $data =
) {
parent::__construct($context, $data);
$this->groupfactory = $groupfactory;
}
/**
* Returns countries array
*
* @return array
*/
/**
* Render block HTML
*
* @return string
*/
public function _toHtml() {
$options = ['Ja', 'Nein'];
if (!$this->getOptions()) {
foreach($options as $option){
$this->addOption($option, $option);
}
}
return parent::_toHtml();
}
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value) {
return $this->setName($value);
}
}
But I could not manage to add an Image Upload to this. I have a model class for the actual upload, but I do not know how to declare a column's input field as image and assign the model Class to it.
I am thankful for any kind of help.
magento2 image backend image-upload array
add a comment |
I have an issue with getting the AbstractFieldArray
class to work with an image upload for Magento Backend.
Basically I have a settings grid with 4 columns. 1 of them contains a dropdown field, the others are text only.
This is my code to create this LinksArray.php
:
namespace VendorModuleBlockSystemConfigFormField;
class LinksArray extends MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray {
protected $_columns = ;
protected $_showRenderer;
protected $_addAfter = true;
protected $_addButtonLabel;
protected function _construct() {
parent::_construct();
$this->_addButtonLabel = __('Add');
}
protected function getShowRenderer() {
if (!$this->_showRenderer) {
$this->_showRenderer = $this->getLayout()->createBlock(
'VendorModuleBlockAdminhtmlFormFieldShow', '', ['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_showRenderer;
}
protected function _prepareToRender() {
$this->addColumn('show', [ 'label' => __('Anzeigen'), 'renderer' => $this->getShowRenderer() ]);
$this->addColumn('label', [ 'label' => __('Label'), 'renderer' => false ]);
$this->addColumn('link_url', [ 'label' => __('Link URL'), 'renderer' => false ]);
$this->addColumn('icon_url', [ 'label' => __('Icon URL'), 'renderer' => false ]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
protected function _prepareArrayRow(MagentoFrameworkDataObject $row) {
$options = ;
$showPicker = $row->_data['show'];
if ($showPicker) {
$options['option_' . $this->getShowRenderer()->calcOptionHash($showPicker)] = 'selected="selected"';
}
$row->setData('option_extra_attrs', $options);
}
public function renderCellTemplate($columnName)
{
if ($columnName == "label") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-label';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "link_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-link_url';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "icon_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-icon_url';
$this->_columns[$columnName]['style'] = '';
}
return parent::renderCellTemplate($columnName);
}
}
The "Show" Class from the getShowRenderer() function is defined in this file Show.php
:
namespace `VendorModuleBlockAdminhtmlFormField`;
class Show extends `MagentoFrameworkViewElementHtmlSelect` {
/**
* methodList
*
* @var array
*/
protected $groupfactory;
/**
* Constructor
*
* @param MagentoFrameworkViewElementContext $context
* @param MagentoBraintreeModelSystemConfigSourceCountry $countrySource
* @param MagentoDirectoryModelResourceModelCountryCollectionFactory $countryCollectionFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementContext $context, MagentoCustomerModelGroupFactory $groupfactory, array $data =
) {
parent::__construct($context, $data);
$this->groupfactory = $groupfactory;
}
/**
* Returns countries array
*
* @return array
*/
/**
* Render block HTML
*
* @return string
*/
public function _toHtml() {
$options = ['Ja', 'Nein'];
if (!$this->getOptions()) {
foreach($options as $option){
$this->addOption($option, $option);
}
}
return parent::_toHtml();
}
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value) {
return $this->setName($value);
}
}
But I could not manage to add an Image Upload to this. I have a model class for the actual upload, but I do not know how to declare a column's input field as image and assign the model Class to it.
I am thankful for any kind of help.
magento2 image backend image-upload array
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02
add a comment |
I have an issue with getting the AbstractFieldArray
class to work with an image upload for Magento Backend.
Basically I have a settings grid with 4 columns. 1 of them contains a dropdown field, the others are text only.
This is my code to create this LinksArray.php
:
namespace VendorModuleBlockSystemConfigFormField;
class LinksArray extends MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray {
protected $_columns = ;
protected $_showRenderer;
protected $_addAfter = true;
protected $_addButtonLabel;
protected function _construct() {
parent::_construct();
$this->_addButtonLabel = __('Add');
}
protected function getShowRenderer() {
if (!$this->_showRenderer) {
$this->_showRenderer = $this->getLayout()->createBlock(
'VendorModuleBlockAdminhtmlFormFieldShow', '', ['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_showRenderer;
}
protected function _prepareToRender() {
$this->addColumn('show', [ 'label' => __('Anzeigen'), 'renderer' => $this->getShowRenderer() ]);
$this->addColumn('label', [ 'label' => __('Label'), 'renderer' => false ]);
$this->addColumn('link_url', [ 'label' => __('Link URL'), 'renderer' => false ]);
$this->addColumn('icon_url', [ 'label' => __('Icon URL'), 'renderer' => false ]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
protected function _prepareArrayRow(MagentoFrameworkDataObject $row) {
$options = ;
$showPicker = $row->_data['show'];
if ($showPicker) {
$options['option_' . $this->getShowRenderer()->calcOptionHash($showPicker)] = 'selected="selected"';
}
$row->setData('option_extra_attrs', $options);
}
public function renderCellTemplate($columnName)
{
if ($columnName == "label") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-label';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "link_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-link_url';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "icon_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-icon_url';
$this->_columns[$columnName]['style'] = '';
}
return parent::renderCellTemplate($columnName);
}
}
The "Show" Class from the getShowRenderer() function is defined in this file Show.php
:
namespace `VendorModuleBlockAdminhtmlFormField`;
class Show extends `MagentoFrameworkViewElementHtmlSelect` {
/**
* methodList
*
* @var array
*/
protected $groupfactory;
/**
* Constructor
*
* @param MagentoFrameworkViewElementContext $context
* @param MagentoBraintreeModelSystemConfigSourceCountry $countrySource
* @param MagentoDirectoryModelResourceModelCountryCollectionFactory $countryCollectionFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementContext $context, MagentoCustomerModelGroupFactory $groupfactory, array $data =
) {
parent::__construct($context, $data);
$this->groupfactory = $groupfactory;
}
/**
* Returns countries array
*
* @return array
*/
/**
* Render block HTML
*
* @return string
*/
public function _toHtml() {
$options = ['Ja', 'Nein'];
if (!$this->getOptions()) {
foreach($options as $option){
$this->addOption($option, $option);
}
}
return parent::_toHtml();
}
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value) {
return $this->setName($value);
}
}
But I could not manage to add an Image Upload to this. I have a model class for the actual upload, but I do not know how to declare a column's input field as image and assign the model Class to it.
I am thankful for any kind of help.
magento2 image backend image-upload array
I have an issue with getting the AbstractFieldArray
class to work with an image upload for Magento Backend.
Basically I have a settings grid with 4 columns. 1 of them contains a dropdown field, the others are text only.
This is my code to create this LinksArray.php
:
namespace VendorModuleBlockSystemConfigFormField;
class LinksArray extends MagentoConfigBlockSystemConfigFormFieldFieldArrayAbstractFieldArray {
protected $_columns = ;
protected $_showRenderer;
protected $_addAfter = true;
protected $_addButtonLabel;
protected function _construct() {
parent::_construct();
$this->_addButtonLabel = __('Add');
}
protected function getShowRenderer() {
if (!$this->_showRenderer) {
$this->_showRenderer = $this->getLayout()->createBlock(
'VendorModuleBlockAdminhtmlFormFieldShow', '', ['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_showRenderer;
}
protected function _prepareToRender() {
$this->addColumn('show', [ 'label' => __('Anzeigen'), 'renderer' => $this->getShowRenderer() ]);
$this->addColumn('label', [ 'label' => __('Label'), 'renderer' => false ]);
$this->addColumn('link_url', [ 'label' => __('Link URL'), 'renderer' => false ]);
$this->addColumn('icon_url', [ 'label' => __('Icon URL'), 'renderer' => false ]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
protected function _prepareArrayRow(MagentoFrameworkDataObject $row) {
$options = ;
$showPicker = $row->_data['show'];
if ($showPicker) {
$options['option_' . $this->getShowRenderer()->calcOptionHash($showPicker)] = 'selected="selected"';
}
$row->setData('option_extra_attrs', $options);
}
public function renderCellTemplate($columnName)
{
if ($columnName == "label") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-label';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "link_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-link_url';
$this->_columns[$columnName]['style'] = '';
}
if ($columnName == "icon_url") {
$this->_columns[$columnName]['class'] = 'input-text required-entry input-text-array-hover-module input-text-array-hover-icon_url';
$this->_columns[$columnName]['style'] = '';
}
return parent::renderCellTemplate($columnName);
}
}
The "Show" Class from the getShowRenderer() function is defined in this file Show.php
:
namespace `VendorModuleBlockAdminhtmlFormField`;
class Show extends `MagentoFrameworkViewElementHtmlSelect` {
/**
* methodList
*
* @var array
*/
protected $groupfactory;
/**
* Constructor
*
* @param MagentoFrameworkViewElementContext $context
* @param MagentoBraintreeModelSystemConfigSourceCountry $countrySource
* @param MagentoDirectoryModelResourceModelCountryCollectionFactory $countryCollectionFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementContext $context, MagentoCustomerModelGroupFactory $groupfactory, array $data =
) {
parent::__construct($context, $data);
$this->groupfactory = $groupfactory;
}
/**
* Returns countries array
*
* @return array
*/
/**
* Render block HTML
*
* @return string
*/
public function _toHtml() {
$options = ['Ja', 'Nein'];
if (!$this->getOptions()) {
foreach($options as $option){
$this->addOption($option, $option);
}
}
return parent::_toHtml();
}
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value) {
return $this->setName($value);
}
}
But I could not manage to add an Image Upload to this. I have a model class for the actual upload, but I do not know how to declare a column's input field as image and assign the model Class to it.
I am thankful for any kind of help.
magento2 image backend image-upload array
magento2 image backend image-upload array
edited Jun 13 '17 at 8:20
sv3n
9,71562352
9,71562352
asked Jun 12 '17 at 7:48
hallleronhallleron
138112
138112
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02
add a comment |
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02
add a comment |
1 Answer
1
active
oldest
votes
I'd like to know this too. I tried to render MagentoConfigBlockSystemConfigFormField, but this can't be done since it is no AbstractBlock (of course). Any idea?
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f178511%2fabstractfieldarray-with-image-upload%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'd like to know this too. I tried to render MagentoConfigBlockSystemConfigFormField, but this can't be done since it is no AbstractBlock (of course). Any idea?
add a comment |
I'd like to know this too. I tried to render MagentoConfigBlockSystemConfigFormField, but this can't be done since it is no AbstractBlock (of course). Any idea?
add a comment |
I'd like to know this too. I tried to render MagentoConfigBlockSystemConfigFormField, but this can't be done since it is no AbstractBlock (of course). Any idea?
I'd like to know this too. I tried to render MagentoConfigBlockSystemConfigFormField, but this can't be done since it is no AbstractBlock (of course). Any idea?
answered 28 mins ago
TommyKTommyK
3414
3414
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f178511%2fabstractfieldarray-with-image-upload%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I need to do the same...have you been able to solve this problem?
– jennymo
Mar 22 '18 at 8:02