Pass Preprocess Values From Custom Module to Custom Form

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
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.
8 forms hooks
add a comment |Â
up vote
2
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.
8 forms hooks
add a comment |Â
up vote
2
down vote
favorite
up vote
2
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.
8 forms hooks
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
8 forms hooks
edited Sep 25 at 2:00
asked Sep 25 at 1:04
Prestosaurus
4229
4229
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
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);
$theme = Drupal::theme()->getActiveTheme()->getName();is a direct implementation and requires less code for this use case. Worked 'out of the box'
â Prestosaurus
Sep 25 at 3:46
1
Upon testing, I did find that$theme = Drupal::config('system.theme')->get('default');really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.
â Prestosaurus
Sep 25 at 4:52
add a comment |Â
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');
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
Sep 25 at 3:44
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
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);
$theme = Drupal::theme()->getActiveTheme()->getName();is a direct implementation and requires less code for this use case. Worked 'out of the box'
â Prestosaurus
Sep 25 at 3:46
1
Upon testing, I did find that$theme = Drupal::config('system.theme')->get('default');really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.
â Prestosaurus
Sep 25 at 4:52
add a comment |Â
up vote
2
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);
$theme = Drupal::theme()->getActiveTheme()->getName();is a direct implementation and requires less code for this use case. Worked 'out of the box'
â Prestosaurus
Sep 25 at 3:46
1
Upon testing, I did find that$theme = Drupal::config('system.theme')->get('default');really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.
â Prestosaurus
Sep 25 at 4:52
add a comment |Â
up vote
2
down vote
accepted
up vote
2
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);
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);
answered Sep 25 at 3:27
Cesar Moore
880317
880317
$theme = Drupal::theme()->getActiveTheme()->getName();is a direct implementation and requires less code for this use case. Worked 'out of the box'
â Prestosaurus
Sep 25 at 3:46
1
Upon testing, I did find that$theme = Drupal::config('system.theme')->get('default');really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.
â Prestosaurus
Sep 25 at 4:52
add a comment |Â
$theme = Drupal::theme()->getActiveTheme()->getName();is a direct implementation and requires less code for this use case. Worked 'out of the box'
â Prestosaurus
Sep 25 at 3:46
1
Upon testing, I did find that$theme = Drupal::config('system.theme')->get('default');really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.
â Prestosaurus
Sep 25 at 4:52
$theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'â Prestosaurus
Sep 25 at 3:46
$theme = Drupal::theme()->getActiveTheme()->getName(); is a direct implementation and requires less code for this use case. Worked 'out of the box'â Prestosaurus
Sep 25 at 3:46
1
1
Upon testing, I did find that
$theme = Drupal::config('system.theme')->get('default'); really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.â Prestosaurus
Sep 25 at 4:52
Upon testing, I did find that
$theme = Drupal::config('system.theme')->get('default'); really best fit my original desire. This ensured my front end theme regions created the field items while viewing the admin theme. This was not really specified in my question, feel free to add to your answer as I feel it remains the same.â Prestosaurus
Sep 25 at 4:52
add a comment |Â
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');
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
Sep 25 at 3:44
add a comment |Â
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');
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
Sep 25 at 3:44
add a comment |Â
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');
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');
answered Sep 25 at 2:26
vinhdv
80319
80319
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
Sep 25 at 3:44
add a comment |Â
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
Sep 25 at 3:44
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
Sep 25 at 3:44
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
Sep 25 at 3:44
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password