class FormController

Same name in this branch
  1. 8.9.x core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
Same name in other branches
  1. 9 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  2. 9 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
  3. 10 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  4. 10 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
  5. 11.x core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  6. 11.x core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController

Routing controller class for condition_test testing of condition forms.

Hierarchy

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_test
View 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

Title Sort descending Modifiers Object type Summary Overriden Title
FormController::$condition protected property The condition plugin we will be working with.
FormController::buildForm public function Form constructor. Overrides FormInterface::buildForm
FormController::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
FormController::submitForm public function Form submission handler. Overrides FormInterface::submitForm
FormController::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm
FormController::__construct public function Constructs a \Drupal\condition_test\FormController object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.