Skip to content

Commit

Permalink
Add missing ITK changes with userinfo url
Browse files Browse the repository at this point in the history
And adding defaults if configuration has not been done
  • Loading branch information
spaceo committed Oct 6, 2023
1 parent da82eb4 commit 9d56ae4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Class that handles reservations settings.
*/
class DplPatronPageSettings extends DplReactConfigBase {
const PINCODE_LENGTH_MAX = 4;
const PINCODE_LENGTH_MIN = 4;

/**
* Gets the configuration key for reservation settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\dpl_patron_page\DplPatronPageSettings;
use Drupal\dpl_react\DplReactConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -82,15 +83,15 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
$form['settings']['pincode_length_min'] = [
'#type' => 'number',
'#title' => $this->t('Pincode length (min)'),
'#default_value' => $config->get('pincode_length_min') ?? 4,
'#default_value' => $config->get('pincode_length_min') ?? DplPatronPageSettings::PINCODE_LENGTH_MIN,
'#min' => 4,
'#step' => 1,
];

$form['settings']['pincode_length_max'] = [
'#type' => 'number',
'#title' => $this->t('Pincode length max'),
'#default_value' => $config->get('pincode_length_max') ?? 4,
'#default_value' => $config->get('pincode_length_max') ?? DplPatronPageSettings::PINCODE_LENGTH_MAX,
'#min' => 4,
'#step' => 1,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dpl_patron_reg.create:
path: "/user/registration/create"
defaults:
_controller: '\Drupal\dpl_patron_reg\Controller\DplPatronRegController::userRegistrationReactAppLoad'
_title: "Patron create"
requirements:
_permission: "access content"
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
class DplPatronRegSettings extends DplReactConfigBase {

const AGE_LIMIT = '18';
const REDIRECT_ON_USER_CREATED_URL = '';
const INFORMATION_VALUE = '';
const INFORMATION_FORMAT = 'plain_text';

/**
* Gets the configuration key for the instant patron registration settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\dpl_patron_reg\DplPatronRegSettings;
use Drupal\dpl_react\DplReactConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
$form['age_limit'] = [
'#type' => 'number',
'#title' => $this->t('Minimum age to allow self registration'),
'#default_value' => $config->get('age_limit') ?? '18',
'#default_value' => $config->get('age_limit') ?? DplPatronRegSettings::AGE_LIMIT,
'#min' => 1,
'#step' => 1,
];
Expand All @@ -72,14 +73,14 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#type' => 'url',
'#title' => $this->t('Redirect on create'),
'#description' => $this->t('Redirect to this on user successful created'),
'#default_value' => $config->get('redirect_on_user_created_url') ?? '',
'#default_value' => $config->get('redirect_on_user_created_url') ?? DplPatronRegSettings::REDIRECT_ON_USER_CREATED_URL,
];

$form['information'] = [
'#type' => 'text_format',
'#title' => $this->t('Information page'),
'#default_value' => $config->get('information')['value'] ?? '',
'#format' => $config->get('information')['format'] ?? 'plain_text',
'#default_value' => $config->get('information')['value'] ?? DplPatronRegSettings::INFORMATION_VALUE,
'#format' => $config->get('information')['format'] ?? DplPatronRegSettings::INFORMATION_FORMAT,
];

return parent::buildForm($form, $form_state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\dpl_library_agency\BranchSettings;
use Drupal\dpl_library_agency\Branch\Branch;
use Drupal\dpl_library_agency\Branch\BranchRepositoryInterface;
use Drupal\dpl_library_agency\ReservationSettings;
use Drupal\dpl_login\UserTokensProvider;
use Drupal\dpl_patron_page\DplPatronPageSettings;
use Drupal\dpl_react\DplReactConfigInterface;
use Drupal\dpl_react_apps\Controller\DplReactAppsController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\dpl_library_agency\Branch\BranchRepositoryInterface;
use Drupal\dpl_library_agency\BranchSettings;
use function Safe\json_encode as json_encode;

/**
* Provides user registration block.
Expand Down Expand Up @@ -39,6 +43,10 @@ class PatronRegistrationBlock extends BlockBase implements ContainerFactoryPlugi
* The branch-settings for branch config.
* @param \Drupal\dpl_library_agency\Branch\BranchRepositoryInterface $branchRepository
* The branch-settings for getting branches.
* @param \Drupal\dpl_library_agency\ReservationSettings $reservationSettings
* Reservation settings.
* @param \Drupal\dpl_react\DplReactConfigInterface $patronPageSettings
* Patron page settings.
* @param \Drupal\dpl_react\DplReactConfigInterface $patronRegSettings
* Patron registration settings.
*/
Expand All @@ -50,6 +58,8 @@ public function __construct(
private ConfigFactoryInterface $configFactory,
private BranchSettings $branchSettings,
private BranchRepositoryInterface $branchRepository,
protected ReservationSettings $reservationSettings,
private DplReactConfigInterface $patronPageSettings,
private DplReactConfigInterface $patronRegSettings
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
Expand All @@ -68,7 +78,9 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('config.factory'),
$container->get('dpl_library_agency.branch_settings'),
$container->get('dpl_library_agency.branch.repository'),
\Drupal::service('dpl_patron_reg.settings')
$container->get('dpl_library_agency.reservation_settings'),
\Drupal::service('dpl_patron_page.settings'),
\Drupal::service('dpl_patron_reg.settings'),
);
}

