ConditionRedirectTrait.php in Block Visibility Groups 8
File
src/ConditionRedirectTrait.php
View source
<?php
namespace Drupal\block_visibility_groups;
use Drupal\Core\Form\FormStateInterface;
trait ConditionRedirectTrait {
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,
]);
}
}
protected function setRedirectValue(array &$form, $redirect) {
$form['bvg_redirect'] = [
'#type' => 'value',
'#value' => $redirect,
];
}
}