class UserNewBlock

Provides a "Who's new" block.

Plugin annotation


@Plugin(
  id = "user_new_block",
  admin_label = @Translation("Who's new"),
  module = "user"
)

Hierarchy

Expanded class hierarchy of UserNewBlock

File

drupal/core/modules/user/lib/Drupal/user/Plugin/Block/UserNewBlock.php, line 23
Contains \Drupal\user\Plugin\Block\UserNewBlock.

Namespace

Drupal\user\Plugin\Block
View source
class UserNewBlock extends BlockBase {

  /**
   * Overrides \Drupal\block\BlockBase::settings().
   */
  public function settings() {
    return array(
      'properties' => array(
        'administrative' => TRUE,
      ),
      'whois_new_count' => 5,
    );
  }

  /**
   * Overrides \Drupal\block\BlockBase::access().
   */
  public function access() {
    return user_access('access content');
  }

  /**
   * Overrides \Drupal\block\BlockBase::blockForm().
   */
  public function blockForm($form, &$form_state) {
    $form['user_block_whois_new_count'] = array(
      '#type' => 'select',
      '#title' => t('Number of users to display'),
      '#default_value' => $this->configuration['whois_new_count'],
      '#options' => drupal_map_assoc(array(
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
      )),
    );
    return $form;
  }

  /**
   * Overrides \Drupal\block\BlockBase::blockSubmit().
   */
  public function blockSubmit($form, &$form_state) {
    $this->configuration['whois_new_count'] = $form_state['values']['user_block_whois_new_count'];
  }

  /**
   * {@inheritdoc}
   */
  public function build() {

    // Retrieve a list of new users who have accessed the site successfully.
    $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])
      ->fetchAll();
    $build = array(
      '#theme' => 'item_list__user__new',
      '#items' => array(),
    );
    foreach ($items as $account) {
      $build['#items'][] = theme('username', array(
        'account' => $account,
      ));
    }
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockBase::blockValidate public function Adds block type-specific validation for the block form.
BlockBase::form public function Implements \Drupal\block\BlockPluginInterface::form(). Overrides BlockPluginInterface::form 1
BlockBase::getConfig public function Returns the configuration data for the block plugin.
BlockBase::setConfig public function Sets a particular value in the block settings.
BlockBase::submit public function Implements \Drupal\block\BlockPluginInterface::submit(). Overrides BlockPluginInterface::submit
BlockBase::validate public function Implements \Drupal\block\BlockPluginInterface::validate(). Overrides BlockPluginInterface::validate
BlockBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
UserNewBlock::access public function Overrides \Drupal\block\BlockBase::access(). Overrides BlockBase::access
UserNewBlock::blockForm public function Overrides \Drupal\block\BlockBase::blockForm(). Overrides BlockBase::blockForm
UserNewBlock::blockSubmit public function Overrides \Drupal\block\BlockBase::blockSubmit(). Overrides BlockBase::blockSubmit
UserNewBlock::build public function Builds and returns the renderable array for this block plugin. Overrides BlockPluginInterface::build
UserNewBlock::settings public function Overrides \Drupal\block\BlockBase::settings(). Overrides BlockBase::settings