Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Serializer.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  protected $_jsonEncoder;
20 
26  public function __construct(
27  \Magento\Framework\View\Element\Template\Context $context,
28  \Magento\Framework\Json\EncoderInterface $jsonEncoder,
29  array $data = []
30  ) {
31  $this->_jsonEncoder = $jsonEncoder;
32  parent::__construct($context, $data);
33  }
34 
40  protected function _prepareLayout()
41  {
42  $grid = $this->getGridBlock();
43  if (is_string($grid)) {
44  $grid = $this->getLayout()->getBlock($grid);
45  }
46  if ($grid instanceof \Magento\Backend\Block\Widget\Grid) {
47  $this->setGridBlock($grid)->setSerializeData($grid->{$this->getCallback()}());
48  }
49  return parent::_prepareLayout();
50  }
51 
57  public function _construct()
58  {
59  parent::_construct();
60  $this->setTemplate('Magento_Backend::widget/grid/serializer.phtml');
61  }
62 
69  public function getColumnInputNames($asJSON = false)
70  {
71  if ($asJSON) {
72  return $this->_jsonEncoder->encode((array)$this->getInputNames());
73  }
74  return (array)$this->getInputNames();
75  }
76 
82  public function getDataAsJSON()
83  {
84  $result = [];
85  $inputNames = $this->getInputNames();
86  if ($serializeData = $this->getSerializeData()) {
87  $result = $serializeData;
88  } elseif (!empty($inputNames)) {
89  return '{}';
90  }
91  return $this->_jsonEncoder->encode($result);
92  }
93 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Json\EncoderInterface $jsonEncoder, array $data=[])
Definition: Serializer.php:26