class FormController

Same name in this branch
  1. 9 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  2. 11.x 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. 8.9.x core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
  6. 8.9.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 $condition_current_theme;
  
  /**
   * {@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->condition_current_theme = $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->condition_current_theme
      ->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->condition_current_theme
      ->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->condition_current_theme
      ->execute()) {
      \Drupal::messenger()->addStatus($this->condition_current_theme
        ->summary());
    }
  }

}

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