Skip to content

Instantly share code, notes, and snippets.

@RobertoCGarcia
RobertoCGarcia / Validación de Campos JavaScript Para WebForm de Drupal 8
Created June 28, 2018 19:43
Validación de Campos JavaScript Para WebForm de Drupal 8 - Código Probado para agregar una validación via custom js a los campos generados por el módulo webform de Drupal 8.
function validateCaptcha(){
var valueGr = document.getElementById("g-recaptcha-response").value;
if(valueGr == null){
return false;
}else{
return true;
}
}
$(document).ready(function () {
@RobertoCGarcia
RobertoCGarcia / drupal-8-register-user.txt
Last active June 19, 2018 19:54
Register a Drupal User with code
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$user = \Drupal\user\Entity\User::create();
$user->setPassword($form_state->getValue('pass'));
$user->enforceIsNew();
$user->setEmail($form_state->getValue('mail'));
$user->setUsername($form_state->getValue('name'));//This username must be unique and accept only a-Z,0-9, - _ @ .
$user->set("init", 'mail');
$user->set("langcode", $language);
$user->set("preferred_langcode", $language);
$user->set("preferred_admin_langcode", $language);