You are here

public function Oauth2ClientPluginList::buildForm in OAuth2 Client 8.3

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/Oauth2ClientPluginList.php, line 42

Class

Oauth2ClientPluginList
Provides a OAuth2 Client form.

Namespace

Drupal\oauth2_client\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $header = [
    [
      'data' => $this
        ->t('Name'),
      'field' => 'name',
      'sort' => 'desc',
    ],
    [
      'data' => $this
        ->t('Grant Type'),
      'field' => 'grant_type',
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ],
    [
      'data' => $this
        ->t('Operations'),
    ],
  ];
  $definitions = $this->pluginManager
    ->getDefinitions();
  $rows = [];
  foreach ($definitions as $definition) {
    $url = Url::fromRoute('oauth2_client.oauth2_client_plugin_config', [
      'plugin' => $definition['id'],
    ]);
    $link = Link::fromTextAndUrl($this
      ->t('Configure'), $url);
    $rows[] = [
      'data' => [
        [
          'data' => $definition['name'],
        ],
        [
          'data' => $definition['grant_type'],
        ],
        [
          'data' => $link
            ->toRenderable() + [
            '#attributes' => [
              'class' => [
                'button',
              ],
            ],
          ],
        ],
      ],
    ];
  }
  $form['oauth2_clients'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No clients available.'),
  ];
  return $form;
}