Closed oppssssss closed 7 years ago
to add category and FAQ form is not showing in magento 2.1.3 see the screenshot
This does not work in 2.1.3. No form is displayed when editing or re-creating categories or FAQs
You should download all the source code with the latest version to your computer
I have last version (master) installed. That did not help. The form is not displayed. In the log is: [2017-03-08 22:22:34] main.CRITICAL: Warning: htmlspecialchars () expects parameter 1 to be string, array given in ..... vendor / magento / framework / Data / Form / Element / AbstractElement.php on line 286 [] []
Is anyone resolve the issue with Magento 2.1.3
We are not able to view the FAQ ADD/EDIT form. Kindly fix this or send me updated branch access
Please, too. This does not work with versions 2.1.3 / 2.1.4 / 2.1.5. Under 2.1.3 I have not tested.
@php-cuong kindly resolve the issue with Version 2.1.3 or upper.
I have mean, I have not tested with version 2.1.2. Otherwise you see the picture above, I use version 2.1.3 and it is blank page displayed. I do not install with the composer. Can it be that in the ZIP not all files are
@mironsoft75 @php-cuong it's not working with composer . I am getting same error
Exception #0 (Exception): Warning: htmlspecialchars() expects parameter 1 to be string, array given
issue resolved. I am able to get Add/Edit form on Magento 2.1.x
@ramanvirtuos how did u resolved the issue
we are facing the same issue in magento 2.0.13
Hi,
You have to update the PHPCuong\Faq\Block\Adminhtml\Faq\Edit\Tab\Websites.php
Function Name: _prepareForm
Comment this function and replace with following Code:
/**
@return $this */ protected function _prepareForm() { /* @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faq');
/**
* Check is single store mode
*/
if (!$this->_storeManager->isSingleStoreMode()) {
$storeField = $fieldset->addField(
'store_id',
'multiselect',
[
'name' => 'stores[]',
'label' => __('Store View'),
'title' => __('Store View'),
'required' => true,
'values' => $this->_systemStore->getStoreValuesForForm(false, true)
]
);
$renderer = $this->getLayout()->createBlock(
'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
);
$storeField->setRenderer($renderer);
} else {
$fieldset->addField(
'store_id',
'hidden',
['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]
);
$formData->setStoreId($this->_storeManager->getStore(true)->getId());
}
$data = $formData->getData(); $data['store_id'] = $formData->getStores(); $form->setValues($data);
$this->setForm($form);
// $this->setForm($form);
return parent::_prepareForm();
}
Exception #0 (Exception): Warning: htmlspecialchars() expects parameter 1 to be string, array given
we are getting above error while adding faq category and faq in magento 2.0.13
error is not resolved after Comment this function and replace with following Code:
/**
@return $this / protected function _prepareForm() { / @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faq');
/**
if (!$this->_storeManager->isSingleStoreMode()) { $storeField = $fieldset->addField( 'store_id', 'multiselect', [ 'name' => 'stores[]', 'label' => ('Store View'), 'title' => ('Store View'), 'required' => true, 'values' => $this->_systemStore->getStoreValuesForForm(false, true) ] ); $renderer = $this->getLayout()->createBlock( 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' ); $storeField->setRenderer($renderer); } else { $fieldset->addField( 'store_id', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()] ); $formData->setStoreId($this->_storeManager->getStore(true)->getId()); }
$data = $formData->getData(); $data['store_id'] = $formData->getStores(); $form->setValues($data);
$this->setForm($form);
// $this->setForm($form);
return parent::_prepareForm();
}
we are facing the same issue while adding categories in FAQ in magento 2.0.13
I have changed $formData->setStores($this->_storeManager->getStore(true)->getId());
instead of $formData->setStoreId($this->_storeManager->getStore(true)->getId());
and working fine. Add/edit screen working fine
`<?php
/*
namespace PHPCuong\Faq\Block\Adminhtml\Faqcat\Edit\Tab;
use Magento\Store\Model\Store;
class Websites extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { /**
@var \Magento\Framework\Registry */ protected $_coreRegistry;
/**
@var \Magento\Store\Model\System\Store */ protected $_systemStore;
/**
@param array $data */ public function __construct( \Magento\Store\Model\System\Store $systemStore, \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, array $data = [] ) { $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); }
/**
@return void */ protected function _construct() { parent::_construct(); $this->setActive(true); }
/**
@return \Magento\Framework\Phrase */ public function getTabLabel() { return __('FAQ Category in Websites'); }
/**
@return \Magento\Framework\Phrase */ public function getTabTitle() { return $this->getTabLabel(); }
/**
@return true */ public function canShowTab() { return true; }
/**
@return true */ public function isHidden() { return false; }
/**
@return $this */ protected function _prepareForm() { /* @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ Category in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faqcat');
/**
* Check is single store mode
*/
if (!$this->_storeManager->hasSingleStore()) {
$field = $fieldset->addField(
'stores',
'multiselect',
[
'label' => __('Stores View'),
'title' => __('Stores View'),
'required' => true,
'name' => 'stores[]',
'values' => $this->_systemStore->getStoreValuesForForm(false, true)
]
);
$renderer = $this->getLayout()->createBlock(
'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
);
$field->setRenderer($renderer);
$formData->setSelectStores($formData->getStores());
} else {
$fieldset->addField(
'stores',
'hidden',
['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]
);
$formData->setStores($this->_storeManager->getStore(true)->getId());
}
if ($formData) {
if ($formData->getStores() == null) {
$formData->setStores([Store::DEFAULT_STORE_ID]);
}
$form->setValues($formData->getData());
}
$this->setForm($form);
return parent::_prepareForm();
} } `
`<?php
/*
namespace PHPCuong\Faq\Block\Adminhtml\Faq\Edit\Tab;
use Magento\Store\Model\Store;
class Websites extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { /**
@var \Magento\Framework\Registry */ protected $_coreRegistry;
/**
@var \Magento\Store\Model\System\Store */ protected $_systemStore;
/**
@param array $data */ public function __construct( \Magento\Store\Model\System\Store $systemStore, \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, array $data = [] ) { $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); }
/**
@return void */ protected function _construct() { parent::_construct(); $this->setActive(true); }
/**
@return \Magento\Framework\Phrase */ public function getTabLabel() { return __('FAQ in Websites'); }
/**
@return \Magento\Framework\Phrase */ public function getTabTitle() { return $this->getTabLabel(); }
/**
@return true */ public function canShowTab() { return true; }
/**
@return true */ public function isHidden() { return false; }
/**
@return $this */ protected function _prepareForm() { /* @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faq');
/**
* Check is single store mode
*/
if (!$this->_storeManager->hasSingleStore()) {
$field = $fieldset->addField(
'stores',
'multiselect',
[
'label' => __('Stores View'),
'title' => __('Stores View'),
'required' => true,
'name' => 'stores[]',
'values' => $this->_systemStore->getStoreValuesForForm(false, true)
]
);
$renderer = $this->getLayout()->createBlock(
'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'
);
$field->setRenderer($renderer);
$formData->setSelectStores($formData->getStores());
} else {
$fieldset->addField(
'stores',
'hidden',
['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]
);
$formData->setStores($this->_storeManager->getStore(true)->getId());
}
if ($formData) {
if ($formData->getStores() == null) {
$formData->setStores([Store::DEFAULT_STORE_ID]);
}
$form->setValues($formData->getData());
}
$this->setForm($form);
return parent::_prepareForm();
} } `
Above code works with 2.16 :)
i have correct edit-add form at 2.1.6 CE but only for Faq, not for Categories!! Any idea?
You need to change 2 files /app/code/PHPCuong/Faq/Block/Adminhtml/Faqcat/Edit/Tab/Websites.php /app/code/PHPCuong/Faq/Block/Adminhtml/Faq/Edit/Tab/Websites.php
/Faqcat/Edit/Tab/Websites.php change on row 139 $formData->setSelectStores($this->_storeManager->getStore(true)->getId()); TO $formData->setStores($this->_storeManager->getStore(true)->getId());
/Faq/Edit/Tab/Websites.php change on row 139 $formData->setSelectStores($this->_storeManager->getStore(true)->getId()); TO $formData->setStores($this->_storeManager->getStore(true)->getId());
Tested it on 2.17 CE
Please update these 2 files :
app\code\PHPCuong\Faq\Block\Adminhtml\Faq\Edit\Tab\Websites.php
`<?php
/*
namespace PHPCuong\Faq\Block\Adminhtml\Faq\Edit\Tab;
use Magento\Store\Model\Store;
class Websites extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { /**
@var \Magento\Framework\Registry */ protected $_coreRegistry;
/**
@var \Magento\Store\Model\System\Store */ protected $_systemStore;
/**
@param array $data */ public function __construct( \Magento\Store\Model\System\Store $systemStore, \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, array $data = [] ) { $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); }
/**
@return void */ protected function _construct() { parent::_construct(); $this->setActive(true); }
/**
@return \Magento\Framework\Phrase */ public function getTabLabel() { return __('FAQ in Websites'); }
/**
@return \Magento\Framework\Phrase */ public function getTabTitle() { return $this->getTabLabel(); }
/**
@return true */ public function canShowTab() { return true; }
/**
@return true */ public function isHidden() { return false; }
/**
@return $this */ protected function _prepareForm() { /* @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faq');
/**
* Check is single store mode
*/
// if (!$this->_storeManager->hasSingleStore()) { $field = $fieldset->addField( 'stores', 'multiselect', [ 'label' => ('Stores View'), 'title' => ('Stores View'), 'required' => true, 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm(false, true) ] ); $renderer = $this->getLayout()->createBlock( 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' ); $field->setRenderer($renderer); $formData->setSelectStores($formData->getStores()); /} else { $fieldset->addField( 'stores', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()] ); $formData->setSelectStores($this->_storeManager->getStore(true)->getId()); }/
if ($formData) {
if ($formData->getStores() == null) {
$formData->setStores([Store::DEFAULT_STORE_ID]);
}
$form->setValues($formData->getData());
}
$this->setForm($form);
return parent::_prepareForm();
} } `
app\code\PHPCuong\Faq\Block\Adminhtml\Faqcat\Edit\Tab\Websites.php
`<?php
/*
namespace PHPCuong\Faq\Block\Adminhtml\Faqcat\Edit\Tab;
use Magento\Store\Model\Store;
class Websites extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { /**
@var \Magento\Framework\Registry */ protected $_coreRegistry;
/**
@var \Magento\Store\Model\System\Store */ protected $_systemStore;
/**
@param array $data */ public function __construct( \Magento\Store\Model\System\Store $systemStore, \Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, array $data = [] ) { $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); }
/**
@return void */ protected function _construct() { parent::_construct(); $this->setActive(true); }
/**
@return \Magento\Framework\Phrase */ public function getTabLabel() { return __('FAQ Category in Websites'); }
/**
@return \Magento\Framework\Phrase */ public function getTabTitle() { return $this->getTabLabel(); }
/**
@return true */ public function canShowTab() { return true; }
/**
@return true */ public function isHidden() { return false; }
/**
@return $this */ protected function _prepareForm() { /* @var \Magento\Framework\Data\Form $form / $form = $this->_formFactory->create();
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('FAQ Category in Websites')]);
$this->_addElementTypes($fieldset);
$formData = $this->_coreRegistry->registry('phpcuong_faqcat');
/**
* Check is single store mode
*/
// if (!$this->_storeManager->hasSingleStore()) { $field = $fieldset->addField( 'stores', 'multiselect', [ 'label' => ('Stores View'), 'title' => ('Stores View'), 'required' => true, 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm(false, true) ] ); $renderer = $this->getLayout()->createBlock( 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' ); $field->setRenderer($renderer); $formData->setSelectStores($formData->getStores()); / } else { $fieldset->addField( 'stores', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()] ); $formData->setSelectStores($this->_storeManager->getStore(true)->getId()); }/
if ($formData) {
if ($formData->getStores() == null) {
$formData->setStores([Store::DEFAULT_STORE_ID]);
}
$form->setValues($formData->getData());
}
$this->setForm($form);
return parent::_prepareForm();
} } `
Above code is tested and also working in magento CE 2.1.x.
Thanks..
The problem was fixed, please pull the latest codes.