class FormController

Same name in this branch
  1. 10 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. 8.9.x core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  4. 8.9.x 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 15

Namespace

Drupal\condition_test
View source
class FormController implements FormInterface {
    use StringTranslationTrait;
    
    /**
     * The condition plugin we will be working with.
     *
     * @var \Drupal\Core\Condition\ConditionInterface
     */
    protected $condition;
    
    /**
     * The condition plugin current_theme.
     *
     * @var \Drupal\Core\Condition\ConditionInterface
     */
    protected $conditionCurrentTheme;
    
    /**
     * {@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('entity_bundle:node');
        $this->conditionCurrentTheme = $manager->createInstance('current_theme');
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['#tree'] = TRUE;
        $form['entity_bundle'] = [];
        $subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
        $form['entity_bundle'] = $this->condition
            ->buildConfigurationForm($form['entity_bundle'], $subformState);
        $form['current_theme'] = [];
        $subformState = SubformState::createForSubform($form['current_theme'], $form, $form_state);
        $form['current_theme'] = $this->conditionCurrentTheme
            ->buildConfigurationForm($form['current_theme'], $subformState);
        $form['actions']['submit'] = [
            '#type' => 'submit',
            '#value' => $this->t('Submit'),
        ];
        return $form;
    }
    
    /**
     * Implements \Drupal\Core\Form\FormInterface::validateForm().
     */
    public function validateForm(array &$form, FormStateInterface $form_state) {
        $subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
        $this->condition
            ->validateConfigurationForm($form['entity_bundle'], $subformState);
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitForm(array &$form, FormStateInterface $form_state) {
        $subformState = SubformState::createForSubform($form['entity_bundle'], $form, $form_state);
        $this->condition
            ->submitConfigurationForm($form['entity_bundle'], $subformState);
        $subformState = SubformState::createForSubform($form['current_theme'], $form, $form_state);
        $this->conditionCurrentTheme
            ->submitConfigurationForm($form['current_theme'], $subformState);
        $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($this->t('Executed successfully.'));
        }
        if ($this->conditionCurrentTheme
            ->execute()) {
            \Drupal::messenger()->addStatus($this->conditionCurrentTheme
                ->summary());
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
FormController::$condition protected property The condition plugin we will be working with.
FormController::$conditionCurrentTheme protected property The condition plugin current_theme.
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.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

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