Expand All @@ -95,32 +107,36 @@ protected function buildBranchesListProp(array $branchIds) : string {
public function build(): array {
$config = $this->patronRegSettings->loadConfig();
$userToken = $this->user_token_provider->getAccessToken()?->token;
$patron_page_settings = $this->patronPageSettings->loadConfig();

// @todo change to use patron_page settings inject, if approved in other PR.
$patron_page_settings = $this->configFactory->get('patron_page.settings');
// Get user info endpoint from OpenIdConnect configuration.
$configuration = $this->configFactory->get('openid_connect.settings.adgangsplatformen');
$userInfoEndpoint = $configuration->get('settings')['userinfo_endpoint'];

$data = [
// Configuration.
'blacklisted-pickup-branches-config' => $this->buildBranchesListProp($this->branchSettings->getExcludedReservationBranches()),
'branches-config' => DplReactAppsController::buildBranchesJsonProp($this->branchRepository->getBranches()),
'min-age-config' => $config->get('age_limit') ?? '18',
'pincode-length-max-config' => $patron_page_settings->get('pincode_length_max'),
'pincode-length-min-config' => $patron_page_settings->get('pincode_length_min'),
'redirect-on-user-created-url' => $config->get('redirect_on_user_created_url'),
'pincode-length-max-config' => $patron_page_settings->get('pincode_length_max') ?? DplPatronPageSettings::PINCODE_LENGTH_MAX,
'pincode-length-min-config' => $patron_page_settings->get('pincode_length_min') ?? DplPatronPageSettings::PINCODE_LENGTH_MIN,
'redirect-on-user-created-url' => $config->get('redirect_on_user_created_url') ?? DplPatronPageSettings::REDIRECT_ON_USER_CREATED_URL,
'user-token' => $userToken,
'userinfo-url' => $userInfoEndpoint,
'text-notifications-enabled-config' => (int) $this->reservationSettings->smsNotificationsIsEnabled(),

// Texts.
'create-patron-cancel-button-text' => $this->t("Cancel", [], ['context' => 'Create patron']),
'create-patron-change-pickup-body-text' => $this->t("create patron change pickup body text", [], ['context' => 'Create patron']),
'create-patron-change-pickup-header-text' => $this->t("create patron change pickup header text", [], ['context' => 'Create patron']),
'create-patron-change-pickup-body-text' => $this->t("Select pickup location in the select", [], ['context' => 'Create patron']),
'create-patron-change-pickup-header-text' => $this->t("Select pickup location", [], ['context' => 'Create patron']),
'create-patron-confirm-button-text' => $this->t("Confirm", [], ['context' => 'Create patron']),
'create-patron-header-text' => $this->t("Register as patron", [], ['context' => 'Create patron']),
'create-patron-invalid-ssn-body-text' => $this->t("This SSN is invalid", [], ['context' => 'Create patron']),
'create-patron-invalid-ssn-header-text' => $this->t("Invalid SSN", [], ['context' => 'Create patron']),
'patron-contact-email-checkbox-text' => $this->t("Receive emails about your loans, reservations, and so forth", [], ['context' => 'Create patron']),
'patron-contact-email-label-text' => $this->t("E-mail", [], ['context' => 'Create patron']),
'patron-contact-info-body-text' => $this->t("contact info body text", [], ['context' => 'Create patron']),
'patron-contact-info-header-text' => $this->t("contact info header text", [], ['context' => 'Create patron']),
'patron-contact-info-body-text' => $this->t("This section is for contact information", [], ['context' => 'Create patron']),
'patron-contact-info-header-text' => $this->t("Contact information", [], ['context' => 'Create patron']),
'patron-contact-name-label-text' => $this->t("Name", [], ['context' => 'Create patron']),
'patron-contact-phone-checkbox-text' => $this->t("Receive text messages about your loans, reservations, and so forth", [], ['context' => 'Create patron']),
'patron-contact-phone-label-text' => $this->t("Phone number", [], ['context' => 'Create patron']),
Expand Down

0 comments on commit 9d56ae4

Please sign in to comment.