@@ -89,41 +89,40 @@ function oit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
8989 if (array_key_exists('#webform_id', $form)) {
9090 // Get node id current webform is on.
9191 $node = \Drupal::routeMatch()->getParameter('node');
92- if ($node == NULL) {
93- return;
94- }
95-
96- $node_id = is_string($node) ? 0 : $node->id();
97- $current_user = \Drupal::currentUser();
98- $roles = $current_user->getRoles();
99-
100- if ($node_id && in_array('administrator', $roles)) {
101- $webform_id = $form['#webform_id'];
102- $config = \Drupal::config('webform.webform.' . $webform_id);
103- $webform_roles = $config->get('access.create.roles');
104- if (!is_array($roles)) {
105- $roles = [];
106- }
92+ if ($node != NULL) {
93+
94+ $node_id = is_string($node) ? 0 : $node->id();
95+ $current_user = \Drupal::currentUser();
96+ $roles = $current_user->getRoles();
97+
98+ if ($node_id && in_array('administrator', $roles)) {
99+ $webform_id = $form['#webform_id'];
100+ $config = \Drupal::config('webform.webform.' . $webform_id);
101+ $webform_roles = $config->get('access.create.roles');
102+ if (!is_array($roles)) {
103+ $roles = [];
104+ }
107105
108- $anonymous_set = FALSE;
109- foreach ($webform_roles as $webform_role) {
110- if ($webform_role == 'anonymous') {
111- $anonymous_set = TRUE;
106+ $anonymous_set = FALSE;
107+ foreach ($webform_roles as $webform_role) {
108+ if ($webform_role == 'anonymous') {
109+ $anonymous_set = TRUE;
110+ }
112111 }
113- }
114112
115- if ($anonymous_set) {
116- $captcha_config = \Drupal::config('captcha.captcha_point.webform_add_' . $node_id)->isNew();
113+ if ($anonymous_set) {
114+ $captcha_config = \Drupal::config('captcha.captcha_point.webform_add_' . $node_id)->isNew();
117115
118- if ($captcha_config) {
119- $button_text = t('Add captcha to form');
120- $form['#prefix'] = Xss::filter("<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>");
121- }
122- else {
123- $button_text = t('Remove captcha from form');
124- $form['#prefix'] = Xss::filter("<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>");
125- }
116+ if ($captcha_config) {
117+ $button_text = t('Add captcha to form');
118+ $form['#prefix'] = Xss::filter("<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>");
119+ }
120+ else {
121+ $button_text = t('Remove captcha from form');
122+ $form['#prefix'] = Xss::filter("<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>");
123+ }
126124
125+ }
127126 }
128127 }
129128 }
0 commit comments