Status message

Maintenant, vous regardez: A real example of Drupal 8 custom module

A real example of Drupal 8 custom module

Create a folder within Drupal installation at the path: /modules/custom/ele_form,
within this ele_form folder, create the following files:

  1. //ele_form.info.yml
  2. name: Ele config form
  3. description: Config form for ele theme , created for footer, homepage and other pages
  4. type: module
  5. version: 1.0
  6. package: ele
  7. core: 8.x
  1. //ele_form.links.menu.yml
  2. ele_form.admin:
  3. title: 'Ele theme settings'
  4. parent: system.admin_config_system
  5. description: 'ele theme settings link'
  6. route_name: ele_form.settings
  1. //ele_form.routing.yml
  2. ele_form.settings:
  3. path: '/admin/config/system/ele-settings'
  4. defaults:
  5. _title: 'Ele theme settings'
  6. _form: '\Drupal\ele_form\Form\EleSettingsForm'
  7. requirements:
  8. _permission: 'administer site configuration'
  1. <?php
  2. //src/Form/EleSettingsForm.php
  3. namespace Drupal\ele_form\Form;
  4.  
  5. use Drupal\Core\Form\ConfigFormBase;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Drupal\Core\Form\FormStateInterface;
  8.  
  9. /**
  10.  * Defines a form that configures forms module settings.
  11.  */
  12. class EleSettingsForm extends ConfigFormBase {
  13.  
  14. /**
  15.   * {@inheritdoc}
  16.   */
  17. public function getFormId() {
  18. return 'ele_form_admin_settings';
  19. }
  20.  
  21. /**
  22.   * {@inheritdoc}
  23.   */
  24. protected function getEditableConfigNames() {
  25. return [
  26. 'ele_form.settings',
  27. ];
  28. }
  29.  
  30. /**
  31.   * {@inheritdoc}
  32.   */
  33. public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  34. $config = $this->config('ele_form.settings');
  35.  
  36. $form['first_screen'] = [
  37. '#type' => 'details',
  38. '#title' => t('Home Description on first screen'),
  39. '#open' => TRUE,
  40. ];
  41.  
  42. $form['first_screen']['home_first_title'] = array(
  43. '#type' => 'textfield',
  44. '#title' => $this->t('Branding'),
  45. '#default_value' => $config->get('home_first_title'),
  46. );
  47.  
  48. $form['first_screen']['home_first_desc'] = array(
  49. '#type' => 'textarea',
  50. '#title' => $this->t('Branding description'),
  51. '#default_value' => $config->get('home_first_desc'),
  52. );
  53.  
  54. $form['first_screen']['home_second_title'] = array(
  55. '#type' => 'textfield',
  56. '#title' => $this->t('Photography'),
  57. '#default_value' => $config->get('home_second_title'),
  58. );
  59.  
  60. $form['first_screen']['home_second_desc'] = array(
  61. '#type' => 'textarea',
  62. '#title' => $this->t('Photography description'),
  63. '#default_value' => $config->get('home_second_desc'),
  64. );
  65.  
  66. $form['first_screen']['home_third_title'] = array(
  67. '#type' => 'textfield',
  68. '#title' => $this->t('Web design'),
  69. '#default_value' => $config->get('home_third_title'),
  70. );
  71.  
  72. $form['first_screen']['home_third_desc'] = array(
  73. '#type' => 'textarea',
  74. '#title' => $this->t('Web design description'),
  75. '#default_value' => $config->get('home_third_desc'),
  76. );
  77.  
  78.  
  79. $form['second_screen'] = [
  80. '#type' => 'details',
  81. '#title' => t('Home description on second screen'),
  82. '#open' => FALSE,
  83. ];
  84.  
  85. $form['second_screen']['home_second_what'] = array(
  86. '#type' => 'textfield',
  87. '#title' => $this->t('what'),
  88. '#default_value' => $config->get('home_second_what'),
  89. );
  90.  
  91. $form['second_screen']['home_second_what_desc'] = array(
  92. '#type' => 'textarea',
  93. '#title' => $this->t('What description'),
  94. '#default_value' => $config->get('home_second_what_desc'),
  95. );
  96.  
  97. $form['second_screen']['home_second_who'] = array(
  98. '#type' => 'textfield',
  99. '#title' => $this->t('who'),
  100. '#default_value' => $config->get('home_second_who'),
  101. );
  102. $form['second_screen']['home_second_who_desc'] = array(
  103. '#type' => 'textarea',
  104. '#title' => $this->t('Who description'),
  105. '#default_value' => $config->get('home_second_who_desc'),
  106. );
  107.  
  108. $form['second_screen']['home_second_how'] = array(
  109. '#type' => 'textfield',
  110. '#title' => $this->t('how'),
  111. '#default_value' => $config->get('home_second_how'),
  112. );
  113. $form['second_screen']['home_second_how_desc'] = array(
  114. '#type' => 'textarea',
  115. '#title' => $this->t('How description'),
  116. '#default_value' => $config->get('home_second_how_desc'),
  117. );
  118.  
  119.  
  120. $form['third_screen'] = [
  121. '#type' => 'details',
  122. '#title' => t('Hoem description on third screen'),
  123. '#open' => FALSE,
  124. ];
  125.  
  126. $form['third_screen']['home_third_small_title'] = array(
  127. '#type' => 'textfield',
  128. '#title' => $this->t('Small title on picture'),
  129. '#default_value' => $config->get('home_third_small_title'),
  130. );
  131.  
  132. $form['third_screen']['home_third_strong_title'] = array(
  133. '#type' => 'textfield',
  134. '#title' => $this->t('Strong title on picture'),
  135. '#default_value' => $config->get('home_third_strong_title'),
  136. );
  137.  
  138. $form['home_work_section'] = [
  139. '#type' => 'details',
  140. '#title' => t('Home work section'),
  141. '#open' => FALSE,
  142. ];
  143.  
  144. $form['home_work_section']['home_work_section_title'] = array(
  145. '#type' => 'textfield',
  146. '#title' => $this->t('Work section title'),
  147. '#default_value' => $config->get('home_work_section_title'),
  148. );
  149.  
  150. $form['home_work_section']['home_work_section_desc'] = array(
  151. '#type' => 'textfield',
  152. '#title' => $this->t('Work section description'),
  153. '#default_value' => $config->get('home_work_section_desc'),
  154. );
  155.  
  156. $form['home_contact_section'] = [
  157. '#type' => 'details',
  158. '#title' => t('Home contact section'),
  159. '#open' => FALSE,
  160. ];
  161.  
  162. $form['home_contact_section']['home_contact_section_title'] = array(
  163. '#type' => 'textfield',
  164. '#title' => $this->t('Home contact section title'),
  165. '#default_value' => $config->get('home_contact_section_title'),
  166. );
  167.  
  168. $form['home_contact_section']['home_contact_section_desc'] = array(
  169. '#type' => 'textfield',
  170. '#title' => $this->t('Home contact section description'),
  171. '#default_value' => $config->get('home_contact_section_desc'),
  172. );
  173.  
  174. $form['site_footer'] = [
  175. '#type' => 'details',
  176. '#title' => t('Elements on footer'),
  177. '#open' => FALSE,
  178. ];
  179.  
  180. $form['site_footer']['site_footer_email'] = array(
  181. '#type' => 'textfield',
  182. '#title' => $this->t('Email'),
  183. '#default_value' => $config->get('site_footer_email'),
  184. );
  185.  
  186. $form['site_footer']['site_footer_phone'] = array(
  187. '#type' => 'textfield',
  188. '#title' => $this->t('Phome'),
  189. '#default_value' => $config->get('site_footer_phone'),
  190. );
  191.  
  192. $form['site_footer']['site_footer_address'] = array(
  193. '#type' => 'textfield',
  194. '#title' => $this->t('Address'),
  195. '#default_value' => $config->get('site_footer_address'),
  196. );
  197.  
  198. return parent::buildForm($form, $form_state);
  199. }
  200.  
  201. /**
  202.   * {@inheritdoc}
  203.   */
  204. public function submitForm(array &$form, FormStateInterface $form_state) {
  205. $values = $form_state->getValues();
  206. $this->config('ele_form.settings')
  207. ->set('home_first_title', $values['home_first_title'])
  208. ->set('home_first_desc', $values['home_first_desc'])
  209. ->set('home_second_title', $values['home_second_title'])
  210. ->set('home_second_desc', $values['home_second_desc'])
  211. ->set('home_third_title', $values['home_third_title'])
  212. ->set('home_third_desc', $values['home_third_desc'])
  213. ->set('home_second_what', $values['home_second_what'])
  214. ->set('home_second_what_desc', $values['home_second_what_desc'])
  215. ->set('home_second_who', $values['home_second_who'])
  216. ->set('home_second_who_desc', $values['home_second_who_desc'])
  217. ->set('home_second_how', $values['home_second_how'])
  218. ->set('home_second_how_desc', $values['home_second_how_desc'])
  219. ->set('home_third_small_title', $values['home_third_small_title'])
  220. ->set('home_third_strong_title', $values['home_third_strong_title'])
  221. ->set('home_work_section_title', $values['home_work_section_title'])
  222. ->set('home_work_section_desc', $values['home_work_section_desc'])
  223. ->set('home_contact_section_title', $values['home_contact_section_title'])
  224. ->set('home_contact_section_desc', $values['home_contact_section_desc'])
  225. ->set('site_footer_email', $values['site_footer_email'])
  226. ->set('site_footer_phone', $values['site_footer_phone'])
  227. ->set('site_footer_address', $values['site_footer_address'])
  228. ->save();
  229. }
  230.  
  231. }

