Caching of API message related user guidance could lead to misleading results, add cache contexts

Created on 1 April 2017, almost 8 years ago
Updated 11 October 2023, over 1 year ago

The advertisement of l10n_client_contributor on admin/config/regional/translate is currently flawed:
* If user does NOT have an API key, the "Set your personal API key..." message is only shown the first time
* If user DOES have an API key, sees the "All changes made will be automatically submitted..." rendered help block, and then removes the API key, the help block will erroneously still be shown.

It looks like we should
* convert the drupal_set_message to a render array return
* add appropriate cache context to the render array so that a change of the API-key field invalidates the help block

Setting major as the advertisement is imho a key feature.

function l10n_client_contributor_help($route_name, RouteMatchInterface $route_match) {
...
    case 'locale.translate_page':
...
      if ($account->hasPermission('contribute translations to localization server')) {
        if (!empty($account->l10n_client_contributor_key->value)) {
          return '<p><strong>' . t('All changes made will be automatically submitted to :server too. Thanks for contributing!', array(':server' => $config->get('server'))) . '</strong></p>';
        }
        else {
          drupal_set_message(t('<a href=":edit">Set your personal API key</a> to contribute translations automatically to :server. Thanks for contributing!', array(':edit' => Url::fromRoute('entity.user.edit_form', array('user' => $account->id()))->toString(), ':server' => $config->get('server'))), 'warning');
        }
🐛 Bug report
Status

Fixed

Version

3.0

Component

Client Contributor

Created by

🇩🇪Germany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024