Exemple #1
0
 /**
  * Prepare form
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /* @var $model \SR\Weblog\Model\BlogPosts */
     $model = $this->_coreRegistry->registry('blog_post');
     $isElementDisabled = false;
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix('page_');
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Blog Post Information')]);
     if ($model->getId()) {
         $fieldset->addField('blogpost_id', 'hidden', ['name' => 'blogpost_id']);
     }
     $fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Post Title'), 'title' => __('Post 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();
 }
Exemple #2
0
 /**
  * @return $this
  */
 protected function _prepareMassaction()
 {
     $this->setMassactionIdField('blogpost_id');
     $this->getMassactionBlock()->setTemplate('SR_Weblog::weblog/grid/massaction_extended.phtml');
     $this->getMassactionBlock()->setFormFieldName('blogpost');
     $this->getMassactionBlock()->addItem('delete', ['label' => __('Delete'), 'url' => $this->getUrl('weblog/*/massDelete'), 'confirm' => __('Are you sure?')]);
     $statuses = $this->_status->getOptionArray();
     array_unshift($statuses, ['label' => '', 'value' => '']);
     $this->getMassactionBlock()->addItem('status', ['label' => __('Change status'), 'url' => $this->getUrl('weblog/*/massStatus', ['_current' => true]), 'additional' => ['visibility' => ['name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses]]]);
     return $this;
 }