Pass Preprocess Values From Custom Module to Custom Form

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












My use case:



I would like to create a unique textfield per region in a custom form.



MYMODULE/MYMODULE.module:



function MYMODULE_preprocess_region(&$variables) 

foreach (array($variables['elements']['#region']) as $key)
drupal_set_message($key);





MYMODULE/src/form/MyModuleForm.php:



protected function getEditableConfigNames() 
return [
'module_config.module_config_settings',
];


public function buildForm(array $form, FormStateInterface $form_state)

$config = $this->config('module_config.module_config_settings');

//build this...
$form['region_name'] = array(
'#type' => 'textfield',
'#title' => t('Form Item Title),
);

return parent::buildForm($form, $form_state);




What is the appropriate way to pass variables/info from the .module file to the .form?



*Note: I have a fully functioning form, hopefully I am showing enough of it to illustrate my focus.










share|improve this question





























    up vote
    1
    down vote

    favorite












    My use case:



    I would like to create a unique textfield per region in a custom form.



    MYMODULE/MYMODULE.module:



    function MYMODULE_preprocess_region(&$variables) 

    foreach (array($variables['elements']['#region']) as $key)
    drupal_set_message($key);





    MYMODULE/src/form/MyModuleForm.php:



    protected function getEditableConfigNames() 
    return [
    'module_config.module_config_settings',
    ];


    public function buildForm(array $form, FormStateInterface $form_state)

    $config = $this->config('module_config.module_config_settings');

    //build this...
    $form['region_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Form Item Title),
    );

    return parent::buildForm($form, $form_state);




    What is the appropriate way to pass variables/info from the .module file to the .form?



    *Note: I have a fully functioning form, hopefully I am showing enough of it to illustrate my focus.










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      My use case:



      I would like to create a unique textfield per region in a custom form.



      MYMODULE/MYMODULE.module:



      function MYMODULE_preprocess_region(&$variables) 

      foreach (array($variables['elements']['#region']) as $key)
      drupal_set_message($key);





      MYMODULE/src/form/MyModuleForm.php:



      protected function getEditableConfigNames() 
      return [
      'module_config.module_config_settings',
      ];


      public function buildForm(array $form, FormStateInterface $form_state)

      $config = $this->config('module_config.module_config_settings');

      //build this...
      $form['region_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Form Item Title),
      );

      return parent::buildForm($form, $form_state);




      What is the appropriate way to pass variables/info from the .module file to the .form?



      *Note: I have a fully functioning form, hopefully I am showing enough of it to illustrate my focus.










      share|improve this question















      My use case:



      I would like to create a unique textfield per region in a custom form.



      MYMODULE/MYMODULE.module:



      function MYMODULE_preprocess_region(&$variables) 

      foreach (array($variables['elements']['#region']) as $key)
      drupal_set_message($key);





      MYMODULE/src/form/MyModuleForm.php:



      protected function getEditableConfigNames() 
      return [
      'module_config.module_config_settings',
      ];


      public function buildForm(array $form, FormStateInterface $form_state)

      $config = $this->config('module_config.module_config_settings');

      //build this...
      $form['region_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Form Item Title),
      );

      return parent::buildForm($form, $form_state);




      What is the appropriate way to pass variables/info from the .module file to the .form?



      *Note: I have a fully functioning form, hopefully I am showing enough of it to illustrate my focus.







      8 forms hooks






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago

























      asked 3 hours ago









      Prestosaurus

      3979




      3979




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          It seems that you can get the list of blocks from this answer: How do i get the all the regions available in the current theme programatically?



          MYMODULE/src/form/MyModuleForm.php:



          protected function getEditableConfigNames() 
          return [
          'module_config.module_config_settings',
          ];


          public function buildForm(array $form, FormStateInterface $form_state)

          // Get the block list based on previous Q/A
          $theme = Drupal::theme()->getActiveTheme()->getName();
          $system_region = system_region_list($theme, REGIONS_ALL);

          foreach ($system_region as $region)
          $form[$region . '_title'] = [
          '#type' => 'textfield',
          '#title' => t('Form ' . $region . ' Title'),
          ];


          return parent::buildForm($form, $form_state);






          share|improve this answer




















          • $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
            – Prestosaurus
            32 mins ago


















          up vote
          1
          down vote













          You try the code



          function MYMODULE_preprocess_region(&$variables) 
          $regions=;
          foreach (array($variables['elements']['#region']) as $key)
          $regions =$key;

          $config = Drupal::service('config.factory')->getEditable('module_config.module_config_settings');
          $config->set('config_regions', $regions);
          $config->save();



          call config:



          $config = $this->config('module_config.module_config_settings');
          $config->get('config_regions');





          share|improve this answer




















          • I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
            – Prestosaurus
            33 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "220"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f269880%2fpass-preprocess-values-from-custom-module-to-custom-form%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          It seems that you can get the list of blocks from this answer: How do i get the all the regions available in the current theme programatically?



          MYMODULE/src/form/MyModuleForm.php:



          protected function getEditableConfigNames() 
          return [
          'module_config.module_config_settings',
          ];


          public function buildForm(array $form, FormStateInterface $form_state)

          // Get the block list based on previous Q/A
          $theme = Drupal::theme()->getActiveTheme()->getName();
          $system_region = system_region_list($theme, REGIONS_ALL);

          foreach ($system_region as $region)
          $form[$region . '_title'] = [
          '#type' => 'textfield',
          '#title' => t('Form ' . $region . ' Title'),
          ];


          return parent::buildForm($form, $form_state);






          share|improve this answer




















          • $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
            – Prestosaurus
            32 mins ago















          up vote
          1
          down vote



          accepted










          It seems that you can get the list of blocks from this answer: How do i get the all the regions available in the current theme programatically?



          MYMODULE/src/form/MyModuleForm.php:



          protected function getEditableConfigNames() 
          return [
          'module_config.module_config_settings',
          ];


          public function buildForm(array $form, FormStateInterface $form_state)

          // Get the block list based on previous Q/A
          $theme = Drupal::theme()->getActiveTheme()->getName();
          $system_region = system_region_list($theme, REGIONS_ALL);

          foreach ($system_region as $region)
          $form[$region . '_title'] = [
          '#type' => 'textfield',
          '#title' => t('Form ' . $region . ' Title'),
          ];


          return parent::buildForm($form, $form_state);






          share|improve this answer




















          • $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
            – Prestosaurus
            32 mins ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          It seems that you can get the list of blocks from this answer: How do i get the all the regions available in the current theme programatically?



          MYMODULE/src/form/MyModuleForm.php:



          protected function getEditableConfigNames() 
          return [
          'module_config.module_config_settings',
          ];


          public function buildForm(array $form, FormStateInterface $form_state)

          // Get the block list based on previous Q/A
          $theme = Drupal::theme()->getActiveTheme()->getName();
          $system_region = system_region_list($theme, REGIONS_ALL);

          foreach ($system_region as $region)
          $form[$region . '_title'] = [
          '#type' => 'textfield',
          '#title' => t('Form ' . $region . ' Title'),
          ];


          return parent::buildForm($form, $form_state);






          share|improve this answer












          It seems that you can get the list of blocks from this answer: How do i get the all the regions available in the current theme programatically?



          MYMODULE/src/form/MyModuleForm.php:



          protected function getEditableConfigNames() 
          return [
          'module_config.module_config_settings',
          ];


          public function buildForm(array $form, FormStateInterface $form_state)

          // Get the block list based on previous Q/A
          $theme = Drupal::theme()->getActiveTheme()->getName();
          $system_region = system_region_list($theme, REGIONS_ALL);

          foreach ($system_region as $region)
          $form[$region . '_title'] = [
          '#type' => 'textfield',
          '#title' => t('Form ' . $region . ' Title'),
          ];


          return parent::buildForm($form, $form_state);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 50 mins ago









          Cesar Moore

          818315




          818315











          • $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
            – Prestosaurus
            32 mins ago

















          • $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
            – Prestosaurus
            32 mins ago
















          $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
          – Prestosaurus
          32 mins ago





          $theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'
          – Prestosaurus
          32 mins ago













          up vote
          1
          down vote













          You try the code



          function MYMODULE_preprocess_region(&$variables) 
          $regions=;
          foreach (array($variables['elements']['#region']) as $key)
          $regions =$key;

          $config = Drupal::service('config.factory')->getEditable('module_config.module_config_settings');
          $config->set('config_regions', $regions);
          $config->save();



          call config:



          $config = $this->config('module_config.module_config_settings');
          $config->get('config_regions');





          share|improve this answer




















          • I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
            – Prestosaurus
            33 mins ago














          up vote
          1
          down vote













          You try the code



          function MYMODULE_preprocess_region(&$variables) 
          $regions=;
          foreach (array($variables['elements']['#region']) as $key)
          $regions =$key;

          $config = Drupal::service('config.factory')->getEditable('module_config.module_config_settings');
          $config->set('config_regions', $regions);
          $config->save();



          call config:



          $config = $this->config('module_config.module_config_settings');
          $config->get('config_regions');





          share|improve this answer




















          • I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
            – Prestosaurus
            33 mins ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          You try the code



          function MYMODULE_preprocess_region(&$variables) 
          $regions=;
          foreach (array($variables['elements']['#region']) as $key)
          $regions =$key;

          $config = Drupal::service('config.factory')->getEditable('module_config.module_config_settings');
          $config->set('config_regions', $regions);
          $config->save();



          call config:



          $config = $this->config('module_config.module_config_settings');
          $config->get('config_regions');





          share|improve this answer












          You try the code



          function MYMODULE_preprocess_region(&$variables) 
          $regions=;
          foreach (array($variables['elements']['#region']) as $key)
          $regions =$key;

          $config = Drupal::service('config.factory')->getEditable('module_config.module_config_settings');
          $config->set('config_regions', $regions);
          $config->save();



          call config:



          $config = $this->config('module_config.module_config_settings');
          $config->get('config_regions');






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          vinhdv

          75019




          75019











          • I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
            – Prestosaurus
            33 mins ago
















          • I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
            – Prestosaurus
            33 mins ago















          I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
          – Prestosaurus
          33 mins ago




          I thought something like $config->set() was what I was looking for, however, $theme = Drupal::theme()->getActiveTheme()->getName(); fits my use case. I do think this answer will be useful to users searching for their own answers.
          – Prestosaurus
          33 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f269880%2fpass-preprocess-values-from-custom-module-to-custom-form%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery