-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
202411 consentratio lp 135 #495
base: develop
Are you sure you want to change the base?
Conversation
label: 'ECC Cookie Consent Tracker settings' | ||
mapping: | ||
enable: | ||
type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact why is lost in the mists of history, but I'm guessing it's an artifact of drush generate:module
. It really doesn't matter one way or the other. It's stored as a string, it's read as a string, it works. I don't see it as having much impact either way? I mean, we can change it, but it'll be change for change's sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate may be quick but it's no guarantee of good code.
web/modules/custom/ecc_cct/README.md
Outdated
@@ -0,0 +1,11 @@ | |||
# Essex Co Co cookie consent statistics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, what am I missing? I don't see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abbreviation is confusing. Change to Essex County Council or ECC, like you have in other places.
// several times per page load. | ||
count++; | ||
if (count === 2) { | ||
console.log(response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the console logs or add a debug mode so we can control if they are written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log removed, PR updated.
]; | ||
|
||
/** @var \Drupal\Core\Database\Connection $connection */ | ||
$connection = \Drupal::service('database'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use a content entity instead of directly accessing the database table. It would make CRUD much easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah. The idea is to make this as minimalistic as possible, with the least overhead. Entities come with overhead. The DB write here couldn't be simpler, and the data extraction is a single SQL query. Entities and all of Drupal's APIs would be needless expense. In fact, we only ever want to do create and read, never update nor delete. We're doing just enough, and no more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Don't call services like this. Use create() for dependency injection.
web/modules/custom/ecc_cct/README.md
Outdated
@@ -0,0 +1,11 @@ | |||
# Essex Co Co cookie consent statistics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abbreviation is confusing. Change to Essex County Council or ECC, like you have in other places.
label: 'ECC Cookie Consent Tracker settings' | ||
mapping: | ||
enable: | ||
type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate may be quick but it's no guarantee of good code.
|
||
async function ecc_cct_log(choice) { | ||
const response = await fetch('/ecc-cct/js/log/' + choice).catch(error => { | ||
console.error('Error sending integer:', error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do users need to see anything in the console?
0 => $this->t('Disabled'), | ||
1 => $this->t('Enabled'), | ||
], | ||
'#default_value' => $this->config('ecc_cct.settings')->get('enable'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add #config_target
and you should be able to remove default_value and the submitForm method.
*/ | ||
public function log(int $choice, Request $request): Response { | ||
// If this isn't turned on, bail. | ||
if (!\Drupal::config('ecc_cct.settings')->get('enable')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be faster (one database read?) to use a State setting instead of config. Either way use the methods state()
or config()
in ControllerBase.
]; | ||
|
||
/** @var \Drupal\Core\Database\Connection $connection */ | ||
$connection = \Drupal::service('database'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Don't call services like this. Use create() for dependency injection.
* Implements hook_preprocess_html(). | ||
*/ | ||
function ecc_cct_preprocess_html(&$vars) { | ||
if ($vars['root_path'] !== 'admin') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to exclude the same paths as EU Cookie Compliance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes as follows:
- using eu cookie settings for excluded paths
- using dependency injection for db service access
- using config() from controllerbase to access config
- using #config_target instead of default_value
- js is printing nothing to console now
- changed config schema to use integer as integer is what's actually used (boolean makes radio button choke)
…l/essex-gov-uk-drupal into 202411_consentratio_LP_135
/start |
Starting Review App. |
Adds a custom module to track cookie consent choices to the database without GA.
Loads Javascript to listen for EU Cookie choice selection, logs choice and timestamp to the DB.
Tracking can be turned on or off via settings screen.
https://eccservicetransformation.atlassian.net/browse/LP-135