/app/code/community/AW/Blog/Block/Manage/Blog/Edit/Tab/Form.php

https://gitlab.com/inglobe/mgt-clemente-css · PHP · 216 lines · 204 code · 9 blank · 3 comment · 1 complexity · 21bdfe1131a9981adc9384ee5cb1f714 MD5 · raw file

  1. <?php
  2. class AW_Blog_Block_Manage_Blog_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
  3. {
  4. protected function _prepareForm()
  5. {
  6. $form = new Varien_Data_Form();
  7. $this->setForm($form);
  8. $fieldset = $form->addFieldset('blog_form', array('legend' => Mage::helper('blog')->__('Post information')));
  9. $fieldset->addField(
  10. 'title',
  11. 'text',
  12. array(
  13. 'label' => Mage::helper('blog')->__('Title'),
  14. 'class' => 'required-entry',
  15. 'required' => true,
  16. 'name' => 'title',
  17. )
  18. );
  19. $noticeMessage = Mage::helper('blog')->__('e.g. domain.com/blog/<b>identifier</b>');
  20. $validationErrorMessage = addslashes(
  21. Mage::helper('blog')->__(
  22. "Please use only letters (a-z or A-Z), numbers (0-9) or symbols '-' and '_' in this field"
  23. )
  24. );
  25. $fieldset->addField(
  26. 'identifier',
  27. 'text',
  28. array(
  29. 'label' => Mage::helper('blog')->__('Identifier'),
  30. 'class' => 'required-entry aw-blog-validate-identifier',
  31. 'required' => true,
  32. 'name' => 'identifier',
  33. 'after_element_html' => '<span class="hint">' . $noticeMessage . '</span>'
  34. . "<script>
  35. Validation.add(
  36. 'aw-blog-validate-identifier',
  37. '" . $validationErrorMessage . "',
  38. function(v, elm) {
  39. var regex = new RegExp(/^[a-zA-Z0-9_-]+$/);
  40. return v.match(regex);
  41. }
  42. );
  43. </script>",
  44. )
  45. );
  46. /**
  47. * Check is single store mode
  48. */
  49. if (!Mage::app()->isSingleStoreMode()) {
  50. $fieldset->addField(
  51. 'store_id',
  52. 'multiselect',
  53. array(
  54. 'name' => 'stores[]',
  55. 'label' => Mage::helper('cms')->__('Store View'),
  56. 'title' => Mage::helper('cms')->__('Store View'),
  57. 'required' => true,
  58. 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
  59. )
  60. );
  61. }
  62. $categories = array();
  63. $collection = Mage::getModel('blog/cat')->getCollection()->setOrder('sort_order', 'asc');
  64. foreach ($collection as $cat) {
  65. $categories[] = (array(
  66. 'label' => (string)$cat->getTitle(),
  67. 'value' => $cat->getCatId()
  68. ));
  69. }
  70. $fieldset->addField(
  71. 'cat_id',
  72. 'multiselect',
  73. array(
  74. 'name' => 'cats[]',
  75. 'label' => Mage::helper('blog')->__('Category'),
  76. 'title' => Mage::helper('blog')->__('Category'),
  77. 'required' => true,
  78. 'style' => 'height:100px',
  79. 'values' => $categories,
  80. )
  81. );
  82. $fieldset->addField(
  83. 'status',
  84. 'select',
  85. array(
  86. 'label' => Mage::helper('blog')->__('Status'),
  87. 'name' => 'status',
  88. 'values' => array(
  89. array(
  90. 'value' => 1,
  91. 'label' => Mage::helper('blog')->__('Enabled'),
  92. ),
  93. array(
  94. 'value' => 2,
  95. 'label' => Mage::helper('blog')->__('Disabled'),
  96. ),
  97. array(
  98. 'value' => 3,
  99. 'label' => Mage::helper('blog')->__('Hidden'),
  100. ),
  101. ),
  102. 'after_element_html' => '<span class="hint">'
  103. . Mage::helper('blog')->__(
  104. "Hidden pages won't be shown in blog but still can be accessed directly"
  105. )
  106. . '</span>',
  107. )
  108. );
  109. $fieldset->addField(
  110. 'comments',
  111. 'select',
  112. array(
  113. 'label' => Mage::helper('blog')->__('Enable Comments'),
  114. 'name' => 'comments',
  115. 'values' => array(
  116. array(
  117. 'value' => 0,
  118. 'label' => Mage::helper('blog')->__('Enabled'),
  119. ),
  120. array(
  121. 'value' => 1,
  122. 'label' => Mage::helper('blog')->__('Disabled'),
  123. ),
  124. ),
  125. 'after_element_html' => '<span class="hint">'
  126. . Mage::helper('blog')->__(
  127. 'Disabling will close the post to new comments'
  128. )
  129. . '</span>',
  130. )
  131. );
  132. $fieldset->addField(
  133. 'tags',
  134. 'text',
  135. array(
  136. 'name' => 'tags',
  137. 'label' => Mage::helper('blog')->__('Tags'),
  138. 'title' => Mage::helper('blog')->__('tags'),
  139. 'style' => 'width:700px;',
  140. 'after_element_html' => Mage::helper('blog')->__('Use comma as separator'),
  141. )
  142. );
  143. try {
  144. $config = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
  145. $config->setData(
  146. Mage::helper('blog')->recursiveReplace(
  147. '/blog_admin/',
  148. '/' . (string)Mage::app()->getConfig()->getNode('admin/routers/adminhtml/args/frontName') . '/',
  149. $config->getData()
  150. )
  151. );
  152. } catch (Exception $ex) {
  153. $config = null;
  154. }
  155. $fieldset->addField(
  156. 'exerpt_image',
  157. 'editor',
  158. array(
  159. 'name' => 'exerpt_image',
  160. 'label' => Mage::helper('blog')->__('Exerpt Image'),
  161. 'title' => Mage::helper('blog')->__('Exerpt Image'),
  162. 'style' => 'width:700px; height:17px;',
  163. 'config' => $config,
  164. )
  165. );
  166. if (Mage::getStoreConfig('blog/blog/useshortcontent')) {
  167. $fieldset->addField(
  168. 'short_content',
  169. 'editor',
  170. array(
  171. 'name' => 'short_content',
  172. 'label' => Mage::helper('blog')->__('Short Content'),
  173. 'title' => Mage::helper('blog')->__('Short Content'),
  174. 'style' => 'width:700px; height:100px;',
  175. 'config' => $config,
  176. )
  177. );
  178. }
  179. $fieldset->addField(
  180. 'post_content',
  181. 'editor',
  182. array(
  183. 'name' => 'post_content',
  184. 'label' => Mage::helper('blog')->__('Content'),
  185. 'title' => Mage::helper('blog')->__('Content'),
  186. 'style' => 'width:700px; height:500px;',
  187. 'config' => $config
  188. )
  189. );
  190. if (Mage::getSingleton('adminhtml/session')->getBlogData()) {
  191. $form->setValues(Mage::getSingleton('adminhtml/session')->getBlogData());
  192. Mage::getSingleton('adminhtml/session')->setBlogData(null);
  193. } elseif (Mage::registry('blog_data')) {
  194. Mage::registry('blog_data')->setTags(
  195. Mage::helper('blog')->convertSlashes(Mage::registry('blog_data')->getTags())
  196. );
  197. $form->setValues(Mage::registry('blog_data')->getData());
  198. }
  199. return parent::_prepareForm();
  200. }
  201. }