Guest User

Untitled

a guest
Dec 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. "Please follow the rules of our site, click accept button to agree and login in:"
  2.  
  3. [Accept Button]
  4.  
  5. mydata.redirect_form:
  6. path: '/user/redirect'
  7. defaults:
  8. _form: 'DrupalmydataFormRedirectForm'
  9. _title: 'Redirect User'
  10. requirements:
  11. _permission: 'access content'
  12.  
  13. use SymfonyComponentHttpFoundationRedirectResponse;
  14. use DrupalCoreUrl;
  15.  
  16. function mydata_preprocess_page(&$var){
  17. if(empty($_SESSION['terms_accepted']) || $_SESSION['terms_accepted'] != 'ok'){
  18. if (Drupal::routeMatch()->getRouteName() == "user.login"){
  19. $path = Url::fromRoute('mydata.redirect_form', [], ['absolute' => TRUE])->toString();
  20. $response = new RedirectResponse($path);
  21. return $response->send();
  22.  
  23. }
  24. }
  25. }
  26.  
  27. namespace DrupalmydataForm;
  28.  
  29. use DrupalCoreFormFormBase;
  30. use DrupalCoreFormFormStateInterface;
  31. use DrupalCoreUrl;
  32. use SymfonyComponentHttpFoundationRedirectResponse;
  33.  
  34. class RedirectForm extends FormBase {
  35.  
  36. public function getFormId() {
  37. return 'redirect_form';
  38. }
  39.  
  40. public function buildForm(array $form, FormStateInterface $form_state) {
  41. if(!empty(@$_SESSION['terms_accepted']) || @$_SESSION['terms_accepted'] == 'ok'){
  42. $path = Url::fromRoute('user.login', [], ['absolute' => TRUE])->toString();
  43. $response = new RedirectResponse($path);
  44. return $response->send();
  45. }
  46.  
  47. $form['test'] = [
  48. '#type' => 'item',
  49. '#markup' => t('Please Follow the rule of our site,click accept button to agree and login-in: '),
  50. ];
  51.  
  52. $form['submit'] = [
  53. '#type' => 'submit',
  54. '#value' => 'Accept',
  55. ];
  56.  
  57. return $form;
  58.  
  59. }
  60.  
  61. public function submitForm(array &$form, FormStateInterface $form_state) {
  62. $_SESSION['terms_accepted'] = 'ok';
  63. if($_SESSION['terms_accepted']){
  64. $form_state->setRedirect('user.login');
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment