From 4e633d84793572b6ce20f68a052721959d9f1897 Mon Sep 17 00:00:00 2001 From: Artem Antonov <artem@antonov.es> Date: Wed, 2 May 2018 19:43:56 +0200 Subject: [PATCH 1/6] CERN-483 fix error on login trustedresponse --- .../CernProfileDisplaynameOutboundPathProcessor.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php index 6181a6e..7375450 100644 --- a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php +++ b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php @@ -4,6 +4,7 @@ namespace Drupal\cern_profile_displayname\PathProcessor; use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\user\Entity\User; use Symfony\Component\HttpFoundation\Request; @@ -39,6 +40,15 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess $new_options = $this->getUserProfileLinkOptions($account); } if (isset($new_options)) { + if (in_array($request->getPathInfo(), ['/user', '/user/login'])){ + // Save the session so things like messages get saved. + $request->getSession()->save(); + $response = new TrustedRedirectResponse($new_options['base_url'].'?'.http_build_query($new_options['query'])); + $response->prepare($request); + // Make sure to trigger kernel events. + \Drupal::service('kernel')->terminate($request, $response); + $response->send(); + } $options = array_merge($options, $new_options); $path = ''; } -- GitLab From 3d79b03f89852cba0e375bb4cf55dfe088ffcf43 Mon Sep 17 00:00:00 2001 From: Eduardo <eduardoa@cern.ch> Date: Tue, 8 May 2018 16:09:03 +0200 Subject: [PATCH 2/6] Set cache per user on the block --- .../src/Plugin/Block/CernProfileDisplaynameBlock.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php index 3d918d8..b5c42a9 100644 --- a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php +++ b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php @@ -25,6 +25,11 @@ class CernProfileDisplaynameBlock extends BlockBase { $build = []; $build['cern_profile_displayname_block']['#markup'] = $this->getBlockContent(); + //Not cache the results since each user will have it's own link + #$build['#cache']['max-age'] = 0; + $build['#cache']['contexts'] = array('user'); + + return $build; } -- GitLab From 3d92f22ed9ec57537510559170f807693a799a47 Mon Sep 17 00:00:00 2001 From: Eduardo <eduardoa@cern.ch> Date: Tue, 8 May 2018 16:13:09 +0200 Subject: [PATCH 3/6] Change profiles sites to point to phonebook.cern.ch as more reliable source --- .../cern_profile_displayname.default_settings.inc | 2 +- .../CernProfileDisplaynameOutboundPathProcessor.php | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cern_profile_displayname/cern_profile_displayname.default_settings.inc b/cern_profile_displayname/cern_profile_displayname.default_settings.inc index e5878ca..f0184b2 100644 --- a/cern_profile_displayname/cern_profile_displayname.default_settings.inc +++ b/cern_profile_displayname/cern_profile_displayname.default_settings.inc @@ -8,7 +8,7 @@ define('DEFAULT_SHOW_ACCOUNT_NAME', FALSE); define('DEFAULT_ENABLE_REDIRECT', TRUE); -define('DEFAULT_PROFILES_SITE', 'http://profiles.web.cern.ch/'); +define('DEFAULT_PROFILES_SITE', 'https://phonebook.cern.ch/phonebook/#personDetails/?id='); define('DEFAULT_UNVERIFIED_ACCOUNT_PATH', 'unverified_account'); define('DEFAULT_REDIRECT_EDIT', TRUE); diff --git a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php index 7375450..cc245a0 100644 --- a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php +++ b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php @@ -65,13 +65,16 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess */ protected function getUserProfileLinkOptions(User $account) { $options = []; - $options['query'] = ['accountname' => "CERN\\" . $account->getAccountName()]; - $options['base_url'] = 'https://social.cern.ch/Person.aspx'; - if (\Drupal::currentUser()->isAuthenticated()) { - // For authenticated users go to social.cern.ch. - $options['query']['auth'] = 1; + $ccid = ""; + if (isset($account->field_person_id_ccid->value)) { + if ($account->field_person_id_ccid->value != '-1') { + $ccid = $account->field_person_id_ccid->value; + } } + $options['query'] = ['id' => $ccid]; + $options['base_url'] = 'https://phonebook.cern.ch/phonebook/#personDetails/'; + return $options; } -- GitLab From 57199b8af4f8f4bf619f6d220b2877bd62593cf3 Mon Sep 17 00:00:00 2001 From: Eduardo <eduardoa@cern.ch> Date: Tue, 8 May 2018 17:48:36 +0200 Subject: [PATCH 4/6] Update config form to remove unnecessary options and update the helper text. Added version --- .../cern_profile_displayname.info.yml | 1 + .../CernProfileDisplaynameSettingsForm.php | 57 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/cern_profile_displayname/cern_profile_displayname.info.yml b/cern_profile_displayname/cern_profile_displayname.info.yml index 979634e..ff73dac 100644 --- a/cern_profile_displayname/cern_profile_displayname.info.yml +++ b/cern_profile_displayname/cern_profile_displayname.info.yml @@ -9,3 +9,4 @@ dependencies: - user - simplesamlphp_auth configure: cern_profile_displayname.settings +version: 1.0 diff --git a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php index 699c788..5791956 100644 --- a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php +++ b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php @@ -42,7 +42,7 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { $form['Displayname_configurations']['show_account_name'] = array( '#type' => 'checkbox', '#title' => t('Show account name (useful to recognize secondary accounts or services)'), - '#description' => t('If option is disabled: <em>Silvia Tomanin</em> <br>If option is enabled: <em>Silvia Tomanin (stomanin)</em>'), + '#description' => t('If option is disabled: <em>Firstname Lastname</em> <br>If option is enabled: <em>Firstname Lastname (account_name)</em>'), '#default_value' => _cern_profile_displayname_get_default_value($config->get('show_account_name'), DEFAULT_SHOW_ACCOUNT_NAME), ); @@ -51,35 +51,35 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { $form['redirect']['enable_redirect'] = array( '#type' => 'checkbox', '#title' => t('Rewrite URLs'), - '#description' => t('CERN users\' profiles are stored at the Profiles site: select this option to enable URL rewriting to point to the Profiles site instead of the local user profile. <br> NB: The path /user/<uid> and all his subdirectories (ie. /user/<uid>/edit, /user/<uid>/devel) will be redirected.'), + '#description' => t('Site\'s users profiles can be redirected to an external central profiles page. Select this option to enable URL rewriting to point to the defined site, currently <a href="https://phonebook.cern.ch">CERN Phonebook</a> personDetails page instead of the local user profile. <br> NB: The path /user/<uid> and all his subdirectories (ie. /user/<uid>/edit, /user/<uid>/devel) will be redirected.'), '#default_value' => _cern_profile_displayname_get_default_value($config->get('enable_redirect'), DEFAULT_ENABLE_REDIRECT), ); - $form['redirect']['profiles_site'] = array( - '#type' => 'textfield', - '#title' => t('Path to the default CERN Profiles site'), - '#description' => t('Edit this path to point to this site clicking on the name for a user. NB! Trailing slash at the end of the URL needed.'), - '#default_value' => _cern_profile_displayname_get_default_value($config->get('profiles_site'), DEFAULT_PROFILES_SITE), - '#required' => TRUE, - ); - - $form['redirect']['enable_redirect_pages'] = array( - '#type' => 'checkboxes', - '#title' => t('Uncheck the user/subdirectory you DON\'T want to be redirected to the Profiles site'), - '#description' => t('For example, if you uncheck <em>Edit</em> the subdirectory <em>/user/<uid>/edit</em> won\'t be redirected to the profile for that user at the Profiles site.<br>This could be useful for development purposes.'), - '#options' => array( - 'edit' => t('Edit'), - 'devel' => t('Devel'), - 'contact' => t('Contact'), - ), - '#default_value' => _cern_profile_displayname_get_default_value($config->get('enable_redirect_pages'), [DEFAULT_REDIRECT_EDIT, DEFAULT_REDIRECT_DEVEL, DEFAULT_REDIRECT_CONTACT]), - '#states' => array( - // Only make visible these checkboxes when the url rewrite option is enabled. - 'visible' => array( - ':input[name="enable_redirect"]' => array('checked' => TRUE), - ), - ), - ); + #$form['redirect']['profiles_site'] = array( + # '#type' => 'textfield', + # '#title' => t('Path to the default CERN Profiles site'), + # '#description' => t('Edit this path to point to this site clicking on the name for a user. NB! Trailing slash at the end of the URL needed.'), + # '#default_value' => _cern_profile_displayname_get_default_value($config->get('profiles_site'), DEFAULT_PROFILES_SITE), + # '#required' => TRUE, + #); + + #$form['redirect']['enable_redirect_pages'] = array( + # '#type' => 'checkboxes', + # '#title' => t('Uncheck the user/subdirectory you DON\'T want to be redirected to the Profiles site'), + # '#description' => t('For example, if you uncheck <em>Edit</em> the subdirectory <em>/user/<uid>/edit</em> won\'t be redirected to the profile for that user at the Profiles site.<br>This could be useful for development purposes.'), + # '#options' => array( + # 'edit' => t('Edit'), + # 'devel' => t('Devel'), + # 'contact' => t('Contact'), + # ), + # '#default_value' => _cern_profile_displayname_get_default_value($config->get('enable_redirect_pages'), [DEFAULT_REDIRECT_EDIT, DEFAULT_REDIRECT_DEVEL, DEFAULT_REDIRECT_CONTACT]), + # '#states' => array( + # // Only make visible these checkboxes when the url rewrite option is enabled. + # 'visible' => array( + # ':input[name="enable_redirect"]' => array('checked' => TRUE), + # ), + # ), + #); return parent::buildForm($form, $form_state); } @@ -105,9 +105,6 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { if (!UrlHelper::isValid($value, TRUE)) { $form_state->setErrorByName('cern_profile_displayname_profiles_site', t('The redirect path %value is not valid. The path must be absolute.', array('%value' => $value))); } - if (!($value[strlen($value) - 1] == '/')) { - $form_state->setErrorByName('cern_profile_displayname_profiles_site', t('Trailing slash at the end of the path needed.')); - } } } -- GitLab From b567b8a667202421f43a2553dd72cbe8affed5b5 Mon Sep 17 00:00:00 2001 From: Eduardo <eduardoa@cern.ch> Date: Tue, 8 May 2018 21:22:16 +0200 Subject: [PATCH 5/6] Cleanup of unused config variables --- .../src/Form/CernProfileDisplaynameSettingsForm.php | 12 ++++++------ .../CernProfileDisplaynameOutboundPathProcessor.php | 4 ++-- .../src/Plugin/Block/CernProfileDisplaynameBlock.php | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php index 5791956..673eca7 100644 --- a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php +++ b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php @@ -92,8 +92,8 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { $values = $form_state->getValues(); $config->set('show_account_name', $values['show_account_name']); $config->set('enable_redirect', $values['enable_redirect']); - $config->set('profiles_site', $values['profiles_site']); - $config->set('enable_redirect_pages', $values['enable_redirect_pages']); + #$config->set('profiles_site', $values['profiles_site']); + #$config->set('enable_redirect_pages', $values['enable_redirect_pages']); $config->save(); } @@ -101,10 +101,10 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $value = $form_state->getValue('profiles_site'); - if (!UrlHelper::isValid($value, TRUE)) { - $form_state->setErrorByName('cern_profile_displayname_profiles_site', t('The redirect path %value is not valid. The path must be absolute.', array('%value' => $value))); - } + #$value = $form_state->getValue('profiles_site'); + #if (!UrlHelper::isValid($value, TRUE)) { + # $form_state->setErrorByName('cern_profile_displayname_profiles_site', t('The redirect path %value is not valid. The path must be absolute.', array('%value' => $value))); + #} } } diff --git a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php index cc245a0..2418b85 100644 --- a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php +++ b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php @@ -21,11 +21,11 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess $enable_redirect = _cern_profile_displayname_get_default_value($config->get('enable_redirect'), DEFAULT_ENABLE_REDIRECT); if ($enable_redirect) { if (preg_match('@user[/\+%]+([0-9]+)(.*)?@', $path, $matches)) { - $opt_enable_redirect_pages = _cern_profile_displayname_get_default_value($config->get('enable_redirect_pages'), [ + $opt_enable_redirect_pages = [ 'edit' => DEFAULT_REDIRECT_EDIT, 'devel' => DEFAULT_REDIRECT_DEVEL, 'contact' => DEFAULT_REDIRECT_CONTACT, - ]); + ]; if (!$opt_enable_redirect_pages['edit'] && $matches[2] == '/edit' || !$opt_enable_redirect_pages['devel'] && $matches[2] == '/devel' diff --git a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php index b5c42a9..0d351db 100644 --- a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php +++ b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php @@ -29,7 +29,6 @@ class CernProfileDisplaynameBlock extends BlockBase { #$build['#cache']['max-age'] = 0; $build['#cache']['contexts'] = array('user'); - return $build; } @@ -69,7 +68,7 @@ class CernProfileDisplaynameBlock extends BlockBase { if (isset($account->field_person_id_ccid->value)) { if ($account->field_person_id_ccid->value != '-1') { $config = \Drupal::config('cern_profile_displayname.settings'); - $path_profiles_site = _cern_profile_displayname_get_default_value($config->get('profiles_site'), DEFAULT_PROFILES_SITE); + $path_profiles_site = DEFAULT_PROFILES_SITE; $path_profiles_site = _cern_profile_displayname_get_profiles_site_url($path_profiles_site); // Return the cern real name linking to the profile site. return Link::fromTextAndUrl($account->getDisplayName(), URL::fromUri($path_profiles_site . $account->field_person_id_ccid->value))->toString(); -- GitLab From f76ef209b1e8d3d3ba2276c84a7c32a4997d46ce Mon Sep 17 00:00:00 2001 From: Eduardo <eduardoa@cern.ch> Date: Wed, 9 May 2018 10:30:03 +0200 Subject: [PATCH 6/6] Consolidate usage of config variables, remove DEFINES and implement update function for existing sites --- ...n_profile_displayname.default_settings.inc | 16 ---------- .../cern_profile_displayname.install | 16 ++++++++++ .../cern_profile_displayname.module | 3 +- .../install/cern_profile_displayname.settings | 7 +++++ .../CernProfileDisplaynameSettingsForm.php | 30 ++----------------- ...rofileDisplaynameOutboundPathProcessor.php | 17 ++++++----- .../Block/CernProfileDisplaynameBlock.php | 6 ++-- 7 files changed, 38 insertions(+), 57 deletions(-) delete mode 100644 cern_profile_displayname/cern_profile_displayname.default_settings.inc create mode 100644 cern_profile_displayname/config/install/cern_profile_displayname.settings diff --git a/cern_profile_displayname/cern_profile_displayname.default_settings.inc b/cern_profile_displayname/cern_profile_displayname.default_settings.inc deleted file mode 100644 index f0184b2..0000000 --- a/cern_profile_displayname/cern_profile_displayname.default_settings.inc +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -/** - * @file - * @file: Set default values for configuration variables. - */ - -define('DEFAULT_SHOW_ACCOUNT_NAME', FALSE); - -define('DEFAULT_ENABLE_REDIRECT', TRUE); -define('DEFAULT_PROFILES_SITE', 'https://phonebook.cern.ch/phonebook/#personDetails/?id='); -define('DEFAULT_UNVERIFIED_ACCOUNT_PATH', 'unverified_account'); - -define('DEFAULT_REDIRECT_EDIT', TRUE); -define('DEFAULT_REDIRECT_CONTACT', TRUE); -define('DEFAULT_REDIRECT_DEVEL', TRUE); diff --git a/cern_profile_displayname/cern_profile_displayname.install b/cern_profile_displayname/cern_profile_displayname.install index 172ad00..cfd0692 100644 --- a/cern_profile_displayname/cern_profile_displayname.install +++ b/cern_profile_displayname/cern_profile_displayname.install @@ -47,3 +47,19 @@ function cern_profile_displayname_uninstall() { user_role_revoke_permissions(AccountInterface::ANONYMOUS_ROLE, ['access user profiles']); user_role_revoke_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']); } + + +/** + * Add previously DEFINE constants as config default variables. + */ +function cern_profile_displayname_update_8001() { + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('cern_profile_displayname.settings'); + $config->set('show_account_name', false); + $config->set('enable_redirect', true); + $config->set('profiles_site', 'https://phonebook.cern.ch/phonebook/#personDetails/'); + $config->set('enable_redirect_pages.edit', true); + $config->set('enable_redirect_pages.contact', true); + $config->set('enable_redirect_pages.devel', true); + $config->save(TRUE); +} diff --git a/cern_profile_displayname/cern_profile_displayname.module b/cern_profile_displayname/cern_profile_displayname.module index 95306a7..cf76e0c 100644 --- a/cern_profile_displayname/cern_profile_displayname.module +++ b/cern_profile_displayname/cern_profile_displayname.module @@ -5,7 +5,6 @@ * Contains cern_profile_displayname.module. */ -module_load_include('inc', 'cern_profile_displayname', 'cern_profile_displayname.default_settings'); use Drupal\Core\Routing\RouteMatchInterface; @@ -49,7 +48,7 @@ function cern_profile_displayname_user_format_name_alter(&$name, $account) { $member = \Drupal\user\Entity\User::load($account->id()); if (!empty($member->field_realname->value)) { $config = \Drupal::config('cern_profile_displayname.settings'); - $shownameacc = _cern_profile_displayname_get_default_value($config->get('show_account_name'), DEFAULT_SHOW_ACCOUNT_NAME); + $shownameacc = $config->get('show_account_name'); $realname = $member->field_realname->value; if (!$shownameacc) { $name = t('@realname', ['@realname' => $realname]); diff --git a/cern_profile_displayname/config/install/cern_profile_displayname.settings b/cern_profile_displayname/config/install/cern_profile_displayname.settings new file mode 100644 index 0000000..285b71a --- /dev/null +++ b/cern_profile_displayname/config/install/cern_profile_displayname.settings @@ -0,0 +1,7 @@ +show_account_name: false +enable_redirect: true +profiles_site: 'https://phonebook.cern.ch/phonebook/#personDetails/' +enable_redirect_pages: + edit: true + contact: true + devel: true diff --git a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php index 673eca7..eaa9375 100644 --- a/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php +++ b/cern_profile_displayname/src/Form/CernProfileDisplaynameSettingsForm.php @@ -43,7 +43,7 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { '#type' => 'checkbox', '#title' => t('Show account name (useful to recognize secondary accounts or services)'), '#description' => t('If option is disabled: <em>Firstname Lastname</em> <br>If option is enabled: <em>Firstname Lastname (account_name)</em>'), - '#default_value' => _cern_profile_displayname_get_default_value($config->get('show_account_name'), DEFAULT_SHOW_ACCOUNT_NAME), + '#default_value' => $config->get('show_account_name'), ); // Redirect to Profiles site configuration. @@ -52,35 +52,9 @@ class CernProfileDisplaynameSettingsForm extends ConfigFormBase { '#type' => 'checkbox', '#title' => t('Rewrite URLs'), '#description' => t('Site\'s users profiles can be redirected to an external central profiles page. Select this option to enable URL rewriting to point to the defined site, currently <a href="https://phonebook.cern.ch">CERN Phonebook</a> personDetails page instead of the local user profile. <br> NB: The path /user/<uid> and all his subdirectories (ie. /user/<uid>/edit, /user/<uid>/devel) will be redirected.'), - '#default_value' => _cern_profile_displayname_get_default_value($config->get('enable_redirect'), DEFAULT_ENABLE_REDIRECT), + '#default_value' => $config->get('enable_redirect'), ); - #$form['redirect']['profiles_site'] = array( - # '#type' => 'textfield', - # '#title' => t('Path to the default CERN Profiles site'), - # '#description' => t('Edit this path to point to this site clicking on the name for a user. NB! Trailing slash at the end of the URL needed.'), - # '#default_value' => _cern_profile_displayname_get_default_value($config->get('profiles_site'), DEFAULT_PROFILES_SITE), - # '#required' => TRUE, - #); - - #$form['redirect']['enable_redirect_pages'] = array( - # '#type' => 'checkboxes', - # '#title' => t('Uncheck the user/subdirectory you DON\'T want to be redirected to the Profiles site'), - # '#description' => t('For example, if you uncheck <em>Edit</em> the subdirectory <em>/user/<uid>/edit</em> won\'t be redirected to the profile for that user at the Profiles site.<br>This could be useful for development purposes.'), - # '#options' => array( - # 'edit' => t('Edit'), - # 'devel' => t('Devel'), - # 'contact' => t('Contact'), - # ), - # '#default_value' => _cern_profile_displayname_get_default_value($config->get('enable_redirect_pages'), [DEFAULT_REDIRECT_EDIT, DEFAULT_REDIRECT_DEVEL, DEFAULT_REDIRECT_CONTACT]), - # '#states' => array( - # // Only make visible these checkboxes when the url rewrite option is enabled. - # 'visible' => array( - # ':input[name="enable_redirect"]' => array('checked' => TRUE), - # ), - # ), - #); - return parent::buildForm($form, $form_state); } diff --git a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php index 2418b85..f3d8be7 100644 --- a/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php +++ b/cern_profile_displayname/src/PathProcessor/CernProfileDisplaynameOutboundPathProcessor.php @@ -18,13 +18,14 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess */ public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { $config = \Drupal::config('cern_profile_displayname.settings'); - $enable_redirect = _cern_profile_displayname_get_default_value($config->get('enable_redirect'), DEFAULT_ENABLE_REDIRECT); + $enable_redirect = $config->get('enable_redirect'); + $base_url = $config->get('profiles_site'); if ($enable_redirect) { if (preg_match('@user[/\+%]+([0-9]+)(.*)?@', $path, $matches)) { $opt_enable_redirect_pages = [ - 'edit' => DEFAULT_REDIRECT_EDIT, - 'devel' => DEFAULT_REDIRECT_DEVEL, - 'contact' => DEFAULT_REDIRECT_CONTACT, + 'edit' => $config->get('enable_redirect_pages.edit'), + 'devel' => $config->get('enable_redirect_pages.devel'), + 'contact' => $config->get('enable_redirect_pages.contact'), ]; if (!$opt_enable_redirect_pages['edit'] && $matches[2] == '/edit' @@ -33,11 +34,11 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess return $path; } $account = User::load($matches[1]); - $new_options = $this->getUserProfileLinkOptions($account); + $new_options = $this->getUserProfileLinkOptions($account, $base_url); } elseif ($path == '/user') { $account = User::load(\Drupal::currentUser()->id()); - $new_options = $this->getUserProfileLinkOptions($account); + $new_options = $this->getUserProfileLinkOptions($account, $base_url); } if (isset($new_options)) { if (in_array($request->getPathInfo(), ['/user', '/user/login'])){ @@ -63,7 +64,7 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess * Now either anonymous and authenticated users can go to social (07/09/2015) * For authenticated users will point to social.cern.ch profile. */ - protected function getUserProfileLinkOptions(User $account) { + protected function getUserProfileLinkOptions(User $account, $base_url) { $options = []; $ccid = ""; if (isset($account->field_person_id_ccid->value)) { @@ -73,7 +74,7 @@ class CernProfileDisplaynameOutboundPathProcessor implements OutboundPathProcess } $options['query'] = ['id' => $ccid]; - $options['base_url'] = 'https://phonebook.cern.ch/phonebook/#personDetails/'; + $options['base_url'] = $base_url; return $options; } diff --git a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php index 0d351db..0fa28c7 100644 --- a/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php +++ b/cern_profile_displayname/src/Plugin/Block/CernProfileDisplaynameBlock.php @@ -43,7 +43,7 @@ class CernProfileDisplaynameBlock extends BlockBase { } else { $config = \Drupal::config('cern_profile_displayname.settings'); - $enred = _cern_profile_displayname_get_default_value($config->get('enable_redirect'), DEFAULT_ENABLE_REDIRECT); + $enred = $config->get('enable_redirect'); $sign_out_link = Link::createFromRoute(t('Sign out'), 'user.logout'); if ($enred) { $username = $this->linkToProfilesSite($user); @@ -68,10 +68,10 @@ class CernProfileDisplaynameBlock extends BlockBase { if (isset($account->field_person_id_ccid->value)) { if ($account->field_person_id_ccid->value != '-1') { $config = \Drupal::config('cern_profile_displayname.settings'); - $path_profiles_site = DEFAULT_PROFILES_SITE; + $path_profiles_site = $config->get('profiles_site'); $path_profiles_site = _cern_profile_displayname_get_profiles_site_url($path_profiles_site); // Return the cern real name linking to the profile site. - return Link::fromTextAndUrl($account->getDisplayName(), URL::fromUri($path_profiles_site . $account->field_person_id_ccid->value))->toString(); + return Link::fromTextAndUrl($account->getDisplayName(), URL::fromUri($path_profiles_site . "?id=" . $account->field_person_id_ccid->value))->toString(); } // For external accounts returns the email address. else { -- GitLab