123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Backend\Block\Widget\Form;
- /**
- * Backend form container block
- *
- * @api
- * @deprecated 100.2.0 in favour of UI component implementation
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- * @since 100.0.2
- */
- class Container extends \Magento\Backend\Block\Widget\Container
- {
- /**
- * @var string
- */
- protected $_objectId = 'id';
- /**
- * @var string[]
- */
- protected $_formScripts = [];
- /**
- * @var string[]
- */
- protected $_formInitScripts = [];
- /**
- * @var string
- */
- protected $_mode = 'edit';
- /**
- * @var string
- */
- protected $_blockGroup = 'Magento_Backend';
-
- /**
- * @var string
- */
- const PARAM_BLOCK_GROUP = 'block_group';
- /**
- * @var string
- */
- const PARAM_MODE = 'mode';
- /**
- * @var string
- */
- protected $_template = 'Magento_Backend::widget/form/container.phtml';
- /**
- * Initialize form.
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
- $this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
- }
- if ($this->hasData(self::PARAM_MODE)) {
- $this->_mode = $this->_getData(self::PARAM_MODE);
- }
- $this->addButton(
- 'back',
- [
- 'label' => __('Back'),
- 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
- 'class' => 'back'
- ],
- -1
- );
- $this->addButton(
- 'reset',
- ['label' => __('Reset'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
- -1
- );
- $objId = (int)$this->getRequest()->getParam($this->_objectId);
- if (!empty($objId)) {
- $this->addButton(
- 'delete',
- [
- 'label' => __('Delete'),
- 'class' => 'delete',
- 'onclick' => 'deleteConfirm(\'' . __(
- 'Are you sure you want to do this?'
- ) . '\', \'' . $this->getDeleteUrl() . '\', {data: {}})'
- ]
- );
- }
- $this->addButton(
- 'save',
- [
- 'label' => __('Save'),
- 'class' => 'save primary',
- 'data_attribute' => [
- 'mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form']],
- ]
- ],
- 1
- );
- }
- /**
- * Create form block
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- if ($this->_blockGroup && $this->_controller && $this->_mode && !$this->_layout->getChildName(
- $this->_nameInLayout,
- 'form'
- )
- ) {
- $this->addChild('form', $this->_buildFormClassName());
- }
- return parent::_prepareLayout();
- }
- /**
- * Build child form class name
- *
- * @return string
- */
- protected function _buildFormClassName()
- {
- return $this->nameBuilder->buildClassName(
- [$this->_blockGroup, 'Block', $this->_controller, $this->_mode, 'Form']
- );
- }
- /**
- * Get URL for back (reset) button
- *
- * @return string
- */
- public function getBackUrl()
- {
- return $this->getUrl('*/*/');
- }
- /**
- * Get URL for delete button.
- *
- * @return string
- */
- public function getDeleteUrl()
- {
- return $this->getUrl('*/*/delete', [$this->_objectId => (int)$this->getRequest()->getParam($this->_objectId)]);
- }
- /**
- * Get form save URL
- *
- * @see getFormActionUrl()
- * @return string
- */
- public function getSaveUrl()
- {
- return $this->getFormActionUrl();
- }
- /**
- * Get form action URL
- *
- * @return string
- */
- public function getFormActionUrl()
- {
- if ($this->hasFormActionUrl()) {
- return $this->getData('form_action_url');
- }
- return $this->getUrl('*/*/save');
- }
- /**
- * Get form HTML.
- *
- * @return string
- */
- public function getFormHtml()
- {
- $this->getChildBlock('form')->setData('action', $this->getSaveUrl());
- return $this->getChildHtml('form');
- }
- /**
- * Get form init scripts.
- *
- * @return string
- */
- public function getFormInitScripts()
- {
- if (!empty($this->_formInitScripts) && is_array($this->_formInitScripts)) {
- return '<script>' . implode("\n", $this->_formInitScripts) . '</script>';
- }
- return '';
- }
- /**
- * Get form scripts.
- *
- * @return string
- */
- public function getFormScripts()
- {
- if (!empty($this->_formScripts) && is_array($this->_formScripts)) {
- return '<script>' . implode("\n", $this->_formScripts) . '</script>';
- }
- return '';
- }
- /**
- * Get header width.
- *
- * @return string
- */
- public function getHeaderWidth()
- {
- return '';
- }
- /**
- * Get header css class.
- *
- * @return string
- */
- public function getHeaderCssClass()
- {
- return 'icon-head head-' . strtr($this->_controller, '_', '-');
- }
- /**
- * Get header HTML.
- *
- * @return string
- */
- public function getHeaderHtml()
- {
- return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
- }
- /**
- * Set data object and pass it to form
- *
- * @param \Magento\Framework\DataObject $object
- * @return $this
- */
- public function setDataObject($object)
- {
- $this->getChildBlock('form')->setDataObject($object);
- return $this->setData('data_object', $object);
- }
- }
|