Tags:

Comments

http://tribtaiti.webcindario.com/ drugs for sale deep web
canadian online pharmacies rated http://tribtaiti.webcindario.com/
canadian pharmacies-24h http://tribtaiti.webcindario.com/

https://canadianhpharmacy.com/ canadian pharmacy viagra brand
northwestpharmacy https://canadianhpharmacy.com/
best canadian pharmacies online https://canadianhpharmacy.com/

https://canadianlpharmacy.com/ drugs for sale in mexico
northwest pharmacies mail order https://canadianlpharmacy.com/
canadian pharmacy no prescription https://canadianlpharmacy.com/

https://canadianhpharmacy.com/ canadian pharmacy no prescription
drugs for sale on internet https://canadianhpharmacy.com/
canadian pharmacies without an rx https://canadianhpharmacy.com/

https://canadianlpharmacy.com/ aarp recommended canadian pharmacies
online pharmacies https://canadianlpharmacy.com/
best canadian pharmacies online https://canadianlpharmacy.com/

https://canadianlpharmacy.com/ discount canadian pharmacies
canadian drugs https://canadianlpharmacy.com/
canadian pharmacy no prescription https://canadianlpharmacy.com/

https://viagracwithoutdoctor.com/ canadian pharmacies shipping to usa
pharmacy canada https://viagracwithoutdoctor.com/
online pharmacies tech school https://viagracwithoutdoctor.com/

