You are here

class FormController in Zircon Profile 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController
  2. 8 core/modules/system/tests/modules/condition_test/src/FormController.php \Drupal\condition_test\FormController
Same name and namespace in other branches
  1. 8.0 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

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 18
Contains \Drupal\condition_test\FormController.

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'] = array(
      '#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_set_message('Bundle: ' . $bundle);
    }
    $article = Node::load(1);
    $this->condition
      ->setContextValue('node', $article);
    if ($this->condition
      ->execute()) {
      drupal_set_message(t('Executed successfully.'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.