Guest User

Untitled

a guest
Apr 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. modulename:
  2. core_address: 107.101.xx.yy
  3. core_port: 153759
  4. core_user: superuser
  5. core_pass: superpass
  6.  
  7. services:
  8. modulename.my_service:
  9. class: DrupalmodulenamegroupMyService
  10.  
  11. /**
  12. * @file
  13. * Contains DrupalmodulenamegroupMyService.
  14. */
  15.  
  16. namespace Drupalmodulenamegroup;
  17.  
  18. /**
  19. * MyService.
  20. */
  21. class MyService{
  22.  
  23. public function __construct() { }
  24.  
  25. public function getDemoValue() {
  26. $config = Drupal::config('modulename.my_service');
  27. $core_port = $config->get('modulename.core_port');
  28. return $core_port. 'asdf';
  29. }
  30.  
  31. }
  32.  
  33. /**
  34. * @file
  35. * Contains DrupalanothermodulenameControllerMyForm.
  36. */
  37.  
  38. namespace DrupalanothermodulenameController;
  39.  
  40. use DrupalCoreFormFormBase;
  41. use DrupalCoreFormFormStateInterface;
  42. use DrupalComponentUtilityUrlHelper;
  43. use SymfonyComponentDependencyInjectionContainerInterface;
  44.  
  45. /**
  46. * MyForm.
  47. */
  48. class MyForm extends FormBase {
  49.  
  50. protected $demoService;
  51.  
  52. /**
  53. * Class constructor.
  54. */
  55. public function __construct($demoService) {
  56. $this->demoService = $demoService;
  57. }
  58.  
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public static function create(ContainerInterface $container) {
  63. return new static(
  64. $container->get('modulename.my_service')
  65. );
  66. }
  67.  
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getFormId() { /** nothing interesting here **/ }
  72.  
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function buildForm(array $form, FormStateInterface $form_state) {
  77. /** nothing interesting here **/
  78. return $form;
  79. }
  80.  
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function validateForm(array &$form, FormStateInterface $form_state){ /** nothing interesting here **/ }
  85.  
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function submitForm(array &$form, FormStateInterface $form_state) {
  90. // Display result.
  91. foreach ($form_state->getValues() as $key => $value) {
  92. drupal_set_message($key . ': ' . $value . ' ' . $this->demoService->getDemoValue()); // i try to print here but didn't happend
  93. }
  94. }
  95.  
  96. }
  97.  
  98. $config = Drupal::config('modulename.my_service');
  99.  
  100. $core_port = $config->get('modulename.core_port');
  101.  
  102. $config = Drupal::service('config.factory')->getEditable('modulename.my_service');
  103. $config->set('modulename.core_port', 153760)->save();
  104.  
  105. aggregator.admin_settings:
  106. path: '/admin/config/services/aggregator/settings'
  107. defaults:
  108. _form: 'DrupalaggregatorFormSettingsForm'
  109. _title: 'Feed aggregator settings'
  110. requirements:
  111. _permission: 'administer news feeds'
  112.  
  113. namespace Drupalmodulename;
  114.  
  115. /**
  116. * Example Service with config.
  117. */
  118. class MyService {
  119.  
  120.  
  121. /**
  122. * Drupal's settings manager.
  123. */
  124. protected $settings;
  125.  
  126. /**
  127. * Constructor.
  128. */
  129. public function __construct() {
  130. $this->settings = Drupal::config('modulename.my_service');
  131. }
  132.  
  133. }
  134.  
  135. $this->settings->get('modulename.core_port');
  136.  
  137. $core_port = $config->get('core_port');
  138. $config->set('core_port', 8888)->save();
  139.  
  140. core_address: 107.101.xx.yy
  141. core_port: 153759
  142. core_user: superuser
  143. core_pass: superpass
Add Comment
Please, Sign In to add comment