This commit is contained in:
2024-03-25 15:59:38 +01:00
parent 432bf3c253
commit 9e171e69a6
83 changed files with 3355 additions and 37 deletions

View File

@@ -0,0 +1,6 @@
name: Login and register block
description: Creates a block showing both login and register.
package: Custom
type: module
core_version_requirement: ^9.4 || ^10

View File

@@ -0,0 +1,43 @@
<?php
namespace Drupal\loginregisterblock\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'login register' Block.
*
* @Block(
* id = "login_register_block",
* admin_label = @Translation("Login register block"),
* category = @Translation("Loginregister"),
* )
*/
class LoginRegisterBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$loginform = \Drupal::formBuilder()->getForm('Drupal\user\Form\UserLoginForm');
$newuser = \Drupal::entityTypeManager()->getStorage('user')->create();
$registerform = \Drupal::service('entity.form_builder')->getForm($newuser, 'register');
return [
'login' => [
'#markup' => '<h1>' . $this->t('Se connecter') . '</h1>',
'form' => $loginform,
],
'register' => [
'#markup' => '<h1>' . $this->t('ou créer un nouveau compte') . '</h1>',
'form' => $registerform
]
];
// return [
// '#markup' => $this->t('Hello, World!'),
// ];
}
}