I've read through other questions regarding the same error message. They all seem to end up being due to typos or the file path. I don't believe that is the case here, but we'll see. I have a working instance of the same code aside from the names, which is all the more confusing.
I enable the module below. Select place its block. And then when I hit the page, receive:
InvalidArgumentException: The form argument Drupal\terminal\Form\TerminalCliForm is not a valid form. in Drupal\Core\Form\FormBuilder->getFormId() (line 197 of core/lib/Drupal/Core/Form/FormBuilder.php).
I've verified that getFormId receives an empty form_id. I've read that this error message indicates not a bad form in those specific cases but a form file that cannot be found. I'm not certain which is the case, here.
/modules/custom/terminal/src/Form/TerminalCliForm
namespace Drupal\terminal\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class TerminalCliForm.
*/
class TerminalCliForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'terminal_cli_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'terminal/terminal';
$form['canvas'] = [
'#type' => 'textarea',
];
$form['commandline'] = [
'#type' => 'textfield',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Nothing.
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}
/modules/custom/terminal/src/Plugin/Block/TerminalCliBlock - I've tried this with and without the use statement for the form class. In the other module that works correctly, it is present.
namespace Drupal\terminal\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\terminal\Form\TerminalCliForm;
/**
* Provides a 'CliBlock' block.
*
* @Block(
* id = "terminal_cli_block",
* admin_label = @Translation("CLI block"),
* category = @Translation("Engine block")
* )
*/
class TerminalCliBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$form = \Drupal::formBuilder()->getForm(TerminalCliForm::class);
return $form;
}
}
/modules/custom/terminal/src/Form/TerminalCliForm
should have the file extension.php
added to it.