class FormController in Drupal 8
Same name in this branch
- 8 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
- 8 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
Same name and namespace in other branches
- 9 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
- 10 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
Routing controller class for condition_test testing of condition forms.
Hierarchy
- class \Drupal\condition_test\FormController implements FormInterface
Expanded class hierarchy of FormController
1 string reference to 'FormController'
- condition_test.routing.yml in core/
modules/ system/ tests/ modules/ condition_test/ condition_test.routing.yml - core/modules/system/tests/modules/condition_test/condition_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ condition_test/ src/ FormController.php, line 13
Namespace
Drupal\condition_testView source
class FormController implements FormInterface {
/**
* The condition plugin we will be working with.
*
* @var \Drupal\Core\Condition\ConditionInterface
*/
protected $condition;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'condition_node_type_test_form';
}
/**
* Constructs a \Drupal\condition_test\FormController object.
*/
public function __construct() {
$manager = new ConditionManager(\Drupal::service('container.namespaces'), \Drupal::cache('discovery'), \Drupal::moduleHandler());
$this->condition = $manager
->createInstance('node_type');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = $this->condition
->buildConfigurationForm($form, $form_state);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
];
return $form;
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$this->condition
->validateConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->condition
->submitConfigurationForm($form, $form_state);
$config = $this->condition
->getConfig();
foreach ($config['bundles'] as $bundle) {
\Drupal::messenger()
->addStatus('Bundle: ' . $bundle);
}
$article = Node::load(1);
$this->condition
->setContextValue('node', $article);
if ($this->condition
->execute()) {
\Drupal::messenger()
->addStatus(t('Executed successfully.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormController:: |
protected | property | The condition plugin we will be working with. | |
FormController:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
FormController:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
FormController:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
FormController:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface:: |
|
FormController:: |
public | function | Constructs a \Drupal\condition_test\FormController object. |