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
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.
8 forms hooks
add a comment |Â
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.
8 forms hooks
add a comment |Â
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.
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 2 hours ago
asked 3 hours ago
Prestosaurus
3979
3979
add a comment |Â
add a comment |Â
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);
$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
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
33 mins ago
add a comment |Â
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);
$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
add a comment |Â
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);
$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
add a comment |Â
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);
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 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
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
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
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
33 mins ago
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
33 mins ago
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 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
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
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
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