Skip to content
Merged

1093 #12

Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions oit.module
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,59 @@ function oit_preprocess(&$variables, $hook) {
* Implements hook_form_alter().
*/
function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

if (array_key_exists('#webform_id', $form)) {
// Get node id current webform is on.
$node = \Drupal::routeMatch()->getParameter('node');
$node_id = is_string($node) ? 0 : $node->id();
$current_user = \Drupal::currentUser();
$roles = $current_user->getRoles();

if ($node_id && in_array('administrator', $roles)) {
$node_type = is_string($node) ? '' : $node->getType();
Comment thread
protitude marked this conversation as resolved.
Outdated
$webform_id = $form['#webform_id'];
$config = \Drupal::config('webform.webform.' . $webform_id);
$roles = $config->get('access.create.roles');
Comment thread
protitude marked this conversation as resolved.
Outdated

$annon_set = FALSE;
foreach ($roles as $key => $role) {
Comment thread
protitude marked this conversation as resolved.
Outdated
Comment thread
protitude marked this conversation as resolved.
Outdated
if ($role == 'anonymous') {
$annon_set = TRUE;
}
}

Copilot AI Dec 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The foreach loop can be simplified by using in_array('anonymous', $roles) instead of iterating through all roles to check for the 'anonymous' role. This is more efficient and clearer.

Suggested change
$annon_set = FALSE;
foreach ($roles as $key => $role) {
if ($role == 'anonymous') {
$annon_set = TRUE;
}
}
$annon_set = in_array('anonymous', $roles);

Copilot uses AI. Check for mistakes.

if ($annon_set) {
Comment thread
protitude marked this conversation as resolved.
Outdated
Comment thread
protitude marked this conversation as resolved.
Outdated
Comment thread
protitude marked this conversation as resolved.
Outdated
$captcha_config = \Drupal::config('captcha.captcha_point.webform_add_' . $node_id)->isNew();

if ($captcha_config) {
$button_text = t('Add captcha to form');
$form['#prefix'] = "<ul class='no-list-style'><li class='red'><a href='/admin/config/people/captcha/captcha-points/add?destination=node/$node_id&webform_id=$node_id' class='button icon'>⬇️ $button_text</a></li></ul>";
Comment thread
protitude marked this conversation as resolved.
Outdated
}
else {
$button_text = t('Remove captcha from form');
$form['#prefix'] = "<ul class='no-list-style'><li class='red'><a href='/admin/config/people/captcha/captcha-points/webform_add_$node_id/delete?destination=node/$node_id' class='button icon'>🔥 $button_text</a></li></ul>";
Comment thread
protitude marked this conversation as resolved.
Outdated
}

}
}
}

// admin/config/people/captcha/captcha-points/add
// Set defaults if 'webform_id' is in query string.
if ($form_id == 'captcha_point_add_form') {
// Get 'webform_id' from query string.
$request = \Drupal::request();
$webform_id = $request->get('webform_id');
$webform_id = is_numeric($webform_id) ? intval($webform_id) : 0;

if ($webform_id == 0) {
return;
}

$form['label']['#default_value'] = 'webform_submission_oit_project_accessibility_review_node_' . $webform_id . '_add_form';
Comment thread
protitude marked this conversation as resolved.
Outdated
$form['formId']['#default_value'] = 'webform_add_' . $webform_id;
}

if ($form_id == 'node_news_form' || $form_id == 'node_news_edit_form' ||
$form_id == 'node_service_alert_form' || $form_id == 'node_service_alert_edit_form'
) {
Expand Down