Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "Please follow the rules of our site, click accept button to agree and login in:"
- [Accept Button]
- mydata.redirect_form:
- path: '/user/redirect'
- defaults:
- _form: 'DrupalmydataFormRedirectForm'
- _title: 'Redirect User'
- requirements:
- _permission: 'access content'
- use SymfonyComponentHttpFoundationRedirectResponse;
- use DrupalCoreUrl;
- function mydata_preprocess_page(&$var){
- if(empty($_SESSION['terms_accepted']) || $_SESSION['terms_accepted'] != 'ok'){
- if (Drupal::routeMatch()->getRouteName() == "user.login"){
- $path = Url::fromRoute('mydata.redirect_form', [], ['absolute' => TRUE])->toString();
- $response = new RedirectResponse($path);
- return $response->send();
- }
- }
- }
- namespace DrupalmydataForm;
- use DrupalCoreFormFormBase;
- use DrupalCoreFormFormStateInterface;
- use DrupalCoreUrl;
- use SymfonyComponentHttpFoundationRedirectResponse;
- class RedirectForm extends FormBase {
- public function getFormId() {
- return 'redirect_form';
- }
- public function buildForm(array $form, FormStateInterface $form_state) {
- if(!empty(@$_SESSION['terms_accepted']) || @$_SESSION['terms_accepted'] == 'ok'){
- $path = Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString();
- $response = new RedirectResponse($path);
- return $response->send();
- }
- $form['test'] = [
- '#type' => 'item',
- '#markup' => t('Please Follow the rule of our site,click accept button to agree and login-in: '),
- ];
- $form['submit'] = [
- '#type' => 'submit',
- '#value' => 'Accept',
- ];
- return $form;
- }
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $_SESSION['terms_accepted'] = 'ok';
- if($_SESSION['terms_accepted']){
- $form_state->setRedirect('user.login');
- }
- }
- }
Add Comment
Please, Sign In to add comment