Skip to content
Snippets Groups Projects
Commit a063d8be authored by Tolga Özses's avatar Tolga Özses
Browse files

Issue #3335528 by samit.310@gmail.com: Render #pre_render callbacks must be...

Issue #3335528 by samit.310@gmail.com: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function
parent ebebb1e3
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\forgot_username\ForgotUsernamePreRender;
/**
* Implements hook_help().
......@@ -98,7 +99,7 @@ function forgot_username_user_accountsettings_form_submit(array $form, FormState
* Implements hook_block_view_BASE_ID_alter().
*/
function forgot_username_block_view_user_login_block_alter(array &$build, BlockPluginInterface $block) {
$build['#pre_render'][] = '_forgot_username_user_login_block_prerender';
$build['#pre_render'][] = [ForgotUsernamePreRender::class, 'forgotUsernameUserLoginBlockPreRender'];
}
/**
......
<?php
namespace Drupal\forgot_username;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Url;
/**
* The PreRender class ForgotUsernamePreRender.
*/
class ForgotUsernamePreRender implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['forgotUsernameUserLoginBlockPreRender'];
}
/**
* Determines the forgot username link.
*
* @return array
* The forgot username link.
*/
public static function forgotUsernameUserLoginBlockPreRender(array $build): array {
$build['content']['forgot_username'] = [
'#type' => 'link',
'#title' => t('Forgot username'),
'#url' => Url::fromRoute('forgot_username.username', [], [
'attributes' => [
'title' => t('Forgot username'),
'class' => ['forgot-username-link'],
],
]),
];
return $build;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment