Email.php in JS Callback Handler 8.3
File
js_callback_examples/src/Plugin/Js/Email.php
View source
<?php
namespace Drupal\js_callback_examples\Plugin\Js;
use Drupal\js\Plugin\Js\JsCallbackBase;
use Drupal\user\UserInterface;
class Email extends JsCallbackBase {
public function validate(UserInterface $user = NULL) {
if (!$user || !$user
->isActive()) {
drupal_set_message(t('You must enter a valid user.'), 'error');
return FALSE;
}
return TRUE;
}
public function execute(UserInterface $user = NULL) {
return [
'#markup' => $user
->getEmail(),
'#attached' => [
'drupalSettings' => [
'testing' => 'test',
],
],
];
}
}
Classes
Name |
Description |
Email |
Plugin annotation
@JsCallback(
id = "js_callback_examples.email",
parameters = {
"user" = {
"type" = "entity:user"
},
},
) |