trait ConditionRedirectTrait in Block Visibility Groups 8
Provides functionality to redirect conditions form to correct location.
Either group edit form or block layout form.
Hierarchy
- trait \Drupal\block_visibility_groups\ConditionRedirectTrait
2 files declare their use of ConditionRedirectTrait
- ConditionDeleteForm.php in src/
Form/ ConditionDeleteForm.php - ConditionFormBase.php in src/
Form/ ConditionFormBase.php
File
- src/
ConditionRedirectTrait.php, line 12
Namespace
Drupal\block_visibility_groupsView source
trait ConditionRedirectTrait {
/**
* Ensure form redirects to the correct route.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
protected function setConditionRedirect(FormStateInterface $form_state) {
$redirect = $form_state
->getValue('bvg_redirect');
if ($redirect == 'edit') {
$form_state
->setRedirectUrl($this->block_visibility_group
->toUrl('edit-form'));
}
elseif ($redirect == 'layout') {
$query = [
'block_visibility_group' => $this->block_visibility_group
->id(),
'show_conditions' => 1,
];
$form_state
->setRedirect('block.admin_display', [], [
'query' => $query,
]);
}
}
/**
* Set value for redirect.
*
* @param array $form
* The form array.
* @param string $redirect
* The redirect option: layout, edit, or null.
*/
protected function setRedirectValue(array &$form, $redirect) {
$form['bvg_redirect'] = [
'#type' => 'value',
'#value' => $redirect,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionRedirectTrait:: |
protected | function | Ensure form redirects to the correct route. | |
ConditionRedirectTrait:: |
protected | function | Set value for redirect. |