Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modulename:
- core_address: 107.101.xx.yy
- core_port: 153759
- core_user: superuser
- core_pass: superpass
- services:
- modulename.my_service:
- class: DrupalmodulenamegroupMyService
- /**
- * @file
- * Contains DrupalmodulenamegroupMyService.
- */
- namespace Drupalmodulenamegroup;
- /**
- * MyService.
- */
- class MyService{
- public function __construct() { }
- public function getDemoValue() {
- $config = Drupal::config('modulename.my_service');
- $core_port = $config->get('modulename.core_port');
- return $core_port. 'asdf';
- }
- }
- /**
- * @file
- * Contains DrupalanothermodulenameControllerMyForm.
- */
- namespace DrupalanothermodulenameController;
- use DrupalCoreFormFormBase;
- use DrupalCoreFormFormStateInterface;
- use DrupalComponentUtilityUrlHelper;
- use SymfonyComponentDependencyInjectionContainerInterface;
- /**
- * MyForm.
- */
- class MyForm extends FormBase {
- protected $demoService;
- /**
- * Class constructor.
- */
- public function __construct($demoService) {
- $this->demoService = $demoService;
- }
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('modulename.my_service')
- );
- }
- /**
- * {@inheritdoc}
- */
- public function getFormId() { /** nothing interesting here **/ }
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state) {
- /** nothing interesting here **/
- return $form;
- }
- /**
- * {@inheritdoc}
- */
- public function validateForm(array &$form, FormStateInterface $form_state){ /** nothing interesting here **/ }
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- // Display result.
- foreach ($form_state->getValues() as $key => $value) {
- drupal_set_message($key . ': ' . $value . ' ' . $this->demoService->getDemoValue()); // i try to print here but didn't happend
- }
- }
- }
- $config = Drupal::config('modulename.my_service');
- $core_port = $config->get('modulename.core_port');
- $config = Drupal::service('config.factory')->getEditable('modulename.my_service');
- $config->set('modulename.core_port', 153760)->save();
- aggregator.admin_settings:
- path: '/admin/config/services/aggregator/settings'
- defaults:
- _form: 'DrupalaggregatorFormSettingsForm'
- _title: 'Feed aggregator settings'
- requirements:
- _permission: 'administer news feeds'
- namespace Drupalmodulename;
- /**
- * Example Service with config.
- */
- class MyService {
- /**
- * Drupal's settings manager.
- */
- protected $settings;
- /**
- * Constructor.
- */
- public function __construct() {
- $this->settings = Drupal::config('modulename.my_service');
- }
- }
- $this->settings->get('modulename.core_port');
- $core_port = $config->get('core_port');
- $config->set('core_port', 8888)->save();
- core_address: 107.101.xx.yy
- core_port: 153759
- core_user: superuser
- core_pass: superpass
Add Comment
Please, Sign In to add comment