You are here

public function OAuthController::consumers in OAuth 1.0 8.2

Same name and namespace in other branches
  1. 8 src/Controller/OAuthController.php \Drupal\oauth\Controller\OAuthController::consumers()

Returns the list of consumers for a user.

Parameters

\Drupal\user\UserInterface $user: A user account object.

Return value

string A HTML-formatted string with the list of OAuth consumers.

1 string reference to 'OAuthController::consumers'
oauth.routing.yml in ./oauth.routing.yml
oauth.routing.yml

File

src/Controller/OAuthController.php, line 73
Contains \Drupal\oauth\Controller\OAuthController.

Class

OAuthController
Controller routines for oauth routes.

Namespace

Drupal\oauth\Controller

Code

public function consumers(UserInterface $user) {
  $list = array();
  $list['#cache']['tags'] = array(
    'oauth:' => $user
      ->id(),
  );
  $list['heading']['#markup'] = $this->linkGenerator
    ->generate($this
    ->t('Add consumer'), Url::fromRoute('oauth.user_consumer_add', array(
    'user' => $user
      ->id(),
  )));

  // Get the list of consumers.
  $result = $this->user_data
    ->get('oauth', $user
    ->id());

  // Define table headers.
  $list['table'] = array(
    '#theme' => 'table',
    '#header' => array(
      'consumer_key' => array(
        'data' => $this
          ->t('Consumer key'),
      ),
      'consumer_secret' => array(
        'data' => $this
          ->t('Consumer secret'),
      ),
      'operations' => array(
        'data' => $this
          ->t('Operations'),
      ),
    ),
    '#rows' => array(),
  );

  // Add existing consumers to the table.
  foreach ($result as $key => $consumer) {
    $list['table']['#rows'][] = array(
      'data' => array(
        'consumer_key' => $key,
        'consumer_secret' => $consumer['consumer_secret'],
        'operations' => array(
          'data' => array(
            '#type' => 'operations',
            '#links' => array(
              'delete' => array(
                'title' => $this
                  ->t('Delete'),
                'url' => Url::fromRoute('oauth.user_consumer_delete', array(
                  'user' => $user
                    ->id(),
                  'key' => $key,
                )),
              ),
            ),
          ),
        ),
      ),
    );
  }
  $list['table']['#empty'] = $this
    ->t('There are no OAuth consumers.');
  return $list;
}