Please I need help with my code. I have a form and a block created programmatically. The block embeds the form to show it on the frontend. The block also has some settings (form preffix text). I want to load the block settings inside my buildForm in my Form.php to get the preffix text and show it in the form markup field. But I can't seem to find a way to pass on the $block_id to the buildForm() so it can load the block.
I have a scenario where there can be two of these blocks on the same page in which Drupal uniques the block by appending some ID with the block id. So for example my page has two of these blocks one would be like feedbackblock
the other would be feedbackblock_2
hence I cannot hardcode the block id to load it in my buildForm function.
I want it to dynamically pass on the block id to the form.
build() from my Block.php:
public function build() {
$block_id // get the block id of the current block instance
$feedback_form = $this->formBuilder->getForm(FeedbackForm::class, $block_id);
$build = [];
$build['#theme'] = 'feedback_block';
$build['feedback_block']['#markup'] = render($feedback_form);
return $build;
}
buildForm from my FeedbackForm.php:
public function buildForm(array $form, FormStateInterface $form_state, string $block_id) {
// Get the block id here.
}
Is there any way to achieve this?