public function ContextConfigure::submitForm in Chaos Tool Suite (ctools) 8.3
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ ContextConfigure.php, line 170
Class
Namespace
Drupal\ctools\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $this->tempstore
->get($this->tempstore_id)
->get($this->machine_name);
$contexts = $this
->getContexts($cached_values);
if ($form_state
->getValue('machine_name') != $form_state
->getValue('context_id')) {
$data_type = $form_state
->getValue('context_id');
if (strpos($data_type, 'entity:') === 0) {
$context_definition = new EntityContextDefinition($data_type, $form_state
->getValue('label'), TRUE, FALSE, $form_state
->getValue('description'));
}
else {
$context_definition = new ContextDefinition($data_type, $form_state
->getValue('label'), TRUE, FALSE, $form_state
->getValue('description'));
}
}
else {
$context = $contexts[$form_state
->getValue('machine_name')];
$context_definition = $context
->getContextDefinition();
$context_definition
->setLabel($form_state
->getValue('label'));
$context_definition
->setDescription($form_state
->getValue('description'));
}
// We're dealing with an entity and should make sure it's loaded.
if (strpos($context_definition
->getDataType(), 'entity:') === 0) {
list(, $entity_type) = explode(':', $context_definition
->getDataType());
if (is_numeric($form_state
->getValue('context_value'))) {
$value = $this->entityTypeManager
->getStorage($entity_type)
->load($form_state
->getValue('context_value'));
}
}
else {
$value = $form_state
->getValue('context_value');
}
$context = new Context($context_definition, $value);
$cached_values = $this
->addContext($cached_values, $form_state
->getValue('machine_name'), $context);
$this->tempstore
->get($this->tempstore_id)
->set($this->machine_name, $cached_values);
list($route_name, $route_parameters) = $this
->getParentRouteInfo($cached_values);
$form_state
->setRedirect($route_name, $route_parameters);
}