Exemplo n.º 1
0
 /**
  * Prepare form
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /* @var $model \Ktpl\Hello\Model\BlogPosts */
     $model = $this->_coreRegistry->registry('hello');
     $isElementDisabled = false;
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix('page_');
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Item Information')]);
     if ($model->getId()) {
         $fieldset->addField('hello_id', 'hidden', ['name' => 'hello_id']);
     }
     $fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Title'), 'title' => __('Title'), 'required' => true, 'disabled' => $isElementDisabled]);
     $wysiwygConfig = $this->_wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
     $contentField = $fieldset->addField('content', 'editor', ['name' => 'content', 'style' => 'height:36em;', 'required' => true, 'disabled' => $isElementDisabled, 'config' => $wysiwygConfig]);
     // Setting custom renderer for content field to remove label column
     $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset\\Element')->setTemplate('Magento_Cms::page/edit/form/renderer/content.phtml');
     $contentField->setRenderer($renderer);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('publish_date', 'date', ['name' => 'publish_date', 'label' => __('Publish Date'), 'date_format' => $dateFormat, 'disabled' => $isElementDisabled, 'class' => 'validate-date validate-date-range date-range-custom_theme-from']);
     $fieldset->addField('is_active', 'select', ['label' => __('Status'), 'title' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => $this->_status->getOptionArray(), 'disabled' => $isElementDisabled]);
     if (!$model->getId()) {
         $model->setData('is_active', $isElementDisabled ? '0' : '1');
     }
     $form->setValues($model->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
Exemplo n.º 2
0
 /**
  * @return $this
  */
 protected function _prepareMassaction()
 {
     $this->setMassactionIdField('hello_id');
     $this->getMassactionBlock()->setTemplate('Ktpl_Hello::hello/grid/massaction_extended.phtml');
     $this->getMassactionBlock()->setFormFieldName('hello');
     $this->getMassactionBlock()->addItem('delete', ['label' => __('Delete'), 'url' => $this->getUrl('hello/*/massDelete'), 'confirm' => __('Are you sure?')]);
     $statuses = $this->_status->getOptionArray();
     $this->getMassactionBlock()->addItem('status', ['label' => __('Change status'), 'url' => $this->getUrl('hello/*/massStatus', ['_current' => true]), 'additional' => ['visibility' => ['name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses]]]);
     return $this;
 }