You are here

UserStatus.php in Open Social 10.0.x

File

modules/social_features/social_user/src/Plugin/GraphQL/DataProducer/UserStatus.php
View source
<?php

namespace Drupal\social_user\Plugin\GraphQL\DataProducer;

use Drupal\graphql\Plugin\DataProducerPluginCachingInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\user\UserInterface;

/**
 * Returns the status for a user.
 *
 * @DataProducer(
 *   id = "user_status",
 *   name = @Translation("User status"),
 *   description = @Translation("Returns the status of the user."),
 *   produces = @ContextDefinition("string",
 *     label = @Translation("User status")
 *   ),
 *   consumes = {
 *     "user" = @ContextDefinition("entity:user",
 *       label = @Translation("User")
 *     )
 *   }
 * )
 */
class UserStatus extends DataProducerPluginBase implements DataProducerPluginCachingInterface {

  /**
   * Resolves the value for this data producer.
   *
   * @param \Drupal\user\UserInterface $user
   *   The user to get the status from.
   *
   * @return string
   *   The status of the user ("ACTIVE" or "BLOCKED").
   */
  public function resolve(UserInterface $user) {
    return $user
      ->isActive() ? "ACTIVE" : "BLOCKED";
  }

}

Classes

Namesort descending Description
UserStatus Returns the status for a user.