Oauth2ClientForm.php in Simple OAuth (OAuth2) & OpenID Connect 8.2
File
src/Entity/Form/Oauth2ClientForm.php
View source
<?php
namespace Drupal\simple_oauth\Entity\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\Language;
use Drupal\user\RoleInterface;
class Oauth2ClientForm extends ContentEntityForm {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['langcode'] = array(
'#title' => $this
->t('Language'),
'#type' => 'language_select',
'#default_value' => $entity
->getUntranslated()
->language()
->getId(),
'#languages' => Language::STATE_ALL,
);
unset($form['roles']['widget']['#options'][RoleInterface::ANONYMOUS_ID]);
unset($form['roles']['widget']['#options'][RoleInterface::AUTHENTICATED_ID]);
$description = $this
->t('Use this field to create a hash of the secret key. This module will never store your client key, only a hash of it. Current hash: "%hash".', [
'%hash' => $entity
->getSecret(),
]);
$form['new_secret'] = [
'#type' => 'password',
'#title' => $this
->t('New Secret'),
'#description' => $description,
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
if ($new_secret = $form_state
->getValue('new_secret')) {
$this
->getEntity()
->setSecret($new_secret);
}
}
public function save(array $form, FormStateInterface $form_state) {
$status = $this->entity
->save();
$label = $this->entity
->label();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this
->t('Created the %label Client.', [
'%label' => $label,
]));
break;
default:
drupal_set_message($this
->t('Saved the %label Client.', [
'%label' => $label,
]));
}
$form_state
->setRedirect('entity.oauth2_client.collection');
}
}