Create node upon form submit rendered by block plugin I'm attempting to create a block plugin that displays a form that allows users to enter information and create a node with that information.
I understand I can easily create a form plugin that accomplishes this task but I'd like this to be inside a block plugin so that I can place it on existing pages instead of it being on it's own dedicated page. I'm building the form like so

&lt;?php

/**
 * @file
 * Contains \Drupal\my_plugin\Plugin\Block\EquipmentEntry.
 */

namespace Drupal\my_plugin\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * @Block(
 * id = "equipmententry",
 * admin_label = @Translation("Equipment Entry"),
 *  )
 */

class EquipmentEntry extends BlockBase {
    public function blockForm($form, FormStateInterface $form_state) {
        return $form;
    }
    public function blockSubmit($form, FormStateInterface $form_state) {

    }
    public function build(){
                $content = [
            'container'    =&gt; [
                '#type'       =&gt; 'container',
                '#attributes' =&gt; [
                    'class'      =&gt; ['equipment-entry'],
                ],
                'form'         =&gt; [
                    '#type'       =&gt; 'form',
                    '#attributes' =&gt; [
                        'name'       =&gt; 'equipment-entry',
                        'id'         =&gt; 'test',
                    ],
                    'title'   =&gt; [
                        '#type'  =&gt; 'html_tag',
                        '#tag'   =&gt; 'h1',
                        '#value' =&gt; $title,
                    ],
                    'contact'      =&gt; [
                        '#type'       =&gt; 'textfield',
                        '#title'      =&gt; t('Contact Person'),
                        '#attributes' =&gt; [
                            'name'       =&gt; 'contact',
                        ],
                    ],
                    'Telephone'    =&gt; [
                        '#type'       =&gt; 'textfield',
                        '#title'      =&gt; t('Telephone'),
                        '#attributes' =&gt; [
                            'name'       =&gt; 'phone',
                        ],
                    ],
                ],
             ];
          return $content;
    }
}


However I'm not sure how to perform any action upon submitting the form. I understand there's a blockSubmit() function but I believe that's only when you save a block. 

I tried intercepting the form with a form_alter hook like so

function my_plugin_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
        die($form_id);
}


but the function never fired. Is there a way to programmatically create a node when someone submits a form that was created to be displayed inside a block plugin? Or is there a way to create a form plugin and embed it inside a block?
You are right, the blockSubmit() method is used when you configure the block. The config form is in blockForm(), not in build().

If you put form elements in build() they get rendered like any other render element, but they are not part of the form api and can't be submitted.

If you want to build a form, use a form class. Then you can put the form class in build() by using the formBuilder():

public function build() {

  $content = \Drupal::formBuilder()-&gt;getForm('Drupal\mymodule\Form\MyForm');

  return $content;
}


Better solution:

Instead of building your own form use the entity form for nodes, which you can place in a block with this module: https://www.drupal.org/project/entityform_block