redirect connected user to node/add/offre
This commit is contained in:
parent
33f79c0d3e
commit
d27c68f389
|
@ -71,7 +71,7 @@ content:
|
||||||
type: entity_reference_label
|
type: entity_reference_label
|
||||||
label: above
|
label: above
|
||||||
settings:
|
settings:
|
||||||
link: true
|
link: false
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
weight: 1
|
weight: 1
|
||||||
region: content
|
region: content
|
||||||
|
|
|
@ -25,7 +25,7 @@ content:
|
||||||
type: image
|
type: image
|
||||||
label: visually_hidden
|
label: visually_hidden
|
||||||
settings:
|
settings:
|
||||||
image_link: ''
|
image_link: content
|
||||||
image_style: large
|
image_style: large
|
||||||
image_loading:
|
image_loading:
|
||||||
attribute: lazy
|
attribute: lazy
|
||||||
|
@ -43,7 +43,7 @@ content:
|
||||||
type: entity_reference_label
|
type: entity_reference_label
|
||||||
label: above
|
label: above
|
||||||
settings:
|
settings:
|
||||||
link: true
|
link: false
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
weight: 1
|
weight: 1
|
||||||
region: content
|
region: content
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Drupal\loginregisterblock\Plugin\Block;
|
namespace Drupal\loginregisterblock\Plugin\Block;
|
||||||
|
|
||||||
use Drupal\Core\Block\BlockBase;
|
use Drupal\Core\Block\BlockBase;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
// use RedirectDestinationTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a 'login register' Block.
|
* Provides a 'login register' Block.
|
||||||
|
@ -19,23 +21,28 @@ class LoginRegisterBlock extends BlockBase {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function build() {
|
public function build() {
|
||||||
$loginform = \Drupal::formBuilder()->getForm('Drupal\user\Form\UserLoginForm');
|
|
||||||
$newuser = \Drupal::entityTypeManager()->getStorage('user')->create();
|
$user = \Drupal::currentUser();
|
||||||
$registerform = \Drupal::service('entity.form_builder')->getForm($newuser, 'register');
|
if ($user->id() === 0) {
|
||||||
|
$loginform = \Drupal::formBuilder()->getForm('Drupal\user\Form\UserLoginForm');
|
||||||
return [
|
$newuser = \Drupal::entityTypeManager()->getStorage('user')->create();
|
||||||
'login' => [
|
$registerform = \Drupal::service('entity.form_builder')->getForm($newuser, 'register');
|
||||||
'#markup' => '<h1>' . $this->t('Se connecter') . '</h1>',
|
|
||||||
'form' => $loginform,
|
return [
|
||||||
],
|
'login' => [
|
||||||
'register' => [
|
'#markup' => '<h1>' . $this->t('Se connecter') . '</h1>',
|
||||||
'#markup' => '<h1>' . $this->t('ou créer un nouveau compte') . '</h1>',
|
'form' => $loginform,
|
||||||
'form' => $registerform
|
],
|
||||||
]
|
'register' => [
|
||||||
];
|
'#markup' => '<h1>' . $this->t('ou créer un nouveau compte') . '</h1>',
|
||||||
// return [
|
'form' => $registerform
|
||||||
// '#markup' => $this->t('Hello, World!'),
|
]
|
||||||
// ];
|
];
|
||||||
|
} else {
|
||||||
|
$destination = \Drupal::service('redirect.destination')->getAsArray();
|
||||||
|
$response = new RedirectResponse($destination['destination']);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue