You are here

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;

/**
 * @JsCallback(
 *   id = "js_callback_examples.email",
 *   parameters = {
 *     "user" = {
 *       "type" = "entity:user"
 *     },
 *   },
 * )
 */
class Email extends JsCallbackBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function execute(UserInterface $user = NULL) {
    return [
      '#markup' => $user
        ->getEmail(),
      '#attached' => [
        'drupalSettings' => [
          'testing' => 'test',
        ],
      ],
    ];
  }

}

Classes

Namesort descending Description
Email Plugin annotation @JsCallback( id = "js_callback_examples.email", parameters = { "user" = { "type" = "entity:user" }, }, )