https://canadianlpharmacy.com/ canadian government approved pharmacies
good canadian online pharmacies https://canadianlpharmacy.com/
canadian pharmacy online 24 https://canadianlpharmacy.com/

https://canadianlpharmacy.com/ canada medication pharmacy
canadian online pharmacies legitimate https://canadianlpharmacy.com/
trust pharmacy of canada https://canadianlpharmacy.com/

https://canadianlpharmacy.com/ canadian online pharmacy
aarp recommended canadian pharmacies https://canadianlpharmacy.com/
northwestpharmacy https://canadianlpharmacy.com/

https://canadianhpharmacy.com/ drugstore online india
canadian pharmacies stendra https://canadianhpharmacy.com/
canadian pharcharmy online https://canadianhpharmacy.com/

https://viagracwithoutdoctor.com/ canadian medications pharmacy
canadian prescriptions online https://viagracwithoutdoctor.com/
online canadian pharmacies https://viagracwithoutdoctor.com/

https://viagracwithoutdoctor.com/ viagra canadiense
drugs for sale in mexico https://viagracwithoutdoctor.com/
the best canadian online pharmacies https://viagracwithoutdoctor.com/

https://canadianlpharmacy.com/ drugs for sale on internet
canadian online pharmacies legal https://canadianlpharmacy.com/
canadian government approved pharmacies https://canadianlpharmacy.com/

https://canadianlpharmacy.com/ the best canadian online pharmacies
canada medication cost https://canadianlpharmacy.com/
canadianpharmacyusa24h https://canadianlpharmacy.com/

https://canadianhpharmacy.com/ online pharmacies legitimate
canadian pharmacies without an rx https://canadianhpharmacy.com/
aarp recommended canadian online pharmacies https://canadianhpharmacy.com/

https://canadianhpharmacy.com/ are canadian online pharmacies safe
canadian medications by mail https://canadianhpharmacy.com/
buy viagra 25mg https://canadianhpharmacy.com/

https://canadianlpharmacy.com/ canadian pharmacies that ship to us
canadian pharmacies online prescriptions https://canadianlpharmacy.com/
canadian prescription drugstore https://canadianlpharmacy.com/

https://viagracwithoutdoctor.com/ trusted pharmacy canada scam
drugs for sale in mexico https://viagracwithoutdoctor.com/
good canadian online pharmacies https://viagracwithoutdoctor.com/

https://viagracwithoutdoctor.com/ top rated canadian pharmacies online
best canadian pharmacy https://viagracwithoutdoctor.com/
legitimate canadian mail order pharmacies https://viagracwithoutdoctor.com/

https://viagrawwithoutdoctor.com/ order canadian prescriptions online
canadian drugstore https://viagrawwithoutdoctor.com/
drugs for sale usa https://viagrawwithoutdoctor.com/

https://viagrawwithoutdoctor.com/ trusted pharmacy canada scam
canadian pharmaceuticals for usa sales https://viagrawwithoutdoctor.com/
canadian online pharmacies rated https://viagrawwithoutdoctor.com/

https://viagracwithoutdoctor.com/ buy viagra now
online canadian discount pharmacies https://viagracwithoutdoctor.com/
aarp recommended canadian online pharmacies https://viagracwithoutdoctor.com/

Pages

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.