system.api.php 197 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by Drupal core and the System module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Defines one or more hooks that are exposed by a module.
  12. *
  13. * Normally hooks do not need to be explicitly defined. However, by declaring a
  14. * hook explicitly, a module may define a "group" for it. Modules that implement
  15. * a hook may then place their implementation in either $module.module or in
  16. * $module.$group.inc. If the hook is located in $module.$group.inc, then that
  17. * file will be automatically loaded when needed.
  18. * In general, hooks that are rarely invoked and/or are very large should be
  19. * placed in a separate include file, while hooks that are very short or very
  20. * frequently called should be left in the main module file so that they are
  21. * always available.
  22. *
  23. * @return
  24. * An associative array whose keys are hook names and whose values are an
  25. * associative array containing:
  26. * - group: A string defining the group to which the hook belongs. The module
  27. * system will determine whether a file with the name $module.$group.inc
  28. * exists, and automatically load it when required.
  29. *
  30. * See system_hook_info() for all hook groups defined by Drupal core.
  31. *
  32. * @see hook_hook_info_alter().
  33. */
  34. function hook_hook_info() {
  35. $hooks['token_info'] = array(
  36. 'group' => 'tokens',
  37. );
  38. $hooks['tokens'] = array(
  39. 'group' => 'tokens',
  40. );
  41. return $hooks;
  42. }
  43. /**
  44. * Alter information from hook_hook_info().
  45. *
  46. * @param $hooks
  47. * Information gathered by module_hook_info() from other modules'
  48. * implementations of hook_hook_info(). Alter this array directly.
  49. * See hook_hook_info() for information on what this may contain.
  50. */
  51. function hook_hook_info_alter(&$hooks) {
  52. // Our module wants to completely override the core tokens, so make
  53. // sure the core token hooks are not found.
  54. $hooks['token_info']['group'] = 'mytokens';
  55. $hooks['tokens']['group'] = 'mytokens';
  56. }
  57. /**
  58. * Inform the base system and the Field API about one or more entity types.
  59. *
  60. * Inform the system about one or more entity types (i.e., object types that
  61. * can be loaded via entity_load() and, optionally, to which fields can be
  62. * attached).
  63. *
  64. * @return
  65. * An array whose keys are entity type names and whose values identify
  66. * properties of those types that the system needs to know about:
  67. * - label: The human-readable name of the type.
  68. * - controller class: The name of the class that is used to load the objects.
  69. * The class has to implement the DrupalEntityControllerInterface interface.
  70. * Leave blank to use the DrupalDefaultEntityController implementation.
  71. * - base table: (used by DrupalDefaultEntityController) The name of the
  72. * entity type's base table.
  73. * - revision table: The name of the entity type's revision table (if any).
  74. * - static cache: (used by DrupalDefaultEntityController) FALSE to disable
  75. * static caching of entities during a page request. Defaults to TRUE.
  76. * - field cache: (used by Field API loading and saving of field data) FALSE
  77. * to disable Field API's persistent cache of field data. Only recommended
  78. * if a higher level persistent cache is available for the entity type.
  79. * Defaults to TRUE.
  80. * - load hook: The name of the hook which should be invoked by
  81. * DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
  82. * - uri callback: The name of an implementation of
  83. * callback_entity_info_uri().
  84. * - label callback: (optional) The name of an implementation of
  85. * callback_entity_info_label(), which returns the label of the entity. The
  86. * entity label is the main string associated with an entity; for example,
  87. * the title of a node or the subject of a comment. If there is an entity
  88. * object property that defines the label, then using the 'label' element of
  89. * the 'entity keys' return value component suffices to provide this
  90. * information (see below). Alternatively, specifying this callback allows
  91. * more complex logic to determine the label of an entity. See also the
  92. * entity_label() function, which implements this logic.
  93. * - language callback: (optional) The name of an implementation of
  94. * callback_entity_info_language(). In most situations, when needing to
  95. * determine this value, inspecting a property named after the 'language'
  96. * element of the 'entity keys' should be enough. The language callback is
  97. * meant to be used primarily for temporary alterations of the property
  98. * value: entity-defining modules are encouraged to always define a
  99. * language property, instead of using the callback as main entity language
  100. * source. In fact not having a language property defined is likely to
  101. * prevent an entity from being queried by language. Moreover, given that
  102. * entity_language() is not necessarily used everywhere it would be
  103. * appropriate, modules implementing the language callback should be aware
  104. * that this might not be always called.
  105. * - fieldable: Set to TRUE if you want your entity type to accept fields
  106. * being attached to it.
  107. * - translation: An associative array of modules registered as field
  108. * translation handlers. Array keys are the module names, array values
  109. * can be any data structure the module uses to provide field translation.
  110. * Any empty value disallows the module to appear as a translation handler.
  111. * - entity keys: An array describing how the Field API can extract the
  112. * information it needs from the objects of the type. Elements:
  113. * - id: The name of the property that contains the primary id of the
  114. * entity. Every entity object passed to the Field API must have this
  115. * property and its value must be numeric.
  116. * - revision: The name of the property that contains the revision id of
  117. * the entity. The Field API assumes that all revision ids are unique
  118. * across all entities of a type. This entry can be omitted if the
  119. * entities of this type are not versionable.
  120. * - bundle: The name of the property that contains the bundle name for the
  121. * entity. The bundle name defines which set of fields are attached to
  122. * the entity (e.g. what nodes call "content type"). This entry can be
  123. * omitted if this entity type exposes a single bundle (all entities have
  124. * the same collection of fields). The name of this single bundle will be
  125. * the same as the entity type.
  126. * - label: The name of the property that contains the entity label. For
  127. * example, if the entity's label is located in $entity->subject, then
  128. * 'subject' should be specified here. If complex logic is required to
  129. * build the label, a 'label callback' should be defined instead (see
  130. * the 'label callback' section above for details).
  131. * - language: The name of the property, typically 'language', that contains
  132. * the language code representing the language the entity has been created
  133. * in. This value may be changed when editing the entity and represents
  134. * the language its textual components are supposed to have. If no
  135. * language property is available, the 'language callback' may be used
  136. * instead. This entry can be omitted if the entities of this type are not
  137. * language-aware.
  138. * - bundle keys: An array describing how the Field API can extract the
  139. * information it needs from the bundle objects for this type. This entry
  140. * is required if the 'path' provided in the 'bundles'/'admin' section
  141. * identifies the bundle using a named menu placeholder whose loader
  142. * callback returns an object (e.g., $vocabulary for taxonomy terms, or
  143. * $node_type for nodes). If the path does not include the bundle, or the
  144. * bundle is just a string rather than an automatically loaded object, then
  145. * this can be omitted. Elements:
  146. * - bundle: The name of the property of the bundle object that contains
  147. * the name of the bundle object.
  148. * - bundles: An array describing all bundles for this object type. Keys are
  149. * bundles machine names, as found in the objects' 'bundle' property
  150. * (defined in the 'entity keys' entry above). This entry can be omitted if
  151. * this entity type exposes a single bundle (all entities have the same
  152. * collection of fields). The name of this single bundle will be the same as
  153. * the entity type. Elements:
  154. * - label: The human-readable name of the bundle.
  155. * - uri callback: Same as the 'uri callback' key documented above for the
  156. * entity type, but for the bundle only. When determining the URI of an
  157. * entity, if a 'uri callback' is defined for both the entity type and
  158. * the bundle, the one for the bundle is used.
  159. * - admin: An array of information that allows Field UI pages to attach
  160. * themselves to the existing administration pages for the bundle.
  161. * Elements:
  162. * - path: the path of the bundle's main administration page, as defined
  163. * in hook_menu(). If the path includes a placeholder for the bundle,
  164. * the 'bundle argument' and 'real path' keys below are required.
  165. * - bundle argument: The position of the bundle placeholder in 'path', if
  166. * any.
  167. * - real path: The actual path (no placeholder) of the bundle's main
  168. * administration page. This will be used to generate links.
  169. * - access callback: As in hook_menu(). 'user_access' will be assumed if
  170. * no value is provided.
  171. * - access arguments: As in hook_menu().
  172. * - view modes: An array describing the view modes for the entity type. View
  173. * modes let entities be displayed differently depending on the context.
  174. * For instance, a node can be displayed differently on its own page
  175. * ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
  176. * in an RSS feed ('rss' mode). Modules taking part in the display of the
  177. * entity (notably the Field API) can adjust their behavior depending on
  178. * the requested view mode. An additional 'default' view mode is available
  179. * for all entity types. This view mode is not intended for actual entity
  180. * display, but holds default display settings. For each available view
  181. * mode, administrators can configure whether it should use its own set of
  182. * field display settings, or just replicate the settings of the 'default'
  183. * view mode, thus reducing the amount of display configurations to keep
  184. * track of. Keys of the array are view mode names. Each view mode is
  185. * described by an array with the following key/value pairs:
  186. * - label: The human-readable name of the view mode
  187. * - custom settings: A boolean specifying whether the view mode should by
  188. * default use its own custom field display settings. If FALSE, entities
  189. * displayed in this view mode will reuse the 'default' display settings
  190. * by default (e.g. right after the module exposing the view mode is
  191. * enabled), but administrators can later use the Field UI to apply custom
  192. * display settings specific to the view mode.
  193. *
  194. * @see entity_load()
  195. * @see hook_entity_info_alter()
  196. */
  197. function hook_entity_info() {
  198. $return = array(
  199. 'node' => array(
  200. 'label' => t('Node'),
  201. 'controller class' => 'NodeController',
  202. 'base table' => 'node',
  203. 'revision table' => 'node_revision',
  204. 'uri callback' => 'node_uri',
  205. 'fieldable' => TRUE,
  206. 'translation' => array(
  207. 'locale' => TRUE,
  208. ),
  209. 'entity keys' => array(
  210. 'id' => 'nid',
  211. 'revision' => 'vid',
  212. 'bundle' => 'type',
  213. 'language' => 'language',
  214. ),
  215. 'bundle keys' => array(
  216. 'bundle' => 'type',
  217. ),
  218. 'bundles' => array(),
  219. 'view modes' => array(
  220. 'full' => array(
  221. 'label' => t('Full content'),
  222. 'custom settings' => FALSE,
  223. ),
  224. 'teaser' => array(
  225. 'label' => t('Teaser'),
  226. 'custom settings' => TRUE,
  227. ),
  228. 'rss' => array(
  229. 'label' => t('RSS'),
  230. 'custom settings' => FALSE,
  231. ),
  232. ),
  233. ),
  234. );
  235. // Search integration is provided by node.module, so search-related
  236. // view modes for nodes are defined here and not in search.module.
  237. if (module_exists('search')) {
  238. $return['node']['view modes'] += array(
  239. 'search_index' => array(
  240. 'label' => t('Search index'),
  241. 'custom settings' => FALSE,
  242. ),
  243. 'search_result' => array(
  244. 'label' => t('Search result highlighting input'),
  245. 'custom settings' => FALSE,
  246. ),
  247. );
  248. }
  249. // Bundles must provide a human readable name so we can create help and error
  250. // messages, and the path to attach Field admin pages to.
  251. foreach (node_type_get_names() as $type => $name) {
  252. $return['node']['bundles'][$type] = array(
  253. 'label' => $name,
  254. 'admin' => array(
  255. 'path' => 'admin/structure/types/manage/%node_type',
  256. 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type),
  257. 'bundle argument' => 4,
  258. 'access arguments' => array('administer content types'),
  259. ),
  260. );
  261. }
  262. return $return;
  263. }
  264. /**
  265. * Alter the entity info.
  266. *
  267. * Modules may implement this hook to alter the information that defines an
  268. * entity. All properties that are available in hook_entity_info() can be
  269. * altered here.
  270. *
  271. * @param $entity_info
  272. * The entity info array, keyed by entity name.
  273. *
  274. * @see hook_entity_info()
  275. */
  276. function hook_entity_info_alter(&$entity_info) {
  277. // Set the controller class for nodes to an alternate implementation of the
  278. // DrupalEntityController interface.
  279. $entity_info['node']['controller class'] = 'MyCustomNodeController';
  280. }
  281. /**
  282. * Act on entities when loaded.
  283. *
  284. * This is a generic load hook called for all entity types loaded via the
  285. * entity API.
  286. *
  287. * @param $entities
  288. * The entities keyed by entity ID.
  289. * @param $type
  290. * The type of entities being loaded (i.e. node, user, comment).
  291. */
  292. function hook_entity_load($entities, $type) {
  293. foreach ($entities as $entity) {
  294. $entity->foo = mymodule_add_something($entity, $type);
  295. }
  296. }
  297. /**
  298. * Act on an entity before it is about to be created or updated.
  299. *
  300. * @param $entity
  301. * The entity object.
  302. * @param $type
  303. * The type of entity being saved (i.e. node, user, comment).
  304. */
  305. function hook_entity_presave($entity, $type) {
  306. $entity->changed = REQUEST_TIME;
  307. }
  308. /**
  309. * Act on entities when inserted.
  310. *
  311. * @param $entity
  312. * The entity object.
  313. * @param $type
  314. * The type of entity being inserted (i.e. node, user, comment).
  315. */
  316. function hook_entity_insert($entity, $type) {
  317. // Insert the new entity into a fictional table of all entities.
  318. $info = entity_get_info($type);
  319. list($id) = entity_extract_ids($type, $entity);
  320. db_insert('example_entity')
  321. ->fields(array(
  322. 'type' => $type,
  323. 'id' => $id,
  324. 'created' => REQUEST_TIME,
  325. 'updated' => REQUEST_TIME,
  326. ))
  327. ->execute();
  328. }
  329. /**
  330. * Act on entities when updated.
  331. *
  332. * @param $entity
  333. * The entity object.
  334. * @param $type
  335. * The type of entity being updated (i.e. node, user, comment).
  336. */
  337. function hook_entity_update($entity, $type) {
  338. // Update the entity's entry in a fictional table of all entities.
  339. $info = entity_get_info($type);
  340. list($id) = entity_extract_ids($type, $entity);
  341. db_update('example_entity')
  342. ->fields(array(
  343. 'updated' => REQUEST_TIME,
  344. ))
  345. ->condition('type', $type)
  346. ->condition('id', $id)
  347. ->execute();
  348. }
  349. /**
  350. * Act on entities when deleted.
  351. *
  352. * @param $entity
  353. * The entity object.
  354. * @param $type
  355. * The type of entity being deleted (i.e. node, user, comment).
  356. */
  357. function hook_entity_delete($entity, $type) {
  358. // Delete the entity's entry from a fictional table of all entities.
  359. $info = entity_get_info($type);
  360. list($id) = entity_extract_ids($type, $entity);
  361. db_delete('example_entity')
  362. ->condition('type', $type)
  363. ->condition('id', $id)
  364. ->execute();
  365. }
  366. /**
  367. * Alter or execute an EntityFieldQuery.
  368. *
  369. * @param EntityFieldQuery $query
  370. * An EntityFieldQuery. One of the most important properties to be changed is
  371. * EntityFieldQuery::executeCallback. If this is set to an existing function,
  372. * this function will get the query as its single argument and its result
  373. * will be the returned as the result of EntityFieldQuery::execute(). This can
  374. * be used to change the behavior of EntityFieldQuery entirely. For example,
  375. * the default implementation can only deal with one field storage engine, but
  376. * it is possible to write a module that can query across field storage
  377. * engines. Also, the default implementation presumes entities are stored in
  378. * SQL, but the execute callback could instead query any other entity storage,
  379. * local or remote.
  380. *
  381. * Note the $query->altered attribute which is TRUE in case the query has
  382. * already been altered once. This happens with cloned queries.
  383. * If there is a pager, then such a cloned query will be executed to count
  384. * all elements. This query can be detected by checking for
  385. * ($query->pager && $query->count), allowing the driver to return 0 from
  386. * the count query and disable the pager.
  387. */
  388. function hook_entity_query_alter($query) {
  389. $query->executeCallback = 'my_module_query_callback';
  390. }
  391. /**
  392. * Act on entities being assembled before rendering.
  393. *
  394. * @param $entity
  395. * The entity object.
  396. * @param $type
  397. * The type of entity being rendered (i.e. node, user, comment).
  398. * @param $view_mode
  399. * The view mode the entity is rendered in.
  400. * @param $langcode
  401. * The language code used for rendering.
  402. *
  403. * The module may add elements to $entity->content prior to rendering. The
  404. * structure of $entity->content is a renderable array as expected by
  405. * drupal_render().
  406. *
  407. * @see hook_entity_view_alter()
  408. * @see hook_comment_view()
  409. * @see hook_node_view()
  410. * @see hook_user_view()
  411. */
  412. function hook_entity_view($entity, $type, $view_mode, $langcode) {
  413. $entity->content['my_additional_field'] = array(
  414. '#markup' => $additional_field,
  415. '#weight' => 10,
  416. '#theme' => 'mymodule_my_additional_field',
  417. );
  418. }
  419. /**
  420. * Alter the results of ENTITY_view().
  421. *
  422. * This hook is called after the content has been assembled in a structured
  423. * array and may be used for doing processing which requires that the complete
  424. * entity content structure has been built.
  425. *
  426. * If a module wishes to act on the rendered HTML of the entity rather than the
  427. * structured content array, it may use this hook to add a #post_render
  428. * callback. Alternatively, it could also implement hook_preprocess_ENTITY().
  429. * See drupal_render() and theme() for details.
  430. *
  431. * @param $build
  432. * A renderable array representing the entity content.
  433. * @param $type
  434. * The type of entity being rendered (i.e. node, user, comment).
  435. *
  436. * @see hook_entity_view()
  437. * @see hook_comment_view_alter()
  438. * @see hook_node_view_alter()
  439. * @see hook_taxonomy_term_view_alter()
  440. * @see hook_user_view_alter()
  441. */
  442. function hook_entity_view_alter(&$build, $type) {
  443. if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
  444. // Change its weight.
  445. $build['an_additional_field']['#weight'] = -10;
  446. // Add a #post_render callback to act on the rendered HTML of the entity.
  447. $build['#post_render'][] = 'my_module_node_post_render';
  448. }
  449. }
  450. /**
  451. * Change the view mode of an entity that is being displayed.
  452. *
  453. * @param string $view_mode
  454. * The view_mode that is to be used to display the entity.
  455. * @param array $context
  456. * Array with contextual information, including:
  457. * - entity_type: The type of the entity that is being viewed.
  458. * - entity: The entity object.
  459. * - langcode: The langcode the entity is being viewed in.
  460. */
  461. function hook_entity_view_mode_alter(&$view_mode, $context) {
  462. // For nodes, change the view mode when it is teaser.
  463. if ($context['entity_type'] == 'node' && $view_mode == 'teaser') {
  464. $view_mode = 'my_custom_view_mode';
  465. }
  466. }
  467. /**
  468. * Define administrative paths.
  469. *
  470. * Modules may specify whether or not the paths they define in hook_menu() are
  471. * to be considered administrative. Other modules may use this information to
  472. * display those pages differently (e.g. in a modal overlay, or in a different
  473. * theme).
  474. *
  475. * To change the administrative status of menu items defined in another module's
  476. * hook_menu(), modules should implement hook_admin_paths_alter().
  477. *
  478. * @return
  479. * An associative array. For each item, the key is the path in question, in
  480. * a format acceptable to drupal_match_path(). The value for each item should
  481. * be TRUE (for paths considered administrative) or FALSE (for non-
  482. * administrative paths).
  483. *
  484. * @see hook_menu()
  485. * @see drupal_match_path()
  486. * @see hook_admin_paths_alter()
  487. */
  488. function hook_admin_paths() {
  489. $paths = array(
  490. 'mymodule/*/add' => TRUE,
  491. 'mymodule/*/edit' => TRUE,
  492. );
  493. return $paths;
  494. }
  495. /**
  496. * Redefine administrative paths defined by other modules.
  497. *
  498. * @param $paths
  499. * An associative array of administrative paths, as defined by implementations
  500. * of hook_admin_paths().
  501. *
  502. * @see hook_admin_paths()
  503. */
  504. function hook_admin_paths_alter(&$paths) {
  505. // Treat all user pages as administrative.
  506. $paths['user'] = TRUE;
  507. $paths['user/*'] = TRUE;
  508. // Treat the forum topic node form as a non-administrative page.
  509. $paths['node/add/forum'] = FALSE;
  510. }
  511. /**
  512. * Act on entities as they are being prepared for view.
  513. *
  514. * Allows you to operate on multiple entities as they are being prepared for
  515. * view. Only use this if attaching the data during the entity_load() phase
  516. * is not appropriate, for example when attaching other 'entity' style objects.
  517. *
  518. * @param $entities
  519. * The entities keyed by entity ID.
  520. * @param $type
  521. * The type of entities being loaded (i.e. node, user, comment).
  522. * @param $langcode
  523. * The language to display the entity in.
  524. */
  525. function hook_entity_prepare_view($entities, $type, $langcode) {
  526. // Load a specific node into the user object for later theming.
  527. if ($type == 'user') {
  528. $nodes = mymodule_get_user_nodes(array_keys($entities));
  529. foreach ($entities as $uid => $entity) {
  530. $entity->user_node = $nodes[$uid];
  531. }
  532. }
  533. }
  534. /**
  535. * Perform periodic actions.
  536. *
  537. * Modules that require some commands to be executed periodically can
  538. * implement hook_cron(). The engine will then call the hook whenever a cron
  539. * run happens, as defined by the administrator. Typical tasks managed by
  540. * hook_cron() are database maintenance, backups, recalculation of settings
  541. * or parameters, automated mailing, and retrieving remote data.
  542. *
  543. * Short-running or non-resource-intensive tasks can be executed directly in
  544. * the hook_cron() implementation.
  545. *
  546. * Long-running tasks and tasks that could time out, such as retrieving remote
  547. * data, sending email, and intensive file tasks, should use the queue API
  548. * instead of executing the tasks directly. To do this, first define one or
  549. * more queues via hook_cron_queue_info(). Then, add items that need to be
  550. * processed to the defined queues.
  551. */
  552. function hook_cron() {
  553. // Short-running operation example, not using a queue:
  554. // Delete all expired records since the last cron run.
  555. $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
  556. db_delete('mymodule_table')
  557. ->condition('expires', $expires, '>=')
  558. ->execute();
  559. variable_set('mymodule_cron_last_run', REQUEST_TIME);
  560. // Long-running operation example, leveraging a queue:
  561. // Fetch feeds from other sites.
  562. $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
  563. ':time' => REQUEST_TIME,
  564. ':never' => AGGREGATOR_CLEAR_NEVER,
  565. ));
  566. $queue = DrupalQueue::get('aggregator_feeds');
  567. foreach ($result as $feed) {
  568. $queue->createItem($feed);
  569. }
  570. }
  571. /**
  572. * Declare queues holding items that need to be run periodically.
  573. *
  574. * While there can be only one hook_cron() process running at the same time,
  575. * there can be any number of processes defined here running. Because of
  576. * this, long running tasks are much better suited for this API. Items queued
  577. * in hook_cron() might be processed in the same cron run if there are not many
  578. * items in the queue, otherwise it might take several requests, which can be
  579. * run in parallel.
  580. *
  581. * @return
  582. * An associative array where the key is the queue name and the value is
  583. * again an associative array. Possible keys are:
  584. * - 'worker callback': A PHP callable to call that is an implementation of
  585. * callback_queue_worker().
  586. * - 'time': (optional) How much time Drupal should spend on calling this
  587. * worker in seconds. Defaults to 15.
  588. * - 'skip on cron': (optional) Set to TRUE to avoid being processed during
  589. * cron runs (for example, if you want to control all queue execution
  590. * manually).
  591. *
  592. * @see hook_cron()
  593. * @see hook_cron_queue_info_alter()
  594. */
  595. function hook_cron_queue_info() {
  596. $queues['aggregator_feeds'] = array(
  597. 'worker callback' => 'aggregator_refresh',
  598. 'time' => 60,
  599. );
  600. return $queues;
  601. }
  602. /**
  603. * Alter cron queue information before cron runs.
  604. *
  605. * Called by drupal_cron_run() to allow modules to alter cron queue settings
  606. * before any jobs are processesed.
  607. *
  608. * @param array $queues
  609. * An array of cron queue information.
  610. *
  611. * @see hook_cron_queue_info()
  612. * @see drupal_cron_run()
  613. */
  614. function hook_cron_queue_info_alter(&$queues) {
  615. // This site has many feeds so let's spend 90 seconds on each cron run
  616. // updating feeds instead of the default 60.
  617. $queues['aggregator_feeds']['time'] = 90;
  618. }
  619. /**
  620. * Work on a single queue item.
  621. *
  622. * Callback for hook_queue_info().
  623. *
  624. * @param $queue_item_data
  625. * The data that was passed to DrupalQueue::createItem() when the item was
  626. * queued.
  627. *
  628. * @throws \Exception
  629. * The worker callback may throw an exception to indicate there was a problem.
  630. * The cron process will log the exception, and leave the item in the queue to
  631. * be processed again later.
  632. *
  633. * @see drupal_cron_run()
  634. */
  635. function callback_queue_worker($queue_item_data) {
  636. $node = node_load($queue_item_data);
  637. $node->title = 'Updated title';
  638. $node->save();
  639. }
  640. /**
  641. * Allows modules to declare their own Form API element types and specify their
  642. * default values.
  643. *
  644. * This hook allows modules to declare their own form element types and to
  645. * specify their default values. The values returned by this hook will be
  646. * merged with the elements returned by hook_form() implementations and so
  647. * can return defaults for any Form APIs keys in addition to those explicitly
  648. * mentioned below.
  649. *
  650. * Each of the form element types defined by this hook is assumed to have
  651. * a matching theme function, e.g. theme_elementtype(), which should be
  652. * registered with hook_theme() as normal.
  653. *
  654. * For more information about custom element types see the explanation at
  655. * http://drupal.org/node/169815.
  656. *
  657. * @return
  658. * An associative array describing the element types being defined. The array
  659. * contains a sub-array for each element type, with the machine-readable type
  660. * name as the key. Each sub-array has a number of possible attributes:
  661. * - "#input": boolean indicating whether or not this element carries a value
  662. * (even if it's hidden).
  663. * - "#process": array of callback functions taking $element, $form_state,
  664. * and $complete_form.
  665. * - "#after_build": array of callback functions taking $element and $form_state.
  666. * - "#validate": array of callback functions taking $form and $form_state.
  667. * - "#element_validate": array of callback functions taking $element and
  668. * $form_state.
  669. * - "#pre_render": array of callback functions taking $element and $form_state.
  670. * - "#post_render": array of callback functions taking $element and $form_state.
  671. * - "#submit": array of callback functions taking $form and $form_state.
  672. * - "#title_display": optional string indicating if and how #title should be
  673. * displayed, see theme_form_element() and theme_form_element_label().
  674. *
  675. * @see hook_element_info_alter()
  676. * @see system_element_info()
  677. */
  678. function hook_element_info() {
  679. $types['filter_format'] = array(
  680. '#input' => TRUE,
  681. );
  682. return $types;
  683. }
  684. /**
  685. * Alter the element type information returned from modules.
  686. *
  687. * A module may implement this hook in order to alter the element type defaults
  688. * defined by a module.
  689. *
  690. * @param $type
  691. * All element type defaults as collected by hook_element_info().
  692. *
  693. * @see hook_element_info()
  694. */
  695. function hook_element_info_alter(&$type) {
  696. // Decrease the default size of textfields.
  697. if (isset($type['textfield']['#size'])) {
  698. $type['textfield']['#size'] = 40;
  699. }
  700. }
  701. /**
  702. * Perform cleanup tasks.
  703. *
  704. * This hook is run at the end of most regular page requests. It is often
  705. * used for page logging and specialized cleanup. This hook MUST NOT print
  706. * anything because by the time it runs the response is already sent to
  707. * the browser.
  708. *
  709. * Only use this hook if your code must run even for cached page views.
  710. * If you have code which must run once on all non-cached pages, use
  711. * hook_init() instead. That is the usual case. If you implement this hook
  712. * and see an error like 'Call to undefined function', it is likely that
  713. * you are depending on the presence of a module which has not been loaded yet.
  714. * It is not loaded because Drupal is still in bootstrap mode.
  715. *
  716. * @param $destination
  717. * If this hook is invoked as part of a drupal_goto() call, then this argument
  718. * will be a fully-qualified URL that is the destination of the redirect.
  719. */
  720. function hook_exit($destination = NULL) {
  721. db_update('counter')
  722. ->expression('hits', 'hits + 1')
  723. ->condition('type', 1)
  724. ->execute();
  725. }
  726. /**
  727. * Perform necessary alterations to the JavaScript before it is presented on
  728. * the page.
  729. *
  730. * @param $javascript
  731. * An array of all JavaScript being presented on the page.
  732. *
  733. * @see drupal_add_js()
  734. * @see drupal_get_js()
  735. * @see drupal_js_defaults()
  736. */
  737. function hook_js_alter(&$javascript) {
  738. // Swap out jQuery to use an updated version of the library.
  739. $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
  740. }
  741. /**
  742. * Registers JavaScript/CSS libraries associated with a module.
  743. *
  744. * Modules implementing this return an array of arrays. The key to each
  745. * sub-array is the machine readable name of the library. Each library may
  746. * contain the following items:
  747. *
  748. * - 'title': The human readable name of the library.
  749. * - 'website': The URL of the library's web site.
  750. * - 'version': A string specifying the version of the library; intentionally
  751. * not a float because a version like "1.2.3" is not a valid float. Use PHP's
  752. * version_compare() to compare different versions.
  753. * - 'js': An array of JavaScript elements; each element's key is used as $data
  754. * argument, each element's value is used as $options array for
  755. * drupal_add_js(). To add library-specific (not module-specific) JavaScript
  756. * settings, the key may be skipped, the value must specify
  757. * 'type' => 'setting', and the actual settings must be contained in a 'data'
  758. * element of the value.
  759. * - 'css': Like 'js', an array of CSS elements passed to drupal_add_css().
  760. * - 'dependencies': An array of libraries that are required for a library. Each
  761. * element is an array listing the module and name of another library. Note
  762. * that all dependencies for each dependent library will also be added when
  763. * this library is added.
  764. *
  765. * Registered information for a library should contain re-usable data only.
  766. * Module- or implementation-specific data and integration logic should be added
  767. * separately.
  768. *
  769. * @return
  770. * An array defining libraries associated with a module.
  771. *
  772. * @see system_library()
  773. * @see drupal_add_library()
  774. * @see drupal_get_library()
  775. */
  776. function hook_library() {
  777. // Library One.
  778. $libraries['library-1'] = array(
  779. 'title' => 'Library One',
  780. 'website' => 'http://example.com/library-1',
  781. 'version' => '1.2',
  782. 'js' => array(
  783. drupal_get_path('module', 'my_module') . '/library-1.js' => array(),
  784. ),
  785. 'css' => array(
  786. drupal_get_path('module', 'my_module') . '/library-2.css' => array(
  787. 'type' => 'file',
  788. 'media' => 'screen',
  789. ),
  790. ),
  791. );
  792. // Library Two.
  793. $libraries['library-2'] = array(
  794. 'title' => 'Library Two',
  795. 'website' => 'http://example.com/library-2',
  796. 'version' => '3.1-beta1',
  797. 'js' => array(
  798. // JavaScript settings may use the 'data' key.
  799. array(
  800. 'type' => 'setting',
  801. 'data' => array('library2' => TRUE),
  802. ),
  803. ),
  804. 'dependencies' => array(
  805. // Require jQuery UI core by System module.
  806. array('system', 'ui'),
  807. // Require our other library.
  808. array('my_module', 'library-1'),
  809. // Require another library.
  810. array('other_module', 'library-3'),
  811. ),
  812. );
  813. return $libraries;
  814. }
  815. /**
  816. * Alters the JavaScript/CSS library registry.
  817. *
  818. * Allows certain, contributed modules to update libraries to newer versions
  819. * while ensuring backwards compatibility. In general, such manipulations should
  820. * only be done by designated modules, since most modules that integrate with a
  821. * certain library also depend on the API of a certain library version.
  822. *
  823. * @param $libraries
  824. * The JavaScript/CSS libraries provided by $module. Keyed by internal library
  825. * name and passed by reference.
  826. * @param $module
  827. * The name of the module that registered the libraries.
  828. *
  829. * @see hook_library()
  830. */
  831. function hook_library_alter(&$libraries, $module) {
  832. // Update Farbtastic to version 2.0.
  833. if ($module == 'system' && isset($libraries['farbtastic'])) {
  834. // Verify existing version is older than the one we are updating to.
  835. if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) {
  836. // Update the existing Farbtastic to version 2.0.
  837. $libraries['farbtastic']['version'] = '2.0';
  838. $libraries['farbtastic']['js'] = array(
  839. drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(),
  840. );
  841. }
  842. }
  843. }
  844. /**
  845. * Alter CSS files before they are output on the page.
  846. *
  847. * @param $css
  848. * An array of all CSS items (files and inline CSS) being requested on the page.
  849. *
  850. * @see drupal_add_css()
  851. * @see drupal_get_css()
  852. */
  853. function hook_css_alter(&$css) {
  854. // Remove defaults.css file.
  855. unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
  856. }
  857. /**
  858. * Alter the commands that are sent to the user through the Ajax framework.
  859. *
  860. * @param $commands
  861. * An array of all commands that will be sent to the user.
  862. *
  863. * @see ajax_render()
  864. */
  865. function hook_ajax_render_alter(&$commands) {
  866. // Inject any new status messages into the content area.
  867. $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages'));
  868. }
  869. /**
  870. * Add elements to a page before it is rendered.
  871. *
  872. * Use this hook when you want to add elements at the page level. For your
  873. * additions to be printed, they have to be placed below a top level array key
  874. * of the $page array that has the name of a region of the active theme.
  875. *
  876. * By default, valid region keys are 'page_top', 'header', 'sidebar_first',
  877. * 'content', 'sidebar_second' and 'page_bottom'. To get a list of all regions
  878. * of the active theme, use system_region_list($theme). Note that $theme is a
  879. * global variable.
  880. *
  881. * If you want to alter the elements added by other modules or if your module
  882. * depends on the elements of other modules, use hook_page_alter() instead which
  883. * runs after this hook.
  884. *
  885. * @param $page
  886. * Nested array of renderable elements that make up the page.
  887. *
  888. * @see hook_page_alter()
  889. * @see drupal_render_page()
  890. */
  891. function hook_page_build(&$page) {
  892. if (menu_get_object('node', 1)) {
  893. // We are on a node detail page. Append a standard disclaimer to the
  894. // content region.
  895. $page['content']['disclaimer'] = array(
  896. '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'),
  897. '#weight' => 25,
  898. );
  899. }
  900. }
  901. /**
  902. * Alter a menu router item right after it has been retrieved from the database or cache.
  903. *
  904. * This hook is invoked by menu_get_item() and allows for run-time alteration of router
  905. * information (page_callback, title, and so on) before it is translated and checked for
  906. * access. The passed-in $router_item is statically cached for the current request, so this
  907. * hook is only invoked once for any router item that is retrieved via menu_get_item().
  908. *
  909. * Usually, modules will only want to inspect the router item and conditionally
  910. * perform other actions (such as preparing a state for the current request).
  911. * Note that this hook is invoked for any router item that is retrieved by
  912. * menu_get_item(), which may or may not be called on the path itself, so implementations
  913. * should check the $path parameter if the alteration should fire for the current request
  914. * only.
  915. *
  916. * @param $router_item
  917. * The menu router item for $path.
  918. * @param $path
  919. * The originally passed path, for which $router_item is responsible.
  920. * @param $original_map
  921. * The path argument map, as contained in $path.
  922. *
  923. * @see menu_get_item()
  924. */
  925. function hook_menu_get_item_alter(&$router_item, $path, $original_map) {
  926. // When retrieving the router item for the current path...
  927. if ($path == $_GET['q']) {
  928. // ...call a function that prepares something for this request.
  929. mymodule_prepare_something();
  930. }
  931. }
  932. /**
  933. * Define menu items and page callbacks.
  934. *
  935. * This hook enables modules to register paths in order to define how URL
  936. * requests are handled. Paths may be registered for URL handling only, or they
  937. * can register a link to be placed in a menu (usually the Navigation menu). A
  938. * path and its associated information is commonly called a "menu router item".
  939. * This hook is rarely called (for example, when modules are enabled), and
  940. * its results are cached in the database.
  941. *
  942. * hook_menu() implementations return an associative array whose keys define
  943. * paths and whose values are an associative array of properties for each
  944. * path. (The complete list of properties is in the return value section below.)
  945. *
  946. * @section sec_callback_funcs Callback Functions
  947. * The definition for each path may include a page callback function, which is
  948. * invoked when the registered path is requested. If there is no other
  949. * registered path that fits the requested path better, any further path
  950. * components are passed to the callback function. For example, your module
  951. * could register path 'abc/def':
  952. * @code
  953. * function mymodule_menu() {
  954. * $items['abc/def'] = array(
  955. * 'page callback' => 'mymodule_abc_view',
  956. * );
  957. * return $items;
  958. * }
  959. *
  960. * function mymodule_abc_view($ghi = 0, $jkl = '') {
  961. * // ...
  962. * }
  963. * @endcode
  964. * When path 'abc/def' is requested, no further path components are in the
  965. * request, and no additional arguments are passed to the callback function (so
  966. * $ghi and $jkl would take the default values as defined in the function
  967. * signature). When 'abc/def/123/foo' is requested, $ghi will be '123' and
  968. * $jkl will be 'foo'. Note that this automatic passing of optional path
  969. * arguments applies only to page and theme callback functions.
  970. *
  971. * @subsection sub_callback_arguments Callback Arguments
  972. * In addition to optional path arguments, the page callback and other callback
  973. * functions may specify argument lists as arrays. These argument lists may
  974. * contain both fixed/hard-coded argument values and integers that correspond
  975. * to path components. When integers are used and the callback function is
  976. * called, the corresponding path components will be substituted for the
  977. * integers. That is, the integer 0 in an argument list will be replaced with
  978. * the first path component, integer 1 with the second, and so on (path
  979. * components are numbered starting from zero). To pass an integer without it
  980. * being replaced with its respective path component, use the string value of
  981. * the integer (e.g., '1') as the argument value. This substitution feature
  982. * allows you to re-use a callback function for several different paths. For
  983. * example:
  984. * @code
  985. * function mymodule_menu() {
  986. * $items['abc/def'] = array(
  987. * 'page callback' => 'mymodule_abc_view',
  988. * 'page arguments' => array(1, 'foo'),
  989. * );
  990. * return $items;
  991. * }
  992. * @endcode
  993. * When path 'abc/def' is requested, the page callback function will get 'def'
  994. * as the first argument and (always) 'foo' as the second argument.
  995. *
  996. * If a page callback function uses an argument list array, and its path is
  997. * requested with optional path arguments, then the list array's arguments are
  998. * passed to the callback function first, followed by the optional path
  999. * arguments. Using the above example, when path 'abc/def/bar/baz' is requested,
  1000. * mymodule_abc_view() will be called with 'def', 'foo', 'bar' and 'baz' as
  1001. * arguments, in that order.
  1002. *
  1003. * Special care should be taken for the page callback drupal_get_form(), because
  1004. * your specific form callback function will always receive $form and
  1005. * &$form_state as the first function arguments:
  1006. * @code
  1007. * function mymodule_abc_form($form, &$form_state) {
  1008. * // ...
  1009. * return $form;
  1010. * }
  1011. * @endcode
  1012. * See @link form_api Form API documentation @endlink for details.
  1013. *
  1014. * @section sec_path_wildcards Wildcards in Paths
  1015. * @subsection sub_simple_wildcards Simple Wildcards
  1016. * Wildcards within paths also work with integer substitution. For example,
  1017. * your module could register path 'my-module/%/edit':
  1018. * @code
  1019. * $items['my-module/%/edit'] = array(
  1020. * 'page callback' => 'mymodule_abc_edit',
  1021. * 'page arguments' => array(1),
  1022. * );
  1023. * @endcode
  1024. * When path 'my-module/foo/edit' is requested, integer 1 will be replaced
  1025. * with 'foo' and passed to the callback function. Note that wildcards may not
  1026. * be used as the first component.
  1027. *
  1028. * @subsection sub_autoload_wildcards Auto-Loader Wildcards
  1029. * Registered paths may also contain special "auto-loader" wildcard components
  1030. * in the form of '%mymodule_abc', where the '%' part means that this path
  1031. * component is a wildcard, and the 'mymodule_abc' part defines the prefix for a
  1032. * load function, which here would be named mymodule_abc_load(). When a matching
  1033. * path is requested, your load function will receive as its first argument the
  1034. * path component in the position of the wildcard; load functions may also be
  1035. * passed additional arguments (see "load arguments" in the return value
  1036. * section below). For example, your module could register path
  1037. * 'my-module/%mymodule_abc/edit':
  1038. * @code
  1039. * $items['my-module/%mymodule_abc/edit'] = array(
  1040. * 'page callback' => 'mymodule_abc_edit',
  1041. * 'page arguments' => array(1),
  1042. * );
  1043. * @endcode
  1044. * When path 'my-module/123/edit' is requested, your load function
  1045. * mymodule_abc_load() will be invoked with the argument '123', and should
  1046. * load and return an "abc" object with internal id 123:
  1047. * @code
  1048. * function mymodule_abc_load($abc_id) {
  1049. * return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
  1050. * }
  1051. * @endcode
  1052. * This 'abc' object will then be passed into the callback functions defined
  1053. * for the menu item, such as the page callback function mymodule_abc_edit()
  1054. * to replace the integer 1 in the argument array. Note that a load function
  1055. * should return FALSE when it is unable to provide a loadable object. For
  1056. * example, the node_load() function for the 'node/%node/edit' menu item will
  1057. * return FALSE for the path 'node/999/edit' if a node with a node ID of 999
  1058. * does not exist. The menu routing system will return a 404 error in this case.
  1059. *
  1060. * @subsection sub_argument_wildcards Argument Wildcards
  1061. * You can also define a %wildcard_to_arg() function (for the example menu
  1062. * entry above this would be 'mymodule_abc_to_arg()'). The _to_arg() function
  1063. * is invoked to retrieve a value that is used in the path in place of the
  1064. * wildcard. A good example is user.module, which defines
  1065. * user_uid_optional_to_arg() (corresponding to the menu entry
  1066. * 'tracker/%user_uid_optional'). This function returns the user ID of the
  1067. * current user.
  1068. *
  1069. * The _to_arg() function will get called with three arguments:
  1070. * - $arg: A string representing whatever argument may have been supplied by
  1071. * the caller (this is particularly useful if you want the _to_arg()
  1072. * function only supply a (default) value if no other value is specified,
  1073. * as in the case of user_uid_optional_to_arg().
  1074. * - $map: An array of all path fragments (e.g. array('node','123','edit') for
  1075. * 'node/123/edit').
  1076. * - $index: An integer indicating which element of $map corresponds to $arg.
  1077. *
  1078. * _load() and _to_arg() functions may seem similar at first glance, but they
  1079. * have different purposes and are called at different times. _load()
  1080. * functions are called when the menu system is collecting arguments to pass
  1081. * to the callback functions defined for the menu item. _to_arg() functions
  1082. * are called when the menu system is generating links to related paths, such
  1083. * as the tabs for a set of MENU_LOCAL_TASK items.
  1084. *
  1085. * @section sec_render_tabs Rendering Menu Items As Tabs
  1086. * You can also make groups of menu items to be rendered (by default) as tabs
  1087. * on a page. To do that, first create one menu item of type MENU_NORMAL_ITEM,
  1088. * with your chosen path, such as 'foo'. Then duplicate that menu item, using a
  1089. * subdirectory path, such as 'foo/tab1', and changing the type to
  1090. * MENU_DEFAULT_LOCAL_TASK to make it the default tab for the group. Then add
  1091. * the additional tab items, with paths such as "foo/tab2" etc., with type
  1092. * MENU_LOCAL_TASK. Example:
  1093. * @code
  1094. * // Make "Foo settings" appear on the admin Config page
  1095. * $items['admin/config/system/foo'] = array(
  1096. * 'title' => 'Foo settings',
  1097. * 'type' => MENU_NORMAL_ITEM,
  1098. * // Page callback, etc. need to be added here.
  1099. * );
  1100. * // Make "Tab 1" the main tab on the "Foo settings" page
  1101. * $items['admin/config/system/foo/tab1'] = array(
  1102. * 'title' => 'Tab 1',
  1103. * 'type' => MENU_DEFAULT_LOCAL_TASK,
  1104. * // Access callback, page callback, and theme callback will be inherited
  1105. * // from 'admin/config/system/foo', if not specified here to override.
  1106. * );
  1107. * // Make an additional tab called "Tab 2" on "Foo settings"
  1108. * $items['admin/config/system/foo/tab2'] = array(
  1109. * 'title' => 'Tab 2',
  1110. * 'type' => MENU_LOCAL_TASK,
  1111. * // Page callback and theme callback will be inherited from
  1112. * // 'admin/config/system/foo', if not specified here to override.
  1113. * // Need to add access callback or access arguments.
  1114. * );
  1115. * @endcode
  1116. *
  1117. * @return
  1118. * An array of menu items. Each menu item has a key corresponding to the
  1119. * Drupal path being registered. The corresponding array value is an
  1120. * associative array that may contain the following key-value pairs:
  1121. * - "title": Required. The untranslated title of the menu item.
  1122. * - "title callback": Function to generate the title; defaults to t().
  1123. * If you require only the raw string to be output, set this to FALSE.
  1124. * - "title arguments": Arguments to send to t() or your custom callback,
  1125. * with path component substitution as described above.
  1126. * - "description": The untranslated description of the menu item.
  1127. * - "page callback": The function to call to display a web page when the user
  1128. * visits the path. If omitted, the parent menu item's callback will be used
  1129. * instead.
  1130. * - "page arguments": An array of arguments to pass to the page callback
  1131. * function, with path component substitution as described above.
  1132. * - "delivery callback": The function to call to package the result of the
  1133. * page callback function and send it to the browser. Defaults to
  1134. * drupal_deliver_html_page() unless a value is inherited from a parent menu
  1135. * item. Note that this function is called even if the access checks fail,
  1136. * so any custom delivery callback function should take that into account.
  1137. * See drupal_deliver_html_page() for an example.
  1138. * - "access callback": A function returning TRUE if the user has access
  1139. * rights to this menu item, and FALSE if not. It can also be a boolean
  1140. * constant instead of a function, and you can also use numeric values
  1141. * (will be cast to boolean). Defaults to user_access() unless a value is
  1142. * inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items
  1143. * can inherit access callbacks. To use the user_access() default callback,
  1144. * you must specify the permission to check as 'access arguments' (see
  1145. * below).
  1146. * - "access arguments": An array of arguments to pass to the access callback
  1147. * function, with path component substitution as described above. If the
  1148. * access callback is inherited (see above), the access arguments will be
  1149. * inherited with it, unless overridden in the child menu item.
  1150. * - "theme callback": (optional) A function returning the machine-readable
  1151. * name of the theme that will be used to render the page. If not provided,
  1152. * the value will be inherited from a parent menu item. If there is no
  1153. * theme callback, or if the function does not return the name of a current
  1154. * active theme on the site, the theme for this page will be determined by
  1155. * either hook_custom_theme() or the default theme instead. As a general
  1156. * rule, the use of theme callback functions should be limited to pages
  1157. * whose functionality is very closely tied to a particular theme, since
  1158. * they can only be overridden by modules which specifically target those
  1159. * pages in hook_menu_alter(). Modules implementing more generic theme
  1160. * switching functionality (for example, a module which allows the theme to
  1161. * be set dynamically based on the current user's role) should use
  1162. * hook_custom_theme() instead.
  1163. * - "theme arguments": An array of arguments to pass to the theme callback
  1164. * function, with path component substitution as described above.
  1165. * - "file": A file that will be included before the page callback is called;
  1166. * this allows page callback functions to be in separate files. The file
  1167. * should be relative to the implementing module's directory unless
  1168. * otherwise specified by the "file path" option. Does not apply to other
  1169. * callbacks (only page callback).
  1170. * - "file path": The path to the directory containing the file specified in
  1171. * "file". This defaults to the path to the module implementing the hook.
  1172. * - "load arguments": An array of arguments to be passed to each of the
  1173. * wildcard object loaders in the path, after the path argument itself.
  1174. * For example, if a module registers path node/%node/revisions/%/view
  1175. * with load arguments set to array(3), the '%node' in the path indicates
  1176. * that the loader function node_load() will be called with the second
  1177. * path component as the first argument. The 3 in the load arguments
  1178. * indicates that the fourth path component will also be passed to
  1179. * node_load() (numbering of path components starts at zero). So, if path
  1180. * node/12/revisions/29/view is requested, node_load(12, 29) will be called.
  1181. * There are also two "magic" values that can be used in load arguments.
  1182. * "%index" indicates the index of the wildcard path component. "%map"
  1183. * indicates the path components as an array. For example, if a module
  1184. * registers for several paths of the form 'user/%user_category/edit/*', all
  1185. * of them can use the same load function user_category_load(), by setting
  1186. * the load arguments to array('%map', '%index'). For instance, if the user
  1187. * is editing category 'foo' by requesting path 'user/32/edit/foo', the load
  1188. * function user_category_load() will be called with 32 as its first
  1189. * argument, the array ('user', 32, 'edit', 'foo') as the map argument,
  1190. * and 1 as the index argument (because %user_category is the second path
  1191. * component and numbering starts at zero). user_category_load() can then
  1192. * use these values to extract the information that 'foo' is the category
  1193. * being requested.
  1194. * - "weight": An integer that determines the relative position of items in
  1195. * the menu; higher-weighted items sink. Defaults to 0. Menu items with the
  1196. * same weight are ordered alphabetically.
  1197. * - "menu_name": Optional. Set this to a custom menu if you don't want your
  1198. * item to be placed in Navigation.
  1199. * - "expanded": Optional. If set to TRUE, and if a menu link is provided for
  1200. * this menu item (as a result of other properties), then the menu link is
  1201. * always expanded, equivalent to its 'always expanded' checkbox being set
  1202. * in the UI.
  1203. * - "context": (optional) Defines the context a tab may appear in. By
  1204. * default, all tabs are only displayed as local tasks when being rendered
  1205. * in a page context. All tabs that should be accessible as contextual links
  1206. * in page region containers outside of the parent menu item's primary page
  1207. * context should be registered using one of the following contexts:
  1208. * - MENU_CONTEXT_PAGE: (default) The tab is displayed as local task for the
  1209. * page context only.
  1210. * - MENU_CONTEXT_INLINE: The tab is displayed as contextual link outside of
  1211. * the primary page context only.
  1212. * Contexts can be combined. For example, to display a tab both on a page
  1213. * and inline, a menu router item may specify:
  1214. * @code
  1215. * 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  1216. * @endcode
  1217. * - "tab_parent": For local task menu items, the path of the task's parent
  1218. * item; defaults to the same path without the last component (e.g., the
  1219. * default parent for 'admin/people/create' is 'admin/people').
  1220. * - "tab_root": For local task menu items, the path of the closest non-tab
  1221. * item; same default as "tab_parent".
  1222. * - "position": Position of the block ('left' or 'right') on the system
  1223. * administration page for this item.
  1224. * - "type": A bitmask of flags describing properties of the menu item.
  1225. * Many shortcut bitmasks are provided as constants in menu.inc:
  1226. * - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be
  1227. * moved/hidden by the administrator.
  1228. * - MENU_CALLBACK: Callbacks simply register a path so that the correct
  1229. * information is generated when the path is accessed.
  1230. * - MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the
  1231. * administrator may enable.
  1232. * - MENU_LOCAL_ACTION: Local actions are menu items that describe actions
  1233. * on the parent item such as adding a new user or block, and are
  1234. * rendered in the action-links list in your theme.
  1235. * - MENU_LOCAL_TASK: Local tasks are menu items that describe different
  1236. * displays of data, and are generally rendered as tabs.
  1237. * - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one
  1238. * "default" task, which should display the same page as the parent item.
  1239. * If the "type" element is omitted, MENU_NORMAL_ITEM is assumed.
  1240. * - "options": An array of options to be passed to l() when generating a link
  1241. * from this menu item. Note that the "options" parameter has no effect on
  1242. * MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, and MENU_LOCAL_ACTION items.
  1243. *
  1244. * For a detailed usage example, see page_example.module.
  1245. * For comprehensive documentation on the menu system, see
  1246. * http://drupal.org/node/102338.
  1247. */
  1248. function hook_menu() {
  1249. $items['example'] = array(
  1250. 'title' => 'Example Page',
  1251. 'page callback' => 'example_page',
  1252. 'access arguments' => array('access content'),
  1253. 'type' => MENU_SUGGESTED_ITEM,
  1254. );
  1255. $items['example/feed'] = array(
  1256. 'title' => 'Example RSS feed',
  1257. 'page callback' => 'example_feed',
  1258. 'access arguments' => array('access content'),
  1259. 'type' => MENU_CALLBACK,
  1260. );
  1261. return $items;
  1262. }
  1263. /**
  1264. * Alter the data being saved to the {menu_router} table after hook_menu is invoked.
  1265. *
  1266. * This hook is invoked by menu_router_build(). The menu definitions are passed
  1267. * in by reference. Each element of the $items array is one item returned
  1268. * by a module from hook_menu. Additional items may be added, or existing items
  1269. * altered.
  1270. *
  1271. * @param $items
  1272. * Associative array of menu router definitions returned from hook_menu().
  1273. */
  1274. function hook_menu_alter(&$items) {
  1275. // Example - disable the page at node/add
  1276. $items['node/add']['access callback'] = FALSE;
  1277. }
  1278. /**
  1279. * Alter the data being saved to the {menu_links} table by menu_link_save().
  1280. *
  1281. * @param $item
  1282. * Associative array defining a menu link as passed into menu_link_save().
  1283. *
  1284. * @see hook_translated_menu_link_alter()
  1285. */
  1286. function hook_menu_link_alter(&$item) {
  1287. // Make all new admin links hidden (a.k.a disabled).
  1288. if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
  1289. $item['hidden'] = 1;
  1290. }
  1291. // Flag a link to be altered by hook_translated_menu_link_alter().
  1292. if ($item['link_path'] == 'devel/cache/clear') {
  1293. $item['options']['alter'] = TRUE;
  1294. }
  1295. // Flag a link to be altered by hook_translated_menu_link_alter(), but only
  1296. // if it is derived from a menu router item; i.e., do not alter a custom
  1297. // menu link pointing to the same path that has been created by a user.
  1298. if ($item['link_path'] == 'user' && $item['module'] == 'system') {
  1299. $item['options']['alter'] = TRUE;
  1300. }
  1301. }
  1302. /**
  1303. * Alter a menu link after it has been translated and before it is rendered.
  1304. *
  1305. * This hook is invoked from _menu_link_translate() after a menu link has been
  1306. * translated; i.e., after dynamic path argument placeholders (%) have been
  1307. * replaced with actual values, the user access to the link's target page has
  1308. * been checked, and the link has been localized. It is only invoked if
  1309. * $item['options']['alter'] has been set to a non-empty value (e.g., TRUE).
  1310. * This flag should be set using hook_menu_link_alter().
  1311. *
  1312. * Implementations of this hook are able to alter any property of the menu link.
  1313. * For example, this hook may be used to add a page-specific query string to all
  1314. * menu links, or hide a certain link by setting:
  1315. * @code
  1316. * 'hidden' => 1,
  1317. * @endcode
  1318. *
  1319. * @param $item
  1320. * Associative array defining a menu link after _menu_link_translate()
  1321. * @param $map
  1322. * Associative array containing the menu $map (path parts and/or objects).
  1323. *
  1324. * @see hook_menu_link_alter()
  1325. */
  1326. function hook_translated_menu_link_alter(&$item, $map) {
  1327. if ($item['href'] == 'devel/cache/clear') {
  1328. $item['localized_options']['query'] = drupal_get_destination();
  1329. }
  1330. }
  1331. /**
  1332. * Inform modules that a menu link has been created.
  1333. *
  1334. * This hook is used to notify modules that menu items have been
  1335. * created. Contributed modules may use the information to perform
  1336. * actions based on the information entered into the menu system.
  1337. *
  1338. * @param $link
  1339. * Associative array defining a menu link as passed into menu_link_save().
  1340. *
  1341. * @see hook_menu_link_update()
  1342. * @see hook_menu_link_delete()
  1343. */
  1344. function hook_menu_link_insert($link) {
  1345. // In our sample case, we track menu items as editing sections
  1346. // of the site. These are stored in our table as 'disabled' items.
  1347. $record['mlid'] = $link['mlid'];
  1348. $record['menu_name'] = $link['menu_name'];
  1349. $record['status'] = 0;
  1350. drupal_write_record('menu_example', $record);
  1351. }
  1352. /**
  1353. * Inform modules that a menu link has been updated.
  1354. *
  1355. * This hook is used to notify modules that menu items have been
  1356. * updated. Contributed modules may use the information to perform
  1357. * actions based on the information entered into the menu system.
  1358. *
  1359. * @param $link
  1360. * Associative array defining a menu link as passed into menu_link_save().
  1361. *
  1362. * @see hook_menu_link_insert()
  1363. * @see hook_menu_link_delete()
  1364. */
  1365. function hook_menu_link_update($link) {
  1366. // If the parent menu has changed, update our record.
  1367. $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchField();
  1368. if ($menu_name != $link['menu_name']) {
  1369. db_update('menu_example')
  1370. ->fields(array('menu_name' => $link['menu_name']))
  1371. ->condition('mlid', $link['mlid'])
  1372. ->execute();
  1373. }
  1374. }
  1375. /**
  1376. * Inform modules that a menu link has been deleted.
  1377. *
  1378. * This hook is used to notify modules that menu items have been
  1379. * deleted. Contributed modules may use the information to perform
  1380. * actions based on the information entered into the menu system.
  1381. *
  1382. * @param $link
  1383. * Associative array defining a menu link as passed into menu_link_save().
  1384. *
  1385. * @see hook_menu_link_insert()
  1386. * @see hook_menu_link_update()
  1387. */
  1388. function hook_menu_link_delete($link) {
  1389. // Delete the record from our table.
  1390. db_delete('menu_example')
  1391. ->condition('mlid', $link['mlid'])
  1392. ->execute();
  1393. }
  1394. /**
  1395. * Alter tabs and actions displayed on the page before they are rendered.
  1396. *
  1397. * This hook is invoked by menu_local_tasks(). The system-determined tabs and
  1398. * actions are passed in by reference. Additional tabs or actions may be added,
  1399. * or existing items altered.
  1400. *
  1401. * Each tab or action is an associative array containing:
  1402. * - #theme: The theme function to use to render.
  1403. * - #link: An associative array containing:
  1404. * - title: The localized title of the link.
  1405. * - href: The system path to link to.
  1406. * - localized_options: An array of options to pass to l().
  1407. * - #active: Whether the link should be marked as 'active'.
  1408. *
  1409. * @param $data
  1410. * An associative array containing:
  1411. * - actions: An associative array containing:
  1412. * - count: The amount of actions determined by the menu system, which can
  1413. * be ignored.
  1414. * - output: A list of of actions, each one being an associative array
  1415. * as described above.
  1416. * - tabs: An indexed array (list) of tab levels (up to 2 levels), each
  1417. * containing an associative array:
  1418. * - count: The amount of tabs determined by the menu system. This value
  1419. * does not need to be altered if there is more than one tab.
  1420. * - output: A list of of tabs, each one being an associative array as
  1421. * described above.
  1422. * @param $router_item
  1423. * The menu system router item of the page.
  1424. * @param $root_path
  1425. * The path to the root item for this set of tabs.
  1426. */
  1427. function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  1428. // Add an action linking to node/add to all pages.
  1429. $data['actions']['output'][] = array(
  1430. '#theme' => 'menu_local_task',
  1431. '#link' => array(
  1432. 'title' => t('Add new content'),
  1433. 'href' => 'node/add',
  1434. 'localized_options' => array(
  1435. 'attributes' => array(
  1436. 'title' => t('Add new content'),
  1437. ),
  1438. ),
  1439. ),
  1440. );
  1441. // Add a tab linking to node/add to all pages.
  1442. $data['tabs'][0]['output'][] = array(
  1443. '#theme' => 'menu_local_task',
  1444. '#link' => array(
  1445. 'title' => t('Example tab'),
  1446. 'href' => 'node/add',
  1447. 'localized_options' => array(
  1448. 'attributes' => array(
  1449. 'title' => t('Add new content'),
  1450. ),
  1451. ),
  1452. ),
  1453. // Define whether this link is active. This can be omitted for
  1454. // implementations that add links to pages outside of the current page
  1455. // context.
  1456. '#active' => ($router_item['path'] == $root_path),
  1457. );
  1458. }
  1459. /**
  1460. * Alter links in the active trail before it is rendered as the breadcrumb.
  1461. *
  1462. * This hook is invoked by menu_get_active_breadcrumb() and allows alteration
  1463. * of the breadcrumb links for the current page, which may be preferred instead
  1464. * of setting a custom breadcrumb via drupal_set_breadcrumb().
  1465. *
  1466. * Implementations should take into account that menu_get_active_breadcrumb()
  1467. * subsequently performs the following adjustments to the active trail *after*
  1468. * this hook has been invoked:
  1469. * - The last link in $active_trail is removed, if its 'href' is identical to
  1470. * the 'href' of $item. This happens, because the breadcrumb normally does
  1471. * not contain a link to the current page.
  1472. * - The (second to) last link in $active_trail is removed, if the current $item
  1473. * is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link
  1474. * to the current page, when being on the path for the default local task;
  1475. * e.g. when being on the path node/%/view, the breadcrumb should not contain
  1476. * a link to node/%.
  1477. *
  1478. * Each link in the active trail must contain:
  1479. * - title: The localized title of the link.
  1480. * - href: The system path to link to.
  1481. * - localized_options: An array of options to pass to url().
  1482. *
  1483. * @param $active_trail
  1484. * An array containing breadcrumb links for the current page.
  1485. * @param $item
  1486. * The menu router item of the current page.
  1487. *
  1488. * @see drupal_set_breadcrumb()
  1489. * @see menu_get_active_breadcrumb()
  1490. * @see menu_get_active_trail()
  1491. * @see menu_set_active_trail()
  1492. */
  1493. function hook_menu_breadcrumb_alter(&$active_trail, $item) {
  1494. // Always display a link to the current page by duplicating the last link in
  1495. // the active trail. This means that menu_get_active_breadcrumb() will remove
  1496. // the last link (for the current page), but since it is added once more here,
  1497. // it will appear.
  1498. if (!drupal_is_front_page()) {
  1499. $end = end($active_trail);
  1500. if ($item['href'] == $end['href']) {
  1501. $active_trail[] = $end;
  1502. }
  1503. }
  1504. }
  1505. /**
  1506. * Alter contextual links before they are rendered.
  1507. *
  1508. * This hook is invoked by menu_contextual_links(). The system-determined
  1509. * contextual links are passed in by reference. Additional links may be added
  1510. * or existing links can be altered.
  1511. *
  1512. * Each contextual link must at least contain:
  1513. * - title: The localized title of the link.
  1514. * - href: The system path to link to.
  1515. * - localized_options: An array of options to pass to url().
  1516. *
  1517. * @param $links
  1518. * An associative array containing contextual links for the given $root_path,
  1519. * as described above. The array keys are used to build CSS class names for
  1520. * contextual links and must therefore be unique for each set of contextual
  1521. * links.
  1522. * @param $router_item
  1523. * The menu router item belonging to the $root_path being requested.
  1524. * @param $root_path
  1525. * The (parent) path that has been requested to build contextual links for.
  1526. * This is a normalized path, which means that an originally passed path of
  1527. * 'node/123' became 'node/%'.
  1528. *
  1529. * @see hook_contextual_links_view_alter()
  1530. * @see menu_contextual_links()
  1531. * @see hook_menu()
  1532. * @see contextual_preprocess()
  1533. */
  1534. function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) {
  1535. // Add a link to all contextual links for nodes.
  1536. if ($root_path == 'node/%') {
  1537. $links['foo'] = array(
  1538. 'title' => t('Do fu'),
  1539. 'href' => 'foo/do',
  1540. 'localized_options' => array(
  1541. 'query' => array(
  1542. 'foo' => 'bar',
  1543. ),
  1544. ),
  1545. );
  1546. }
  1547. }
  1548. /**
  1549. * Perform alterations before a page is rendered.
  1550. *
  1551. * Use this hook when you want to remove or alter elements at the page
  1552. * level, or add elements at the page level that depend on an other module's
  1553. * elements (this hook runs after hook_page_build().
  1554. *
  1555. * If you are making changes to entities such as forms, menus, or user
  1556. * profiles, use those objects' native alter hooks instead (hook_form_alter(),
  1557. * for example).
  1558. *
  1559. * The $page array contains top level elements for each block region:
  1560. * @code
  1561. * $page['page_top']
  1562. * $page['header']
  1563. * $page['sidebar_first']
  1564. * $page['content']
  1565. * $page['sidebar_second']
  1566. * $page['page_bottom']
  1567. * @endcode
  1568. *
  1569. * The 'content' element contains the main content of the current page, and its
  1570. * structure will vary depending on what module is responsible for building the
  1571. * page. Some legacy modules may not return structured content at all: their
  1572. * pre-rendered markup will be located in $page['content']['main']['#markup'].
  1573. *
  1574. * Pages built by Drupal's core Node and Blog modules use a standard structure:
  1575. *
  1576. * @code
  1577. * // Node body.
  1578. * $page['content']['system_main']['nodes'][$nid]['body']
  1579. * // Array of links attached to the node (add comments, read more).
  1580. * $page['content']['system_main']['nodes'][$nid]['links']
  1581. * // The node object itself.
  1582. * $page['content']['system_main']['nodes'][$nid]['#node']
  1583. * // The results pager.
  1584. * $page['content']['system_main']['pager']
  1585. * @endcode
  1586. *
  1587. * Blocks may be referenced by their module/delta pair within a region:
  1588. * @code
  1589. * // The login block in the first sidebar region.
  1590. * $page['sidebar_first']['user_login']['#block'];
  1591. * @endcode
  1592. *
  1593. * @param $page
  1594. * Nested array of renderable elements that make up the page.
  1595. *
  1596. * @see hook_page_build()
  1597. * @see drupal_render_page()
  1598. */
  1599. function hook_page_alter(&$page) {
  1600. // Add help text to the user login block.
  1601. $page['sidebar_first']['user_login']['help'] = array(
  1602. '#weight' => -10,
  1603. '#markup' => t('To post comments or add new content, you first have to log in.'),
  1604. );
  1605. }
  1606. /**
  1607. * Perform alterations before a form is rendered.
  1608. *
  1609. * One popular use of this hook is to add form elements to the node form. When
  1610. * altering a node form, the node object can be accessed at $form['#node'].
  1611. *
  1612. * In addition to hook_form_alter(), which is called for all forms, there are
  1613. * two more specific form hooks available. The first,
  1614. * hook_form_BASE_FORM_ID_alter(), allows targeting of a form/forms via a base
  1615. * form (if one exists). The second, hook_form_FORM_ID_alter(), can be used to
  1616. * target a specific form directly.
  1617. *
  1618. * The call order is as follows: all existing form alter functions are called
  1619. * for module A, then all for module B, etc., followed by all for any base
  1620. * theme(s), and finally for the theme itself. The module order is determined
  1621. * by system weight, then by module name.
  1622. *
  1623. * Within each module, form alter hooks are called in the following order:
  1624. * first, hook_form_alter(); second, hook_form_BASE_FORM_ID_alter(); third,
  1625. * hook_form_FORM_ID_alter(). So, for each module, the more general hooks are
  1626. * called first followed by the more specific.
  1627. *
  1628. * @param $form
  1629. * Nested array of form elements that comprise the form.
  1630. * @param $form_state
  1631. * A keyed array containing the current state of the form. The arguments
  1632. * that drupal_get_form() was originally called with are available in the
  1633. * array $form_state['build_info']['args'].
  1634. * @param $form_id
  1635. * String representing the name of the form itself. Typically this is the
  1636. * name of the function that generated the form.
  1637. *
  1638. * @see hook_form_BASE_FORM_ID_alter()
  1639. * @see hook_form_FORM_ID_alter()
  1640. * @see forms_api_reference.html
  1641. */
  1642. function hook_form_alter(&$form, &$form_state, $form_id) {
  1643. if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) {
  1644. $form['workflow']['upload_' . $form['type']['#value']] = array(
  1645. '#type' => 'radios',
  1646. '#title' => t('Attachments'),
  1647. '#default_value' => variable_get('upload_' . $form['type']['#value'], 1),
  1648. '#options' => array(t('Disabled'), t('Enabled')),
  1649. );
  1650. }
  1651. }
  1652. /**
  1653. * Provide a form-specific alteration instead of the global hook_form_alter().
  1654. *
  1655. * Modules can implement hook_form_FORM_ID_alter() to modify a specific form,
  1656. * rather than implementing hook_form_alter() and checking the form ID, or
  1657. * using long switch statements to alter multiple forms.
  1658. *
  1659. * Form alter hooks are called in the following order: hook_form_alter(),
  1660. * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See
  1661. * hook_form_alter() for more details.
  1662. *
  1663. * @param $form
  1664. * Nested array of form elements that comprise the form.
  1665. * @param $form_state
  1666. * A keyed array containing the current state of the form. The arguments
  1667. * that drupal_get_form() was originally called with are available in the
  1668. * array $form_state['build_info']['args'].
  1669. * @param $form_id
  1670. * String representing the name of the form itself. Typically this is the
  1671. * name of the function that generated the form.
  1672. *
  1673. * @see hook_form_alter()
  1674. * @see hook_form_BASE_FORM_ID_alter()
  1675. * @see drupal_prepare_form()
  1676. * @see forms_api_reference.html
  1677. */
  1678. function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
  1679. // Modification for the form with the given form ID goes here. For example, if
  1680. // FORM_ID is "user_register_form" this code would run only on the user
  1681. // registration form.
  1682. // Add a checkbox to registration form about agreeing to terms of use.
  1683. $form['terms_of_use'] = array(
  1684. '#type' => 'checkbox',
  1685. '#title' => t("I agree with the website's terms and conditions."),
  1686. '#required' => TRUE,
  1687. );
  1688. }
  1689. /**
  1690. * Provide a form-specific alteration for shared ('base') forms.
  1691. *
  1692. * By default, when drupal_get_form() is called, Drupal looks for a function
  1693. * with the same name as the form ID, and uses that function to build the form.
  1694. * In contrast, base forms allow multiple form IDs to be mapped to a single base
  1695. * (also called 'factory') form function.
  1696. *
  1697. * Modules can implement hook_form_BASE_FORM_ID_alter() to modify a specific
  1698. * base form, rather than implementing hook_form_alter() and checking for
  1699. * conditions that would identify the shared form constructor.
  1700. *
  1701. * To identify the base form ID for a particular form (or to determine whether
  1702. * one exists) check the $form_state. The base form ID is stored under
  1703. * $form_state['build_info']['base_form_id'].
  1704. *
  1705. * See hook_forms() for more information on how to implement base forms in
  1706. * Drupal.
  1707. *
  1708. * Form alter hooks are called in the following order: hook_form_alter(),
  1709. * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See
  1710. * hook_form_alter() for more details.
  1711. *
  1712. * @param $form
  1713. * Nested array of form elements that comprise the form.
  1714. * @param $form_state
  1715. * A keyed array containing the current state of the form.
  1716. * @param $form_id
  1717. * String representing the name of the form itself. Typically this is the
  1718. * name of the function that generated the form.
  1719. *
  1720. * @see hook_form_alter()
  1721. * @see hook_form_FORM_ID_alter()
  1722. * @see drupal_prepare_form()
  1723. * @see hook_forms()
  1724. */
  1725. function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) {
  1726. // Modification for the form with the given BASE_FORM_ID goes here. For
  1727. // example, if BASE_FORM_ID is "node_form", this code would run on every
  1728. // node form, regardless of node type.
  1729. // Add a checkbox to the node form about agreeing to terms of use.
  1730. $form['terms_of_use'] = array(
  1731. '#type' => 'checkbox',
  1732. '#title' => t("I agree with the website's terms and conditions."),
  1733. '#required' => TRUE,
  1734. );
  1735. }
  1736. /**
  1737. * Map form_ids to form builder functions.
  1738. *
  1739. * By default, when drupal_get_form() is called, the system will look for a
  1740. * function with the same name as the form ID, and use that function to build
  1741. * the form. If no such function is found, Drupal calls this hook. Modules
  1742. * implementing this hook can then provide their own instructions for mapping
  1743. * form IDs to constructor functions. As a result, you can easily map multiple
  1744. * form IDs to a single form constructor (referred to as a 'base' form).
  1745. *
  1746. * Using a base form can help to avoid code duplication, by allowing many
  1747. * similar forms to use the same code base. Another benefit is that it becomes
  1748. * much easier for other modules to apply a general change to the group of
  1749. * forms; hook_form_BASE_FORM_ID_alter() can be used to easily alter multiple
  1750. * forms at once by directly targeting the shared base form.
  1751. *
  1752. * Two example use cases where base forms may be useful are given below.
  1753. *
  1754. * First, you can use this hook to tell the form system to use a different
  1755. * function to build certain forms in your module; this is often used to define
  1756. * a form "factory" function that is used to build several similar forms. In
  1757. * this case, your hook implementation will likely ignore all of the input
  1758. * arguments. See node_forms() for an example of this. Note, node_forms() is the
  1759. * hook_forms() implementation; the base form itself is defined in node_form().
  1760. *
  1761. * Second, you could use this hook to define how to build a form with a
  1762. * dynamically-generated form ID. In this case, you would need to verify that
  1763. * the $form_id input matched your module's format for dynamically-generated
  1764. * form IDs, and if so, act appropriately.
  1765. *
  1766. * @param $form_id
  1767. * The unique string identifying the desired form.
  1768. * @param $args
  1769. * An array containing the original arguments provided to drupal_get_form()
  1770. * or drupal_form_submit(). These are always passed to the form builder and
  1771. * do not have to be specified manually in 'callback arguments'.
  1772. *
  1773. * @return
  1774. * An associative array whose keys define form_ids and whose values are an
  1775. * associative array defining the following keys:
  1776. * - callback: The name of the form builder function to invoke. This will be
  1777. * used for the base form ID, for example, to target a base form using
  1778. * hook_form_BASE_FORM_ID_alter().
  1779. * - callback arguments: (optional) Additional arguments to pass to the
  1780. * function defined in 'callback', which are prepended to $args.
  1781. * - wrapper_callback: (optional) The name of a form builder function to
  1782. * invoke before the form builder defined in 'callback' is invoked. This
  1783. * wrapper callback may prepopulate the $form array with form elements,
  1784. * which will then be already contained in the $form that is passed on to
  1785. * the form builder defined in 'callback'. For example, a wrapper callback
  1786. * could setup wizard-alike form buttons that are the same for a variety of
  1787. * forms that belong to the wizard, which all share the same wrapper
  1788. * callback.
  1789. */
  1790. function hook_forms($form_id, $args) {
  1791. // Simply reroute the (non-existing) $form_id 'mymodule_first_form' to
  1792. // 'mymodule_main_form'.
  1793. $forms['mymodule_first_form'] = array(
  1794. 'callback' => 'mymodule_main_form',
  1795. );
  1796. // Reroute the $form_id and prepend an additional argument that gets passed to
  1797. // the 'mymodule_main_form' form builder function.
  1798. $forms['mymodule_second_form'] = array(
  1799. 'callback' => 'mymodule_main_form',
  1800. 'callback arguments' => array('some parameter'),
  1801. );
  1802. // Reroute the $form_id, but invoke the form builder function
  1803. // 'mymodule_main_form_wrapper' first, so we can prepopulate the $form array
  1804. // that is passed to the actual form builder 'mymodule_main_form'.
  1805. $forms['mymodule_wrapped_form'] = array(
  1806. 'callback' => 'mymodule_main_form',
  1807. 'wrapper_callback' => 'mymodule_main_form_wrapper',
  1808. );
  1809. return $forms;
  1810. }
  1811. /**
  1812. * Perform setup tasks for all page requests.
  1813. *
  1814. * This hook is run at the beginning of the page request. It is typically
  1815. * used to set up global parameters that are needed later in the request.
  1816. *
  1817. * Only use this hook if your code must run even for cached page views. This
  1818. * hook is called before the theme, modules, or most include files are loaded
  1819. * into memory. It happens while Drupal is still in bootstrap mode.
  1820. *
  1821. * @see hook_init()
  1822. */
  1823. function hook_boot() {
  1824. // We need user_access() in the shutdown function. Make sure it gets loaded.
  1825. drupal_load('module', 'user');
  1826. drupal_register_shutdown_function('devel_shutdown');
  1827. }
  1828. /**
  1829. * Perform setup tasks for non-cached page requests.
  1830. *
  1831. * This hook is run at the beginning of the page request. It is typically
  1832. * used to set up global parameters that are needed later in the request.
  1833. * When this hook is called, the theme and all modules are already loaded in
  1834. * memory.
  1835. *
  1836. * This hook is not run on cached pages.
  1837. *
  1838. * To add CSS or JS that should be present on all pages, modules should not
  1839. * implement this hook, but declare these files in their .info file.
  1840. *
  1841. * @see hook_boot()
  1842. */
  1843. function hook_init() {
  1844. // Since this file should only be loaded on the front page, it cannot be
  1845. // declared in the info file.
  1846. if (drupal_is_front_page()) {
  1847. drupal_add_css(drupal_get_path('module', 'foo') . '/foo.css');
  1848. }
  1849. }
  1850. /**
  1851. * Define image toolkits provided by this module.
  1852. *
  1853. * The file which includes each toolkit's functions must be included in this
  1854. * hook.
  1855. *
  1856. * The toolkit's functions must be named image_toolkitname_operation().
  1857. * where the operation may be:
  1858. * - 'load': Required. See image_gd_load() for usage.
  1859. * - 'save': Required. See image_gd_save() for usage.
  1860. * - 'settings': Optional. See image_gd_settings() for usage.
  1861. * - 'resize': Optional. See image_gd_resize() for usage.
  1862. * - 'rotate': Optional. See image_gd_rotate() for usage.
  1863. * - 'crop': Optional. See image_gd_crop() for usage.
  1864. * - 'desaturate': Optional. See image_gd_desaturate() for usage.
  1865. *
  1866. * @return
  1867. * An array with the toolkit name as keys and sub-arrays with these keys:
  1868. * - 'title': A string with the toolkit's title.
  1869. * - 'available': A Boolean value to indicate that the toolkit is operating
  1870. * properly, e.g. all required libraries exist.
  1871. *
  1872. * @see system_image_toolkits()
  1873. */
  1874. function hook_image_toolkits() {
  1875. return array(
  1876. 'working' => array(
  1877. 'title' => t('A toolkit that works.'),
  1878. 'available' => TRUE,
  1879. ),
  1880. 'broken' => array(
  1881. 'title' => t('A toolkit that is "broken" and will not be listed.'),
  1882. 'available' => FALSE,
  1883. ),
  1884. );
  1885. }
  1886. /**
  1887. * Alter an email message created with the drupal_mail() function.
  1888. *
  1889. * hook_mail_alter() allows modification of email messages created and sent
  1890. * with drupal_mail(). Usage examples include adding and/or changing message
  1891. * text, message fields, and message headers.
  1892. *
  1893. * Email messages sent using functions other than drupal_mail() will not
  1894. * invoke hook_mail_alter(). For example, a contributed module directly
  1895. * calling the drupal_mail_system()->mail() or PHP mail() function
  1896. * will not invoke this hook. All core modules use drupal_mail() for
  1897. * messaging, it is best practice but not mandatory in contributed modules.
  1898. *
  1899. * @param $message
  1900. * An array containing the message data. Keys in this array include:
  1901. * - 'id':
  1902. * The drupal_mail() id of the message. Look at module source code or
  1903. * drupal_mail() for possible id values.
  1904. * - 'to':
  1905. * The address or addresses the message will be sent to. The formatting of
  1906. * this string will be validated with the
  1907. * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
  1908. * - 'from':
  1909. * The address the message will be marked as being from, which is
  1910. * either a custom address or the site-wide default email address.
  1911. * - 'subject':
  1912. * Subject of the email to be sent. This must not contain any newline
  1913. * characters, or the email may not be sent properly.
  1914. * - 'body':
  1915. * An array of strings containing the message text. The message body is
  1916. * created by concatenating the individual array strings into a single text
  1917. * string using "\n\n" as a separator.
  1918. * - 'headers':
  1919. * Associative array containing mail headers, such as From, Sender,
  1920. * MIME-Version, Content-Type, etc.
  1921. * - 'params':
  1922. * An array of optional parameters supplied by the caller of drupal_mail()
  1923. * that is used to build the message before hook_mail_alter() is invoked.
  1924. * - 'language':
  1925. * The language object used to build the message before hook_mail_alter()
  1926. * is invoked.
  1927. * - 'send':
  1928. * Set to FALSE to abort sending this email message.
  1929. *
  1930. * @see drupal_mail()
  1931. */
  1932. function hook_mail_alter(&$message) {
  1933. if ($message['id'] == 'modulename_messagekey') {
  1934. if (!example_notifications_optin($message['to'], $message['id'])) {
  1935. // If the recipient has opted to not receive such messages, cancel
  1936. // sending.
  1937. $message['send'] = FALSE;
  1938. return;
  1939. }
  1940. $message['body'][] = "--\nMail sent out from " . variable_get('site_name', t('Drupal'));
  1941. }
  1942. }
  1943. /**
  1944. * Alter the registry of modules implementing a hook.
  1945. *
  1946. * This hook is invoked during module_implements(). A module may implement this
  1947. * hook in order to reorder the implementing modules, which are otherwise
  1948. * ordered by the module's system weight.
  1949. *
  1950. * Note that hooks invoked using drupal_alter() can have multiple variations
  1951. * (such as hook_form_alter() and hook_form_FORM_ID_alter()). drupal_alter()
  1952. * will call all such variants defined by a single module in turn. For the
  1953. * purposes of hook_module_implements_alter(), these variants are treated as
  1954. * a single hook. Thus, to ensure that your implementation of
  1955. * hook_form_FORM_ID_alter() is called at the right time, you will have to
  1956. * change the order of hook_form_alter() implementation in
  1957. * hook_module_implements_alter().
  1958. *
  1959. * @param $implementations
  1960. * An array keyed by the module's name. The value of each item corresponds
  1961. * to a $group, which is usually FALSE, unless the implementation is in a
  1962. * file named $module.$group.inc.
  1963. * @param $hook
  1964. * The name of the module hook being implemented.
  1965. */
  1966. function hook_module_implements_alter(&$implementations, $hook) {
  1967. if ($hook == 'rdf_mapping') {
  1968. // Move my_module_rdf_mapping() to the end of the list. module_implements()
  1969. // iterates through $implementations with a foreach loop which PHP iterates
  1970. // in the order that the items were added, so to move an item to the end of
  1971. // the array, we remove it and then add it.
  1972. $group = $implementations['my_module'];
  1973. unset($implementations['my_module']);
  1974. $implementations['my_module'] = $group;
  1975. }
  1976. }
  1977. /**
  1978. * Return additional themes provided by modules.
  1979. *
  1980. * Only use this hook for testing purposes. Use a hidden MYMODULE_test.module
  1981. * to implement this hook. Testing themes should be hidden, too.
  1982. *
  1983. * This hook is invoked from _system_rebuild_theme_data() and allows modules to
  1984. * register additional themes outside of the regular 'themes' directories of a
  1985. * Drupal installation.
  1986. *
  1987. * @return
  1988. * An associative array. Each key is the system name of a theme and each value
  1989. * is the corresponding path to the theme's .info file.
  1990. */
  1991. function hook_system_theme_info() {
  1992. $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info';
  1993. return $themes;
  1994. }
  1995. /**
  1996. * Alter the information parsed from module and theme .info files
  1997. *
  1998. * This hook is invoked in _system_rebuild_module_data() and in
  1999. * _system_rebuild_theme_data(). A module may implement this hook in order to
  2000. * add to or alter the data generated by reading the .info file with
  2001. * drupal_parse_info_file().
  2002. *
  2003. * @param $info
  2004. * The .info file contents, passed by reference so that it can be altered.
  2005. * @param $file
  2006. * Full information about the module or theme, including $file->name, and
  2007. * $file->filename
  2008. * @param $type
  2009. * Either 'module' or 'theme', depending on the type of .info file that was
  2010. * passed.
  2011. */
  2012. function hook_system_info_alter(&$info, $file, $type) {
  2013. // Only fill this in if the .info file does not define a 'datestamp'.
  2014. if (empty($info['datestamp'])) {
  2015. $info['datestamp'] = filemtime($file->filename);
  2016. }
  2017. }
  2018. /**
  2019. * Define user permissions.
  2020. *
  2021. * This hook can supply permissions that the module defines, so that they
  2022. * can be selected on the user permissions page and used to grant or restrict
  2023. * access to actions the module performs.
  2024. *
  2025. * Permissions are checked using user_access().
  2026. *
  2027. * For a detailed usage example, see page_example.module.
  2028. *
  2029. * @return
  2030. * An array whose keys are permission names and whose corresponding values
  2031. * are arrays containing the following key-value pairs:
  2032. * - title: The human-readable name of the permission, to be shown on the
  2033. * permission administration page. This should be wrapped in the t()
  2034. * function so it can be translated.
  2035. * - description: (optional) A description of what the permission does. This
  2036. * should be wrapped in the t() function so it can be translated.
  2037. * - restrict access: (optional) A boolean which can be set to TRUE to
  2038. * indicate that site administrators should restrict access to this
  2039. * permission to trusted users. This should be used for permissions that
  2040. * have inherent security risks across a variety of potential use cases
  2041. * (for example, the "administer filters" and "bypass node access"
  2042. * permissions provided by Drupal core). When set to TRUE, a standard
  2043. * warning message defined in user_admin_permissions() and output via
  2044. * theme_user_permission_description() will be associated with the
  2045. * permission and displayed with it on the permission administration page.
  2046. * Defaults to FALSE.
  2047. * - warning: (optional) A translated warning message to display for this
  2048. * permission on the permission administration page. This warning overrides
  2049. * the automatic warning generated by 'restrict access' being set to TRUE.
  2050. * This should rarely be used, since it is important for all permissions to
  2051. * have a clear, consistent security warning that is the same across the
  2052. * site. Use the 'description' key instead to provide any information that
  2053. * is specific to the permission you are defining.
  2054. *
  2055. * @see theme_user_permission_description()
  2056. */
  2057. function hook_permission() {
  2058. return array(
  2059. 'administer my module' => array(
  2060. 'title' => t('Administer my module'),
  2061. 'description' => t('Perform administration tasks for my module.'),
  2062. ),
  2063. );
  2064. }
  2065. /**
  2066. * Provide online user help.
  2067. *
  2068. * By implementing hook_help(), a module can make documentation available to
  2069. * the user for the module as a whole, or for specific paths. Help for
  2070. * developers should usually be provided via function header comments in the
  2071. * code, or in special API example files.
  2072. *
  2073. * The page-specific help information provided by this hook appears as a system
  2074. * help block on that page. The module overview help information is displayed
  2075. * by the Help module. It can be accessed from the page at admin/help or from
  2076. * the Modules page.
  2077. *
  2078. * For detailed usage examples of:
  2079. * - Module overview help, see node_help(). Module overview help should follow
  2080. * @link https://drupal.org/node/632280 the standard help template. @endlink
  2081. * - Page-specific help with simple paths, see dashboard_help().
  2082. * - Page-specific help using wildcards in path and $arg, see node_help()
  2083. * and block_help().
  2084. *
  2085. * @param $path
  2086. * The router menu path, as defined in hook_menu(), for the help that is
  2087. * being requested; e.g., 'admin/people' or 'user/register'. If the router
  2088. * path includes a wildcard, then this will appear in $path as %, even if it
  2089. * is a named %autoloader wildcard in the hook_menu() implementation; for
  2090. * example, node pages would have $path equal to 'node/%' or 'node/%/view'.
  2091. * For the help page for the module as a whole, $path will have the value
  2092. * 'admin/help#module_name', where 'module_name" is the machine name of your
  2093. * module.
  2094. * @param $arg
  2095. * An array that corresponds to the return value of the arg() function, for
  2096. * modules that want to provide help that is specific to certain values
  2097. * of wildcards in $path. For example, you could provide help for the path
  2098. * 'user/1' by looking for the path 'user/%' and $arg[1] == '1'. This given
  2099. * array should always be used rather than directly invoking arg(), because
  2100. * your hook implementation may be called for other purposes besides building
  2101. * the current page's help. Note that depending on which module is invoking
  2102. * hook_help, $arg may contain only empty strings. Regardless, $arg[0] to
  2103. * $arg[11] will always be set.
  2104. *
  2105. * @return
  2106. * A localized string containing the help text.
  2107. */
  2108. function hook_help($path, $arg) {
  2109. switch ($path) {
  2110. // Main module help for the block module
  2111. case 'admin/help#block':
  2112. return '<p>' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Bartik, for example, implements the regions "Sidebar first", "Sidebar second", "Featured", "Content", "Header", "Footer", etc., and a block may appear in any one of these areas. The <a href="@blocks">blocks administration page</a> provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions.', array('@blocks' => url('admin/structure/block'))) . '</p>';
  2113. // Help for another path in the block module
  2114. case 'admin/structure/block':
  2115. return '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>';
  2116. }
  2117. }
  2118. /**
  2119. * Register a module (or theme's) theme implementations.
  2120. *
  2121. * The implementations declared by this hook have two purposes: either they
  2122. * specify how a particular render array is to be rendered as HTML (this is
  2123. * usually the case if the theme function is assigned to the render array's
  2124. * #theme property), or they return the HTML that should be returned by an
  2125. * invocation of theme(). See
  2126. * @link http://drupal.org/node/933976 Using the theme layer Drupal 7.x @endlink
  2127. * for more information on how to implement theme hooks.
  2128. *
  2129. * The following parameters are all optional.
  2130. *
  2131. * @param array $existing
  2132. * An array of existing implementations that may be used for override
  2133. * purposes. This is primarily useful for themes that may wish to examine
  2134. * existing implementations to extract data (such as arguments) so that
  2135. * it may properly register its own, higher priority implementations.
  2136. * @param $type
  2137. * Whether a theme, module, etc. is being processed. This is primarily useful
  2138. * so that themes tell if they are the actual theme being called or a parent
  2139. * theme. May be one of:
  2140. * - 'module': A module is being checked for theme implementations.
  2141. * - 'base_theme_engine': A theme engine is being checked for a theme that is
  2142. * a parent of the actual theme being used.
  2143. * - 'theme_engine': A theme engine is being checked for the actual theme
  2144. * being used.
  2145. * - 'base_theme': A base theme is being checked for theme implementations.
  2146. * - 'theme': The actual theme in use is being checked.
  2147. * @param $theme
  2148. * The actual name of theme, module, etc. that is being being processed.
  2149. * @param $path
  2150. * The directory path of the theme or module, so that it doesn't need to be
  2151. * looked up.
  2152. *
  2153. * @return array
  2154. * An associative array of theme hook information. The keys on the outer
  2155. * array are the internal names of the hooks, and the values are arrays
  2156. * containing information about the hook. Each information array must contain
  2157. * either a 'variables' element or a 'render element' element, but not both.
  2158. * Use 'render element' if you are theming a single element or element tree
  2159. * composed of elements, such as a form array, a page array, or a single
  2160. * checkbox element. Use 'variables' if your theme implementation is
  2161. * intended to be called directly through theme() and has multiple arguments
  2162. * for the data and style; in this case, the variables not supplied by the
  2163. * calling function will be given default values and passed to the template
  2164. * or theme function. The returned theme information array can contain the
  2165. * following key/value pairs:
  2166. * - variables: (see above) Each array key is the name of the variable, and
  2167. * the value given is used as the default value if the function calling
  2168. * theme() does not supply it. Template implementations receive each array
  2169. * key as a variable in the template file (so they must be legal PHP
  2170. * variable names). Function implementations are passed the variables in a
  2171. * single $variables function argument.
  2172. * - render element: (see above) The name of the renderable element or element
  2173. * tree to pass to the theme function. This name is used as the name of the
  2174. * variable that holds the renderable element or tree in preprocess and
  2175. * process functions.
  2176. * - file: The file the implementation resides in. This file will be included
  2177. * prior to the theme being rendered, to make sure that the function or
  2178. * preprocess function (as needed) is actually loaded; this makes it
  2179. * possible to split theme functions out into separate files quite easily.
  2180. * - path: Override the path of the file to be used. Ordinarily the module or
  2181. * theme path will be used, but if the file will not be in the default
  2182. * path, include it here. This path should be relative to the Drupal root
  2183. * directory.
  2184. * - template: If specified, this theme implementation is a template, and
  2185. * this is the template file without an extension. Do not put .tpl.php on
  2186. * this file; that extension will be added automatically by the default
  2187. * rendering engine (which is PHPTemplate). If 'path', above, is specified,
  2188. * the template should also be in this path.
  2189. * - function: If specified, this will be the function name to invoke for
  2190. * this implementation. If neither 'template' nor 'function' is specified,
  2191. * a default function name will be assumed. For example, if a module
  2192. * registers the 'node' theme hook, 'theme_node' will be assigned to its
  2193. * function. If the chameleon theme registers the node hook, it will be
  2194. * assigned 'chameleon_node' as its function.
  2195. * - base hook: A string declaring the base theme hook if this theme
  2196. * implementation is actually implementing a suggestion for another theme
  2197. * hook.
  2198. * - pattern: A regular expression pattern to be used to allow this theme
  2199. * implementation to have a dynamic name. The convention is to use __ to
  2200. * differentiate the dynamic portion of the theme. For example, to allow
  2201. * forums to be themed individually, the pattern might be: 'forum__'. Then,
  2202. * when the forum is themed, call:
  2203. * @code
  2204. * theme(array('forum__' . $tid, 'forum'), $forum)
  2205. * @endcode
  2206. * - preprocess functions: A list of functions used to preprocess this data.
  2207. * Ordinarily this won't be used; it's automatically filled in. By default,
  2208. * for a module this will be filled in as template_preprocess_HOOK. For
  2209. * a theme this will be filled in as phptemplate_preprocess and
  2210. * phptemplate_preprocess_HOOK as well as themename_preprocess and
  2211. * themename_preprocess_HOOK.
  2212. * - override preprocess functions: Set to TRUE when a theme does NOT want
  2213. * the standard preprocess functions to run. This can be used to give a
  2214. * theme FULL control over how variables are set. For example, if a theme
  2215. * wants total control over how certain variables in the page.tpl.php are
  2216. * set, this can be set to true. Please keep in mind that when this is used
  2217. * by a theme, that theme becomes responsible for making sure necessary
  2218. * variables are set.
  2219. * - type: (automatically derived) Where the theme hook is defined:
  2220. * 'module', 'theme_engine', or 'theme'.
  2221. * - theme path: (automatically derived) The directory path of the theme or
  2222. * module, so that it doesn't need to be looked up.
  2223. *
  2224. * @see hook_theme_registry_alter()
  2225. */
  2226. function hook_theme($existing, $type, $theme, $path) {
  2227. return array(
  2228. 'forum_display' => array(
  2229. 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
  2230. ),
  2231. 'forum_list' => array(
  2232. 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
  2233. ),
  2234. 'forum_topic_list' => array(
  2235. 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
  2236. ),
  2237. 'forum_icon' => array(
  2238. 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),
  2239. ),
  2240. 'status_report' => array(
  2241. 'render element' => 'requirements',
  2242. 'file' => 'system.admin.inc',
  2243. ),
  2244. 'system_date_time_settings' => array(
  2245. 'render element' => 'form',
  2246. 'file' => 'system.admin.inc',
  2247. ),
  2248. );
  2249. }
  2250. /**
  2251. * Alter the theme registry information returned from hook_theme().
  2252. *
  2253. * The theme registry stores information about all available theme hooks,
  2254. * including which callback functions those hooks will call when triggered,
  2255. * what template files are exposed by these hooks, and so on.
  2256. *
  2257. * Note that this hook is only executed as the theme cache is re-built.
  2258. * Changes here will not be visible until the next cache clear.
  2259. *
  2260. * The $theme_registry array is keyed by theme hook name, and contains the
  2261. * information returned from hook_theme(), as well as additional properties
  2262. * added by _theme_process_registry().
  2263. *
  2264. * For example:
  2265. * @code
  2266. * $theme_registry['user_profile'] = array(
  2267. * 'variables' => array(
  2268. * 'account' => NULL,
  2269. * ),
  2270. * 'template' => 'modules/user/user-profile',
  2271. * 'file' => 'modules/user/user.pages.inc',
  2272. * 'type' => 'module',
  2273. * 'theme path' => 'modules/user',
  2274. * 'preprocess functions' => array(
  2275. * 0 => 'template_preprocess',
  2276. * 1 => 'template_preprocess_user_profile',
  2277. * ),
  2278. * );
  2279. * @endcode
  2280. *
  2281. * @param $theme_registry
  2282. * The entire cache of theme registry information, post-processing.
  2283. *
  2284. * @see hook_theme()
  2285. * @see _theme_process_registry()
  2286. */
  2287. function hook_theme_registry_alter(&$theme_registry) {
  2288. // Kill the next/previous forum topic navigation links.
  2289. foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
  2290. if ($value == 'template_preprocess_forum_topic_navigation') {
  2291. unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);
  2292. }
  2293. }
  2294. }
  2295. /**
  2296. * Return the machine-readable name of the theme to use for the current page.
  2297. *
  2298. * This hook can be used to dynamically set the theme for the current page
  2299. * request. It should be used by modules which need to override the theme
  2300. * based on dynamic conditions (for example, a module which allows the theme to
  2301. * be set based on the current user's role). The return value of this hook will
  2302. * be used on all pages except those which have a valid per-page or per-section
  2303. * theme set via a theme callback function in hook_menu(); the themes on those
  2304. * pages can only be overridden using hook_menu_alter().
  2305. *
  2306. * Note that returning different themes for the same path may not work with page
  2307. * caching. This is most likely to be a problem if an anonymous user on a given
  2308. * path could have different themes returned under different conditions.
  2309. *
  2310. * Since only one theme can be used at a time, the last (i.e., highest
  2311. * weighted) module which returns a valid theme name from this hook will
  2312. * prevail.
  2313. *
  2314. * @return
  2315. * The machine-readable name of the theme that should be used for the current
  2316. * page request. The value returned from this function will only have an
  2317. * effect if it corresponds to a currently-active theme on the site. Do not
  2318. * return a value if you do not wish to set a custom theme.
  2319. */
  2320. function hook_custom_theme() {
  2321. // Allow the user to request a particular theme via a query parameter.
  2322. if (isset($_GET['theme'])) {
  2323. return $_GET['theme'];
  2324. }
  2325. }
  2326. /**
  2327. * Register XML-RPC callbacks.
  2328. *
  2329. * This hook lets a module register callback functions to be called when
  2330. * particular XML-RPC methods are invoked by a client.
  2331. *
  2332. * @return
  2333. * An array which maps XML-RPC methods to Drupal functions. Each array
  2334. * element is either a pair of method => function or an array with four
  2335. * entries:
  2336. * - The XML-RPC method name (for example, module.function).
  2337. * - The Drupal callback function (for example, module_function).
  2338. * - The method signature is an array of XML-RPC types. The first element
  2339. * of this array is the type of return value and then you should write a
  2340. * list of the types of the parameters. XML-RPC types are the following
  2341. * (See the types at http://www.xmlrpc.com/spec):
  2342. * - "boolean": 0 (false) or 1 (true).
  2343. * - "double": a floating point number (for example, -12.214).
  2344. * - "int": a integer number (for example, -12).
  2345. * - "array": an array without keys (for example, array(1, 2, 3)).
  2346. * - "struct": an associative array or an object (for example,
  2347. * array('one' => 1, 'two' => 2)).
  2348. * - "date": when you return a date, then you may either return a
  2349. * timestamp (time(), mktime() etc.) or an ISO8601 timestamp. When
  2350. * date is specified as an input parameter, then you get an object,
  2351. * which is described in the function xmlrpc_date
  2352. * - "base64": a string containing binary data, automatically
  2353. * encoded/decoded automatically.
  2354. * - "string": anything else, typically a string.
  2355. * - A descriptive help string, enclosed in a t() function for translation
  2356. * purposes.
  2357. * Both forms are shown in the example.
  2358. */
  2359. function hook_xmlrpc() {
  2360. return array(
  2361. 'drupal.login' => 'drupal_login',
  2362. array(
  2363. 'drupal.site.ping',
  2364. 'drupal_directory_ping',
  2365. array('boolean', 'string', 'string', 'string', 'string', 'string'),
  2366. t('Handling ping request'))
  2367. );
  2368. }
  2369. /**
  2370. * Alters the definition of XML-RPC methods before they are called.
  2371. *
  2372. * This hook allows modules to modify the callback definition of declared
  2373. * XML-RPC methods, right before they are invoked by a client. Methods may be
  2374. * added, or existing methods may be altered.
  2375. *
  2376. * Note that hook_xmlrpc() supports two distinct and incompatible formats to
  2377. * define a callback, so care must be taken when altering other methods.
  2378. *
  2379. * @param $methods
  2380. * An asssociative array of method callback definitions, as returned from
  2381. * hook_xmlrpc() implementations.
  2382. *
  2383. * @see hook_xmlrpc()
  2384. * @see xmlrpc_server()
  2385. */
  2386. function hook_xmlrpc_alter(&$methods) {
  2387. // Directly change a simple method.
  2388. $methods['drupal.login'] = 'mymodule_login';
  2389. // Alter complex definitions.
  2390. foreach ($methods as $key => &$method) {
  2391. // Skip simple method definitions.
  2392. if (!is_int($key)) {
  2393. continue;
  2394. }
  2395. // Perform the wanted manipulation.
  2396. if ($method[0] == 'drupal.site.ping') {
  2397. $method[1] = 'mymodule_directory_ping';
  2398. }
  2399. }
  2400. }
  2401. /**
  2402. * Log an event message.
  2403. *
  2404. * This hook allows modules to route log events to custom destinations, such as
  2405. * SMS, Email, pager, syslog, ...etc.
  2406. *
  2407. * @param $log_entry
  2408. * An associative array containing the following keys:
  2409. * - type: The type of message for this entry.
  2410. * - user: The user object for the user who was logged in when the event
  2411. * happened.
  2412. * - uid: The user ID for the user who was logged in when the event happened.
  2413. * - request_uri: The request URI for the page the event happened in.
  2414. * - referer: The page that referred the user to the page where the event
  2415. * occurred.
  2416. * - ip: The IP address where the request for the page came from.
  2417. * - timestamp: The UNIX timestamp of the date/time the event occurred.
  2418. * - severity: The severity of the message; one of the following values as
  2419. * defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink
  2420. * - WATCHDOG_EMERGENCY: Emergency, system is unusable.
  2421. * - WATCHDOG_ALERT: Alert, action must be taken immediately.
  2422. * - WATCHDOG_CRITICAL: Critical conditions.
  2423. * - WATCHDOG_ERROR: Error conditions.
  2424. * - WATCHDOG_WARNING: Warning conditions.
  2425. * - WATCHDOG_NOTICE: Normal but significant conditions.
  2426. * - WATCHDOG_INFO: Informational messages.
  2427. * - WATCHDOG_DEBUG: Debug-level messages.
  2428. * - link: An optional link provided by the module that called the watchdog()
  2429. * function.
  2430. * - message: The text of the message to be logged. Variables in the message
  2431. * are indicated by using placeholder strings alongside the variables
  2432. * argument to declare the value of the placeholders. See t() for
  2433. * documentation on how the message and variable parameters interact.
  2434. * - variables: An array of variables to be inserted into the message on
  2435. * display. Will be NULL or missing if a message is already translated or if
  2436. * the message is not possible to translate.
  2437. */
  2438. function hook_watchdog(array $log_entry) {
  2439. global $base_url, $language;
  2440. $severity_list = array(
  2441. WATCHDOG_EMERGENCY => t('Emergency'),
  2442. WATCHDOG_ALERT => t('Alert'),
  2443. WATCHDOG_CRITICAL => t('Critical'),
  2444. WATCHDOG_ERROR => t('Error'),
  2445. WATCHDOG_WARNING => t('Warning'),
  2446. WATCHDOG_NOTICE => t('Notice'),
  2447. WATCHDOG_INFO => t('Info'),
  2448. WATCHDOG_DEBUG => t('Debug'),
  2449. );
  2450. $to = 'someone@example.com';
  2451. $params = array();
  2452. $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(
  2453. '@site_name' => variable_get('site_name', 'Drupal'),
  2454. '@severity_desc' => $severity_list[$log_entry['severity']],
  2455. ));
  2456. $params['message'] = "\nSite: @base_url";
  2457. $params['message'] .= "\nSeverity: (@severity) @severity_desc";
  2458. $params['message'] .= "\nTimestamp: @timestamp";
  2459. $params['message'] .= "\nType: @type";
  2460. $params['message'] .= "\nIP Address: @ip";
  2461. $params['message'] .= "\nRequest URI: @request_uri";
  2462. $params['message'] .= "\nReferrer URI: @referer_uri";
  2463. $params['message'] .= "\nUser: (@uid) @name";
  2464. $params['message'] .= "\nLink: @link";
  2465. $params['message'] .= "\nMessage: \n\n@message";
  2466. $params['message'] = t($params['message'], array(
  2467. '@base_url' => $base_url,
  2468. '@severity' => $log_entry['severity'],
  2469. '@severity_desc' => $severity_list[$log_entry['severity']],
  2470. '@timestamp' => format_date($log_entry['timestamp']),
  2471. '@type' => $log_entry['type'],
  2472. '@ip' => $log_entry['ip'],
  2473. '@request_uri' => $log_entry['request_uri'],
  2474. '@referer_uri' => $log_entry['referer'],
  2475. '@uid' => $log_entry['uid'],
  2476. '@name' => $log_entry['user']->name,
  2477. '@link' => strip_tags($log_entry['link']),
  2478. '@message' => strip_tags($log_entry['message']),
  2479. ));
  2480. drupal_mail('emaillog', 'entry', $to, $language, $params);
  2481. }
  2482. /**
  2483. * Prepare a message based on parameters; called from drupal_mail().
  2484. *
  2485. * Note that hook_mail(), unlike hook_mail_alter(), is only called on the
  2486. * $module argument to drupal_mail(), not all modules.
  2487. *
  2488. * @param $key
  2489. * An identifier of the mail.
  2490. * @param $message
  2491. * An array to be filled in. Elements in this array include:
  2492. * - id: An ID to identify the mail sent. Look at module source code
  2493. * or drupal_mail() for possible id values.
  2494. * - to: The address or addresses the message will be sent to. The formatting
  2495. * of this string will be validated with the
  2496. * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink
  2497. * - subject: Subject of the e-mail to be sent. This must not contain any
  2498. * newline characters, or the mail may not be sent properly. drupal_mail()
  2499. * sets this to an empty string when the hook is invoked.
  2500. * - body: An array of lines containing the message to be sent. Drupal will
  2501. * format the correct line endings for you. drupal_mail() sets this to an
  2502. * empty array when the hook is invoked.
  2503. * - from: The address the message will be marked as being from, which is
  2504. * set by drupal_mail() to either a custom address or the site-wide
  2505. * default email address when the hook is invoked.
  2506. * - headers: Associative array containing mail headers, such as From,
  2507. * Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills
  2508. * several headers in this array.
  2509. * @param $params
  2510. * An array of parameters supplied by the caller of drupal_mail().
  2511. */
  2512. function hook_mail($key, &$message, $params) {
  2513. $account = $params['account'];
  2514. $context = $params['context'];
  2515. $variables = array(
  2516. '%site_name' => variable_get('site_name', 'Drupal'),
  2517. '%username' => format_username($account),
  2518. );
  2519. if ($context['hook'] == 'taxonomy') {
  2520. $entity = $params['entity'];
  2521. $vocabulary = taxonomy_vocabulary_load($entity->vid);
  2522. $variables += array(
  2523. '%term_name' => $entity->name,
  2524. '%term_description' => $entity->description,
  2525. '%term_id' => $entity->tid,
  2526. '%vocabulary_name' => $vocabulary->name,
  2527. '%vocabulary_description' => $vocabulary->description,
  2528. '%vocabulary_id' => $vocabulary->vid,
  2529. );
  2530. }
  2531. // Node-based variable translation is only available if we have a node.
  2532. if (isset($params['node'])) {
  2533. $node = $params['node'];
  2534. $variables += array(
  2535. '%uid' => $node->uid,
  2536. '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
  2537. '%node_type' => node_type_get_name($node),
  2538. '%title' => $node->title,
  2539. '%teaser' => $node->teaser,
  2540. '%body' => $node->body,
  2541. );
  2542. }
  2543. $subject = strtr($context['subject'], $variables);
  2544. $body = strtr($context['message'], $variables);
  2545. $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
  2546. $message['body'][] = drupal_html_to_text($body);
  2547. }
  2548. /**
  2549. * Add a list of cache tables to be cleared.
  2550. *
  2551. * This hook allows your module to add cache table names to the list of cache
  2552. * tables that will be cleared by the Clear button on the Performance page or
  2553. * whenever drupal_flush_all_caches is invoked.
  2554. *
  2555. * @return
  2556. * An array of cache table names.
  2557. *
  2558. * @see drupal_flush_all_caches()
  2559. */
  2560. function hook_flush_caches() {
  2561. return array('cache_example');
  2562. }
  2563. /**
  2564. * Perform necessary actions after modules are installed.
  2565. *
  2566. * This function differs from hook_install() in that it gives all other modules
  2567. * a chance to perform actions when a module is installed, whereas
  2568. * hook_install() is only called on the module actually being installed. See
  2569. * module_enable() for a detailed description of the order in which install and
  2570. * enable hooks are invoked.
  2571. *
  2572. * @param $modules
  2573. * An array of the modules that were installed.
  2574. *
  2575. * @see module_enable()
  2576. * @see hook_modules_enabled()
  2577. * @see hook_install()
  2578. */
  2579. function hook_modules_installed($modules) {
  2580. if (in_array('lousy_module', $modules)) {
  2581. variable_set('lousy_module_conflicting_variable', FALSE);
  2582. }
  2583. }
  2584. /**
  2585. * Perform necessary actions after modules are enabled.
  2586. *
  2587. * This function differs from hook_enable() in that it gives all other modules a
  2588. * chance to perform actions when modules are enabled, whereas hook_enable() is
  2589. * only called on the module actually being enabled. See module_enable() for a
  2590. * detailed description of the order in which install and enable hooks are
  2591. * invoked.
  2592. *
  2593. * @param $modules
  2594. * An array of the modules that were enabled.
  2595. *
  2596. * @see hook_enable()
  2597. * @see hook_modules_installed()
  2598. * @see module_enable()
  2599. */
  2600. function hook_modules_enabled($modules) {
  2601. if (in_array('lousy_module', $modules)) {
  2602. drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error');
  2603. mymodule_disable_functionality();
  2604. }
  2605. }
  2606. /**
  2607. * Perform necessary actions after modules are disabled.
  2608. *
  2609. * This function differs from hook_disable() in that it gives all other modules
  2610. * a chance to perform actions when modules are disabled, whereas hook_disable()
  2611. * is only called on the module actually being disabled.
  2612. *
  2613. * @param $modules
  2614. * An array of the modules that were disabled.
  2615. *
  2616. * @see hook_disable()
  2617. * @see hook_modules_uninstalled()
  2618. */
  2619. function hook_modules_disabled($modules) {
  2620. if (in_array('lousy_module', $modules)) {
  2621. mymodule_enable_functionality();
  2622. }
  2623. }
  2624. /**
  2625. * Perform necessary actions after modules are uninstalled.
  2626. *
  2627. * This function differs from hook_uninstall() in that it gives all other
  2628. * modules a chance to perform actions when a module is uninstalled, whereas
  2629. * hook_uninstall() is only called on the module actually being uninstalled.
  2630. *
  2631. * It is recommended that you implement this hook if your module stores
  2632. * data that may have been set by other modules.
  2633. *
  2634. * @param $modules
  2635. * An array of the modules that were uninstalled.
  2636. *
  2637. * @see hook_uninstall()
  2638. * @see hook_modules_disabled()
  2639. */
  2640. function hook_modules_uninstalled($modules) {
  2641. foreach ($modules as $module) {
  2642. db_delete('mymodule_table')
  2643. ->condition('module', $module)
  2644. ->execute();
  2645. }
  2646. mymodule_cache_rebuild();
  2647. }
  2648. /**
  2649. * Registers PHP stream wrapper implementations associated with a module.
  2650. *
  2651. * Provide a facility for managing and querying user-defined stream wrappers
  2652. * in PHP. PHP's internal stream_get_wrappers() doesn't return the class
  2653. * registered to handle a stream, which we need to be able to find the handler
  2654. * for class instantiation.
  2655. *
  2656. * If a module registers a scheme that is already registered with PHP, it will
  2657. * be unregistered and replaced with the specified class.
  2658. *
  2659. * @return
  2660. * A nested array, keyed first by scheme name ("public" for "public://"),
  2661. * then keyed by the following values:
  2662. * - 'name' A short string to name the wrapper.
  2663. * - 'class' A string specifying the PHP class that implements the
  2664. * DrupalStreamWrapperInterface interface.
  2665. * - 'description' A string with a short description of what the wrapper does.
  2666. * - 'type' (Optional) A bitmask of flags indicating what type of streams this
  2667. * wrapper will access - local or remote, readable and/or writeable, etc.
  2668. * Many shortcut constants are defined in stream_wrappers.inc. Defaults to
  2669. * STREAM_WRAPPERS_NORMAL which includes all of these bit flags:
  2670. * - STREAM_WRAPPERS_READ
  2671. * - STREAM_WRAPPERS_WRITE
  2672. * - STREAM_WRAPPERS_VISIBLE
  2673. *
  2674. * @see file_get_stream_wrappers()
  2675. * @see hook_stream_wrappers_alter()
  2676. * @see system_stream_wrappers()
  2677. */
  2678. function hook_stream_wrappers() {
  2679. return array(
  2680. 'public' => array(
  2681. 'name' => t('Public files'),
  2682. 'class' => 'DrupalPublicStreamWrapper',
  2683. 'description' => t('Public local files served by the webserver.'),
  2684. 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
  2685. ),
  2686. 'private' => array(
  2687. 'name' => t('Private files'),
  2688. 'class' => 'DrupalPrivateStreamWrapper',
  2689. 'description' => t('Private local files served by Drupal.'),
  2690. 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
  2691. ),
  2692. 'temp' => array(
  2693. 'name' => t('Temporary files'),
  2694. 'class' => 'DrupalTempStreamWrapper',
  2695. 'description' => t('Temporary local files for upload and previews.'),
  2696. 'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
  2697. ),
  2698. 'cdn' => array(
  2699. 'name' => t('Content delivery network files'),
  2700. 'class' => 'MyModuleCDNStreamWrapper',
  2701. 'description' => t('Files served by a content delivery network.'),
  2702. // 'type' can be omitted to use the default of STREAM_WRAPPERS_NORMAL
  2703. ),
  2704. 'youtube' => array(
  2705. 'name' => t('YouTube video'),
  2706. 'class' => 'MyModuleYouTubeStreamWrapper',
  2707. 'description' => t('Video streamed from YouTube.'),
  2708. // A module implementing YouTube integration may decide to support using
  2709. // the YouTube API for uploading video, but here, we assume that this
  2710. // particular module only supports playing YouTube video.
  2711. 'type' => STREAM_WRAPPERS_READ_VISIBLE,
  2712. ),
  2713. );
  2714. }
  2715. /**
  2716. * Alters the list of PHP stream wrapper implementations.
  2717. *
  2718. * @see file_get_stream_wrappers()
  2719. * @see hook_stream_wrappers()
  2720. */
  2721. function hook_stream_wrappers_alter(&$wrappers) {
  2722. // Change the name of private files to reflect the performance.
  2723. $wrappers['private']['name'] = t('Slow files');
  2724. }
  2725. /**
  2726. * Load additional information into file objects.
  2727. *
  2728. * file_load_multiple() calls this hook to allow modules to load
  2729. * additional information into each file.
  2730. *
  2731. * @param $files
  2732. * An array of file objects, indexed by fid.
  2733. *
  2734. * @see file_load_multiple()
  2735. * @see file_load()
  2736. */
  2737. function hook_file_load($files) {
  2738. // Add the upload specific data into the file object.
  2739. $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);
  2740. foreach ($result as $record) {
  2741. foreach ($record as $key => $value) {
  2742. $files[$record['fid']]->$key = $value;
  2743. }
  2744. }
  2745. }
  2746. /**
  2747. * Check that files meet a given criteria.
  2748. *
  2749. * This hook lets modules perform additional validation on files. They're able
  2750. * to report a failure by returning one or more error messages.
  2751. *
  2752. * @param $file
  2753. * The file object being validated.
  2754. * @return
  2755. * An array of error messages. If there are no problems with the file return
  2756. * an empty array.
  2757. *
  2758. * @see file_validate()
  2759. */
  2760. function hook_file_validate($file) {
  2761. $errors = array();
  2762. if (empty($file->filename)) {
  2763. $errors[] = t("The file's name is empty. Please give a name to the file.");
  2764. }
  2765. if (strlen($file->filename) > 255) {
  2766. $errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again.");
  2767. }
  2768. return $errors;
  2769. }
  2770. /**
  2771. * Act on a file being inserted or updated.
  2772. *
  2773. * This hook is called when a file has been added to the database. The hook
  2774. * doesn't distinguish between files created as a result of a copy or those
  2775. * created by an upload.
  2776. *
  2777. * @param $file
  2778. * The file that has just been created.
  2779. *
  2780. * @see file_save()
  2781. */
  2782. function hook_file_presave($file) {
  2783. // Change the file timestamp to an hour prior.
  2784. $file->timestamp -= 3600;
  2785. }
  2786. /**
  2787. * Respond to a file being added.
  2788. *
  2789. * This hook is called after a file has been added to the database. The hook
  2790. * doesn't distinguish between files created as a result of a copy or those
  2791. * created by an upload.
  2792. *
  2793. * @param $file
  2794. * The file that has been added.
  2795. *
  2796. * @see file_save()
  2797. */
  2798. function hook_file_insert($file) {
  2799. // Add a message to the log, if the file is a jpg
  2800. $validate = file_validate_extensions($file, 'jpg');
  2801. if (empty($validate)) {
  2802. watchdog('file', 'A jpg has been added.');
  2803. }
  2804. }
  2805. /**
  2806. * Respond to a file being updated.
  2807. *
  2808. * This hook is called when file_save() is called on an existing file.
  2809. *
  2810. * @param $file
  2811. * The file that has just been updated.
  2812. *
  2813. * @see file_save()
  2814. */
  2815. function hook_file_update($file) {
  2816. $file_user = user_load($file->uid);
  2817. // Make sure that the file name starts with the owner's user name.
  2818. if (strpos($file->filename, $file_user->name) !== 0) {
  2819. $old_filename = $file->filename;
  2820. $file->filename = $file_user->name . '_' . $file->filename;
  2821. $file->save();
  2822. watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename)));
  2823. }
  2824. }
  2825. /**
  2826. * Respond to a file that has been copied.
  2827. *
  2828. * @param $file
  2829. * The newly copied file object.
  2830. * @param $source
  2831. * The original file before the copy.
  2832. *
  2833. * @see file_copy()
  2834. */
  2835. function hook_file_copy($file, $source) {
  2836. $file_user = user_load($file->uid);
  2837. // Make sure that the file name starts with the owner's user name.
  2838. if (strpos($file->filename, $file_user->name) !== 0) {
  2839. $file->filename = $file_user->name . '_' . $file->filename;
  2840. $file->save();
  2841. watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
  2842. }
  2843. }
  2844. /**
  2845. * Respond to a file that has been moved.
  2846. *
  2847. * @param $file
  2848. * The updated file object after the move.
  2849. * @param $source
  2850. * The original file object before the move.
  2851. *
  2852. * @see file_move()
  2853. */
  2854. function hook_file_move($file, $source) {
  2855. $file_user = user_load($file->uid);
  2856. // Make sure that the file name starts with the owner's user name.
  2857. if (strpos($file->filename, $file_user->name) !== 0) {
  2858. $file->filename = $file_user->name . '_' . $file->filename;
  2859. $file->save();
  2860. watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
  2861. }
  2862. }
  2863. /**
  2864. * Respond to a file being deleted.
  2865. *
  2866. * @param $file
  2867. * The file that has just been deleted.
  2868. *
  2869. * @see file_delete()
  2870. */
  2871. function hook_file_delete($file) {
  2872. // Delete all information associated with the file.
  2873. db_delete('upload')->condition('fid', $file->fid)->execute();
  2874. }
  2875. /**
  2876. * Control access to private file downloads and specify HTTP headers.
  2877. *
  2878. * This hook allows modules enforce permissions on file downloads when the
  2879. * private file download method is selected. Modules can also provide headers
  2880. * to specify information like the file's name or MIME type.
  2881. *
  2882. * @param $uri
  2883. * The URI of the file.
  2884. * @return
  2885. * If the user does not have permission to access the file, return -1. If the
  2886. * user has permission, return an array with the appropriate headers. If the
  2887. * file is not controlled by the current module, the return value should be
  2888. * NULL.
  2889. *
  2890. * @see file_download()
  2891. */
  2892. function hook_file_download($uri) {
  2893. // Check if the file is controlled by the current module.
  2894. if (!file_prepare_directory($uri)) {
  2895. $uri = FALSE;
  2896. }
  2897. if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
  2898. if (!user_access('access user profiles')) {
  2899. // Access to the file is denied.
  2900. return -1;
  2901. }
  2902. else {
  2903. $info = image_get_info($uri);
  2904. return array('Content-Type' => $info['mime_type']);
  2905. }
  2906. }
  2907. }
  2908. /**
  2909. * Alter the URL to a file.
  2910. *
  2911. * This hook is called from file_create_url(), and is called fairly
  2912. * frequently (10+ times per page), depending on how many files there are in a
  2913. * given page.
  2914. * If CSS and JS aggregation are disabled, this can become very frequently
  2915. * (50+ times per page) so performance is critical.
  2916. *
  2917. * This function should alter the URI, if it wants to rewrite the file URL.
  2918. *
  2919. * @param $uri
  2920. * The URI to a file for which we need an external URL, or the path to a
  2921. * shipped file.
  2922. */
  2923. function hook_file_url_alter(&$uri) {
  2924. global $user;
  2925. // User 1 will always see the local file in this example.
  2926. if ($user->uid == 1) {
  2927. return;
  2928. }
  2929. $cdn1 = 'http://cdn1.example.com';
  2930. $cdn2 = 'http://cdn2.example.com';
  2931. $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
  2932. // Most CDNs don't support private file transfers without a lot of hassle,
  2933. // so don't support this in the common case.
  2934. $schemes = array('public');
  2935. $scheme = file_uri_scheme($uri);
  2936. // Only serve shipped files and public created files from the CDN.
  2937. if (!$scheme || in_array($scheme, $schemes)) {
  2938. // Shipped files.
  2939. if (!$scheme) {
  2940. $path = $uri;
  2941. }
  2942. // Public created files.
  2943. else {
  2944. $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
  2945. $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
  2946. }
  2947. // Clean up Windows paths.
  2948. $path = str_replace('\\', '/', $path);
  2949. // Serve files with one of the CDN extensions from CDN 1, all others from
  2950. // CDN 2.
  2951. $pathinfo = pathinfo($path);
  2952. if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {
  2953. $uri = $cdn1 . '/' . $path;
  2954. }
  2955. else {
  2956. $uri = $cdn2 . '/' . $path;
  2957. }
  2958. }
  2959. }
  2960. /**
  2961. * Check installation requirements and do status reporting.
  2962. *
  2963. * This hook has three closely related uses, determined by the $phase argument:
  2964. * - Checking installation requirements ($phase == 'install').
  2965. * - Checking update requirements ($phase == 'update').
  2966. * - Status reporting ($phase == 'runtime').
  2967. *
  2968. * Note that this hook, like all others dealing with installation and updates,
  2969. * must reside in a module_name.install file, or it will not properly abort
  2970. * the installation of the module if a critical requirement is missing.
  2971. *
  2972. * During the 'install' phase, modules can for example assert that
  2973. * library or server versions are available or sufficient.
  2974. * Note that the installation of a module can happen during installation of
  2975. * Drupal itself (by install.php) with an installation profile or later by hand.
  2976. * As a consequence, install-time requirements must be checked without access
  2977. * to the full Drupal API, because it is not available during install.php.
  2978. * For localization you should for example use $t = get_t() to
  2979. * retrieve the appropriate localization function name (t() or st()).
  2980. * If a requirement has a severity of REQUIREMENT_ERROR, install.php will abort
  2981. * or at least the module will not install.
  2982. * Other severity levels have no effect on the installation.
  2983. * Module dependencies do not belong to these installation requirements,
  2984. * but should be defined in the module's .info file.
  2985. *
  2986. * The 'runtime' phase is not limited to pure installation requirements
  2987. * but can also be used for more general status information like maintenance
  2988. * tasks and security issues.
  2989. * The returned 'requirements' will be listed on the status report in the
  2990. * administration section, with indication of the severity level.
  2991. * Moreover, any requirement with a severity of REQUIREMENT_ERROR severity will
  2992. * result in a notice on the administration configuration page.
  2993. *
  2994. * @param $phase
  2995. * The phase in which requirements are checked:
  2996. * - install: The module is being installed.
  2997. * - update: The module is enabled and update.php is run.
  2998. * - runtime: The runtime requirements are being checked and shown on the
  2999. * status report page.
  3000. *
  3001. * @return
  3002. * An associative array where the keys are arbitrary but must be unique (it
  3003. * is suggested to use the module short name as a prefix) and the values are
  3004. * themselves associative arrays with the following elements:
  3005. * - title: The name of the requirement.
  3006. * - value: The current value (e.g., version, time, level, etc). During
  3007. * install phase, this should only be used for version numbers, do not set
  3008. * it if not applicable.
  3009. * - description: The description of the requirement/status.
  3010. * - severity: The requirement's result/severity level, one of:
  3011. * - REQUIREMENT_INFO: For info only.
  3012. * - REQUIREMENT_OK: The requirement is satisfied.
  3013. * - REQUIREMENT_WARNING: The requirement failed with a warning.
  3014. * - REQUIREMENT_ERROR: The requirement failed with an error.
  3015. */
  3016. function hook_requirements($phase) {
  3017. $requirements = array();
  3018. // Ensure translations don't break during installation.
  3019. $t = get_t();
  3020. // Report Drupal version
  3021. if ($phase == 'runtime') {
  3022. $requirements['drupal'] = array(
  3023. 'title' => $t('Drupal'),
  3024. 'value' => VERSION,
  3025. 'severity' => REQUIREMENT_INFO
  3026. );
  3027. }
  3028. // Test PHP version
  3029. $requirements['php'] = array(
  3030. 'title' => $t('PHP'),
  3031. 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/reports/status/php') : phpversion(),
  3032. );
  3033. if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) {
  3034. $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
  3035. $requirements['php']['severity'] = REQUIREMENT_ERROR;
  3036. }
  3037. // Report cron status
  3038. if ($phase == 'runtime') {
  3039. $cron_last = variable_get('cron_last');
  3040. if (is_numeric($cron_last)) {
  3041. $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
  3042. }
  3043. else {
  3044. $requirements['cron'] = array(
  3045. 'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Check the help pages for <a href="@url">configuring cron jobs</a>.', array('@url' => 'http://drupal.org/cron')),
  3046. 'severity' => REQUIREMENT_ERROR,
  3047. 'value' => $t('Never run'),
  3048. );
  3049. }
  3050. $requirements['cron']['description'] .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
  3051. $requirements['cron']['title'] = $t('Cron maintenance tasks');
  3052. }
  3053. return $requirements;
  3054. }
  3055. /**
  3056. * Define the current version of the database schema.
  3057. *
  3058. * A Drupal schema definition is an array structure representing one or more
  3059. * tables and their related keys and indexes. A schema is defined by
  3060. * hook_schema() which must live in your module's .install file.
  3061. *
  3062. * This hook is called at install and uninstall time, and in the latter case, it
  3063. * cannot rely on the .module file being loaded or hooks being known. If the
  3064. * .module file is needed, it may be loaded with drupal_load().
  3065. *
  3066. * The tables declared by this hook will be automatically created when the
  3067. * module is first enabled, and removed when the module is uninstalled. This
  3068. * happens before hook_install() is invoked, and after hook_uninstall() is
  3069. * invoked, respectively.
  3070. *
  3071. * By declaring the tables used by your module via an implementation of
  3072. * hook_schema(), these tables will be available on all supported database
  3073. * engines. You don't have to deal with the different SQL dialects for table
  3074. * creation and alteration of the supported database engines.
  3075. *
  3076. * See the Schema API Handbook at http://drupal.org/node/146843 for details on
  3077. * schema definition structures.
  3078. *
  3079. * @return array
  3080. * A schema definition structure array. For each element of the
  3081. * array, the key is a table name and the value is a table structure
  3082. * definition.
  3083. *
  3084. * @see hook_schema_alter()
  3085. *
  3086. * @ingroup schemaapi
  3087. */
  3088. function hook_schema() {
  3089. $schema['node'] = array(
  3090. // Example (partial) specification for table "node".
  3091. 'description' => 'The base table for nodes.',
  3092. 'fields' => array(
  3093. 'nid' => array(
  3094. 'description' => 'The primary identifier for a node.',
  3095. 'type' => 'serial',
  3096. 'unsigned' => TRUE,
  3097. 'not null' => TRUE,
  3098. ),
  3099. 'vid' => array(
  3100. 'description' => 'The current {node_revision}.vid version identifier.',
  3101. 'type' => 'int',
  3102. 'unsigned' => TRUE,
  3103. 'not null' => TRUE,
  3104. 'default' => 0,
  3105. ),
  3106. 'type' => array(
  3107. 'description' => 'The {node_type} of this node.',
  3108. 'type' => 'varchar',
  3109. 'length' => 32,
  3110. 'not null' => TRUE,
  3111. 'default' => '',
  3112. ),
  3113. 'title' => array(
  3114. 'description' => 'The title of this node, always treated as non-markup plain text.',
  3115. 'type' => 'varchar',
  3116. 'length' => 255,
  3117. 'not null' => TRUE,
  3118. 'default' => '',
  3119. ),
  3120. ),
  3121. 'indexes' => array(
  3122. 'node_changed' => array('changed'),
  3123. 'node_created' => array('created'),
  3124. ),
  3125. 'unique keys' => array(
  3126. 'nid_vid' => array('nid', 'vid'),
  3127. 'vid' => array('vid'),
  3128. ),
  3129. 'foreign keys' => array(
  3130. 'node_revision' => array(
  3131. 'table' => 'node_revision',
  3132. 'columns' => array('vid' => 'vid'),
  3133. ),
  3134. 'node_author' => array(
  3135. 'table' => 'users',
  3136. 'columns' => array('uid' => 'uid'),
  3137. ),
  3138. ),
  3139. 'primary key' => array('nid'),
  3140. );
  3141. return $schema;
  3142. }
  3143. /**
  3144. * Perform alterations to existing database schemas.
  3145. *
  3146. * When a module modifies the database structure of another module (by
  3147. * changing, adding or removing fields, keys or indexes), it should
  3148. * implement hook_schema_alter() to update the default $schema to take its
  3149. * changes into account.
  3150. *
  3151. * See hook_schema() for details on the schema definition structure.
  3152. *
  3153. * @param $schema
  3154. * Nested array describing the schemas for all modules.
  3155. *
  3156. * @ingroup schemaapi
  3157. */
  3158. function hook_schema_alter(&$schema) {
  3159. // Add field to existing schema.
  3160. $schema['users']['fields']['timezone_id'] = array(
  3161. 'type' => 'int',
  3162. 'not null' => TRUE,
  3163. 'default' => 0,
  3164. 'description' => 'Per-user timezone configuration.',
  3165. );
  3166. }
  3167. /**
  3168. * Perform alterations to a structured query.
  3169. *
  3170. * Structured (aka dynamic) queries that have tags associated may be altered by any module
  3171. * before the query is executed.
  3172. *
  3173. * @param $query
  3174. * A Query object describing the composite parts of a SQL query.
  3175. *
  3176. * @see hook_query_TAG_alter()
  3177. * @see node_query_node_access_alter()
  3178. * @see QueryAlterableInterface
  3179. * @see SelectQueryInterface
  3180. */
  3181. function hook_query_alter(QueryAlterableInterface $query) {
  3182. if ($query->hasTag('micro_limit')) {
  3183. $query->range(0, 2);
  3184. }
  3185. }
  3186. /**
  3187. * Perform alterations to a structured query for a given tag.
  3188. *
  3189. * @param $query
  3190. * An Query object describing the composite parts of a SQL query.
  3191. *
  3192. * @see hook_query_alter()
  3193. * @see node_query_node_access_alter()
  3194. * @see QueryAlterableInterface
  3195. * @see SelectQueryInterface
  3196. */
  3197. function hook_query_TAG_alter(QueryAlterableInterface $query) {
  3198. // Skip the extra expensive alterations if site has no node access control modules.
  3199. if (!node_access_view_all_nodes()) {
  3200. // Prevent duplicates records.
  3201. $query->distinct();
  3202. // The recognized operations are 'view', 'update', 'delete'.
  3203. if (!$op = $query->getMetaData('op')) {
  3204. $op = 'view';
  3205. }
  3206. // Skip the extra joins and conditions for node admins.
  3207. if (!user_access('bypass node access')) {
  3208. // The node_access table has the access grants for any given node.
  3209. $access_alias = $query->join('node_access', 'na', '%alias.nid = n.nid');
  3210. $or = db_or();
  3211. // If any grant exists for the specified user, then user has access to the node for the specified operation.
  3212. foreach (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) {
  3213. foreach ($gids as $gid) {
  3214. $or->condition(db_and()
  3215. ->condition($access_alias . '.gid', $gid)
  3216. ->condition($access_alias . '.realm', $realm)
  3217. );
  3218. }
  3219. }
  3220. if (count($or->conditions())) {
  3221. $query->condition($or);
  3222. }
  3223. $query->condition($access_alias . 'grant_' . $op, 1, '>=');
  3224. }
  3225. }
  3226. }
  3227. /**
  3228. * Perform setup tasks when the module is installed.
  3229. *
  3230. * If the module implements hook_schema(), the database tables will
  3231. * be created before this hook is fired.
  3232. *
  3233. * Implementations of this hook are by convention declared in the module's
  3234. * .install file. The implementation can rely on the .module file being loaded.
  3235. * The hook will only be called the first time a module is enabled or after it
  3236. * is re-enabled after being uninstalled. The module's schema version will be
  3237. * set to the module's greatest numbered update hook. Because of this, any time
  3238. * a hook_update_N() is added to the module, this function needs to be updated
  3239. * to reflect the current version of the database schema.
  3240. *
  3241. * See the @link http://drupal.org/node/146843 Schema API documentation @endlink
  3242. * for details on hook_schema and how database tables are defined.
  3243. *
  3244. * Note that since this function is called from a full bootstrap, all functions
  3245. * (including those in modules enabled by the current page request) are
  3246. * available when this hook is called. Use cases could be displaying a user
  3247. * message, or calling a module function necessary for initial setup, etc.
  3248. *
  3249. * Please be sure that anything added or modified in this function that can
  3250. * be removed during uninstall should be removed with hook_uninstall().
  3251. *
  3252. * @see hook_schema()
  3253. * @see module_enable()
  3254. * @see hook_enable()
  3255. * @see hook_disable()
  3256. * @see hook_uninstall()
  3257. * @see hook_modules_installed()
  3258. */
  3259. function hook_install() {
  3260. // Populate the default {node_access} record.
  3261. db_insert('node_access')
  3262. ->fields(array(
  3263. 'nid' => 0,
  3264. 'gid' => 0,
  3265. 'realm' => 'all',
  3266. 'grant_view' => 1,
  3267. 'grant_update' => 0,
  3268. 'grant_delete' => 0,
  3269. ))
  3270. ->execute();
  3271. }
  3272. /**
  3273. * Perform a single update.
  3274. *
  3275. * For each change that requires one or more actions to be performed when
  3276. * updating a site, add a new hook_update_N(), which will be called by
  3277. * update.php. The documentation block preceding this function is stripped of
  3278. * newlines and used as the description for the update on the pending updates
  3279. * task list. Schema updates should adhere to the
  3280. * @link http://drupal.org/node/150215 Schema API. @endlink
  3281. *
  3282. * Implementations of hook_update_N() are named (module name)_update_(number).
  3283. * The numbers are composed of three parts:
  3284. * - 1 digit for Drupal core compatibility.
  3285. * - 1 digit for your module's major release version (e.g., is this the 7.x-1.*
  3286. * (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for
  3287. * initial porting of your module to a new Drupal core API.
  3288. * - 2 digits for sequential counting, starting with 00.
  3289. *
  3290. * Examples:
  3291. * - mymodule_update_7000(): This is the required update for mymodule to run
  3292. * with Drupal core API 7.x when upgrading from Drupal core API 6.x.
  3293. * - mymodule_update_7100(): This is the first update to get the database ready
  3294. * to run mymodule 7.x-1.*.
  3295. * - mymodule_update_7200(): This is the first update to get the database ready
  3296. * to run mymodule 7.x-2.*. Users can directly update from 6.x-2.* to 7.x-2.*
  3297. * and they get all 70xx and 72xx updates, but not 71xx updates, because
  3298. * those reside in the 7.x-1.x branch only.
  3299. *
  3300. * A good rule of thumb is to remove updates older than two major releases of
  3301. * Drupal. See hook_update_last_removed() to notify Drupal about the removals.
  3302. * For further information about releases and release numbers see:
  3303. * @link http://drupal.org/node/711070 Maintaining a drupal.org project with Git @endlink
  3304. *
  3305. * Never renumber update functions.
  3306. *
  3307. * Implementations of this hook should be placed in a mymodule.install file in
  3308. * the same directory as mymodule.module. Drupal core's updates are implemented
  3309. * using the system module as a name and stored in database/updates.inc.
  3310. *
  3311. * Not all module functions are available from within a hook_update_N() function.
  3312. * In order to call a function from your mymodule.module or an include file,
  3313. * you need to explicitly load that file first.
  3314. *
  3315. * During database updates the schema of any module could be out of date. For
  3316. * this reason, caution is needed when using any API function within an update
  3317. * function - particularly CRUD functions, functions that depend on the schema
  3318. * (for example by using drupal_write_record()), and any functions that invoke
  3319. * hooks. See @link update_api Update versions of API functions @endlink for
  3320. * details.
  3321. *
  3322. * The $sandbox parameter should be used when a multipass update is needed, in
  3323. * circumstances where running the whole update at once could cause PHP to
  3324. * timeout. Each pass is run in a way that avoids PHP timeouts, provided each
  3325. * pass remains under the timeout limit. To signify that an update requires
  3326. * at least one more pass, set $sandbox['#finished'] to a number less than 1
  3327. * (you need to do this each pass). The value of $sandbox['#finished'] will be
  3328. * unset between passes but all other data in $sandbox will be preserved. The
  3329. * system will stop iterating this update when $sandbox['#finished'] is left
  3330. * unset or set to a number higher than 1. It is recommended that
  3331. * $sandbox['#finished'] is initially set to 0, and then updated each pass to a
  3332. * number between 0 and 1 that represents the overall % completed for this
  3333. * update, finishing with 1.
  3334. *
  3335. * See the @link batch Batch operations topic @endlink for more information on
  3336. * how to use the Batch API.
  3337. *
  3338. * @param array $sandbox
  3339. * Stores information for multipass updates. See above for more information.
  3340. *
  3341. * @throws DrupalUpdateException|PDOException
  3342. * In case of error, update hooks should throw an instance of DrupalUpdateException
  3343. * with a meaningful message for the user. If a database query fails for whatever
  3344. * reason, it will throw a PDOException.
  3345. *
  3346. * @return string|null
  3347. * Optionally, update hooks may return a translated string that will be
  3348. * displayed to the user after the update has completed. If no message is
  3349. * returned, no message will be presented to the user.
  3350. *
  3351. * @see batch
  3352. * @see schemaapi
  3353. * @see update_api
  3354. * @see hook_update_last_removed()
  3355. * @see update_get_update_list()
  3356. */
  3357. function hook_update_N(&$sandbox) {
  3358. // For non-multipass updates, the signature can simply be;
  3359. // function hook_update_N() {
  3360. // For most updates, the following is sufficient.
  3361. db_add_field('mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.'));
  3362. // However, for more complex operations that may take a long time,
  3363. // you may hook into Batch API as in the following example.
  3364. // Update 3 users at a time to have an exclamation point after their names.
  3365. // (They're really happy that we can do batch API in this hook!)
  3366. if (!isset($sandbox['progress'])) {
  3367. $sandbox['progress'] = 0;
  3368. $sandbox['current_uid'] = 0;
  3369. // We'll -1 to disregard the uid 0...
  3370. $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
  3371. }
  3372. $users = db_select('users', 'u')
  3373. ->fields('u', array('uid', 'name'))
  3374. ->condition('uid', $sandbox['current_uid'], '>')
  3375. ->range(0, 3)
  3376. ->orderBy('uid', 'ASC')
  3377. ->execute();
  3378. foreach ($users as $user) {
  3379. $user->name .= '!';
  3380. db_update('users')
  3381. ->fields(array('name' => $user->name))
  3382. ->condition('uid', $user->uid)
  3383. ->execute();
  3384. $sandbox['progress']++;
  3385. $sandbox['current_uid'] = $user->uid;
  3386. }
  3387. $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  3388. // To display a message to the user when the update is completed, return it.
  3389. // If you do not want to display a completion message, simply return nothing.
  3390. return t('The update did what it was supposed to do.');
  3391. // In case of an error, simply throw an exception with an error message.
  3392. throw new DrupalUpdateException('Something went wrong; here is what you should do.');
  3393. }
  3394. /**
  3395. * Return an array of information about module update dependencies.
  3396. *
  3397. * This can be used to indicate update functions from other modules that your
  3398. * module's update functions depend on, or vice versa. It is used by the update
  3399. * system to determine the appropriate order in which updates should be run, as
  3400. * well as to search for missing dependencies.
  3401. *
  3402. * Implementations of this hook should be placed in a mymodule.install file in
  3403. * the same directory as mymodule.module.
  3404. *
  3405. * @return
  3406. * A multidimensional array containing information about the module update
  3407. * dependencies. The first two levels of keys represent the module and update
  3408. * number (respectively) for which information is being returned, and the
  3409. * value is an array of information about that update's dependencies. Within
  3410. * this array, each key represents a module, and each value represents the
  3411. * number of an update function within that module. In the event that your
  3412. * update function depends on more than one update from a particular module,
  3413. * you should always list the highest numbered one here (since updates within
  3414. * a given module always run in numerical order).
  3415. *
  3416. * @see update_resolve_dependencies()
  3417. * @see hook_update_N()
  3418. */
  3419. function hook_update_dependencies() {
  3420. // Indicate that the mymodule_update_7000() function provided by this module
  3421. // must run after the another_module_update_7002() function provided by the
  3422. // 'another_module' module.
  3423. $dependencies['mymodule'][7000] = array(
  3424. 'another_module' => 7002,
  3425. );
  3426. // Indicate that the mymodule_update_7001() function provided by this module
  3427. // must run before the yet_another_module_update_7004() function provided by
  3428. // the 'yet_another_module' module. (Note that declaring dependencies in this
  3429. // direction should be done only in rare situations, since it can lead to the
  3430. // following problem: If a site has already run the yet_another_module
  3431. // module's database updates before it updates its codebase to pick up the
  3432. // newest mymodule code, then the dependency declared here will be ignored.)
  3433. $dependencies['yet_another_module'][7004] = array(
  3434. 'mymodule' => 7001,
  3435. );
  3436. return $dependencies;
  3437. }
  3438. /**
  3439. * Return a number which is no longer available as hook_update_N().
  3440. *
  3441. * If you remove some update functions from your mymodule.install file, you
  3442. * should notify Drupal of those missing functions. This way, Drupal can
  3443. * ensure that no update is accidentally skipped.
  3444. *
  3445. * Implementations of this hook should be placed in a mymodule.install file in
  3446. * the same directory as mymodule.module.
  3447. *
  3448. * @return
  3449. * An integer, corresponding to hook_update_N() which has been removed from
  3450. * mymodule.install.
  3451. *
  3452. * @see hook_update_N()
  3453. */
  3454. function hook_update_last_removed() {
  3455. // We've removed the 5.x-1.x version of mymodule, including database updates.
  3456. // The next update function is mymodule_update_5200().
  3457. return 5103;
  3458. }
  3459. /**
  3460. * Remove any information that the module sets.
  3461. *
  3462. * The information that the module should remove includes:
  3463. * - variables that the module has set using variable_set() or system_settings_form()
  3464. * - modifications to existing tables
  3465. *
  3466. * The module should not remove its entry from the {system} table. Database
  3467. * tables defined by hook_schema() will be removed automatically.
  3468. *
  3469. * The uninstall hook must be implemented in the module's .install file. It
  3470. * will fire when the module gets uninstalled but before the module's database
  3471. * tables are removed, allowing your module to query its own tables during
  3472. * this routine.
  3473. *
  3474. * When hook_uninstall() is called, your module will already be disabled, so
  3475. * its .module file will not be automatically included. If you need to call API
  3476. * functions from your .module file in this hook, use drupal_load() to make
  3477. * them available. (Keep this usage to a minimum, though, especially when
  3478. * calling API functions that invoke hooks, or API functions from modules
  3479. * listed as dependencies, since these may not be available or work as expected
  3480. * when the module is disabled.)
  3481. *
  3482. * @see hook_install()
  3483. * @see hook_schema()
  3484. * @see hook_disable()
  3485. * @see hook_modules_uninstalled()
  3486. */
  3487. function hook_uninstall() {
  3488. variable_del('upload_file_types');
  3489. }
  3490. /**
  3491. * Perform necessary actions after module is enabled.
  3492. *
  3493. * The hook is called every time the module is enabled. It should be
  3494. * implemented in the module's .install file. The implementation can
  3495. * rely on the .module file being loaded.
  3496. *
  3497. * @see module_enable()
  3498. * @see hook_install()
  3499. * @see hook_modules_enabled()
  3500. */
  3501. function hook_enable() {
  3502. mymodule_cache_rebuild();
  3503. }
  3504. /**
  3505. * Perform necessary actions before module is disabled.
  3506. *
  3507. * The hook is called every time the module is disabled. It should be
  3508. * implemented in the module's .install file. The implementation can rely
  3509. * on the .module file being loaded.
  3510. *
  3511. * @see hook_uninstall()
  3512. * @see hook_modules_disabled()
  3513. */
  3514. function hook_disable() {
  3515. mymodule_cache_rebuild();
  3516. }
  3517. /**
  3518. * Perform necessary alterations to the list of files parsed by the registry.
  3519. *
  3520. * Modules can manually modify the list of files before the registry parses
  3521. * them. The $modules array provides the .info file information, which includes
  3522. * the list of files registered to each module. Any files in the list can then
  3523. * be added to the list of files that the registry will parse, or modify
  3524. * attributes of a file.
  3525. *
  3526. * A necessary alteration made by the core SimpleTest module is to force .test
  3527. * files provided by disabled modules into the list of files parsed by the
  3528. * registry.
  3529. *
  3530. * @param $files
  3531. * List of files to be parsed by the registry. The list will contain
  3532. * files found in each enabled module's info file and the core includes
  3533. * directory. The array is keyed by the file path and contains an array of
  3534. * the related module's name and weight as used internally by
  3535. * _registry_update() and related functions.
  3536. *
  3537. * For example:
  3538. * @code
  3539. * $files["modules/system/system.module"] = array(
  3540. * 'module' => 'system',
  3541. * 'weight' => 0,
  3542. * );
  3543. * @endcode
  3544. * @param $modules
  3545. * An array containing all module information stored in the {system} table.
  3546. * Each element of the array also contains the module's .info file
  3547. * information in the property 'info'. An additional 'dir' property has been
  3548. * added to the module information which provides the path to the directory
  3549. * in which the module resides. The example shows how to take advantage of
  3550. * both properties.
  3551. *
  3552. * @see _registry_update()
  3553. * @see simpletest_test_get_all()
  3554. */
  3555. function hook_registry_files_alter(&$files, $modules) {
  3556. foreach ($modules as $module) {
  3557. // Only add test files for disabled modules, as enabled modules should
  3558. // already include any test files they provide.
  3559. if (!$module->status) {
  3560. $dir = $module->dir;
  3561. foreach ($module->info['files'] as $file) {
  3562. if (substr($file, -5) == '.test') {
  3563. $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
  3564. }
  3565. }
  3566. }
  3567. }
  3568. }
  3569. /**
  3570. * Return an array of tasks to be performed by an installation profile.
  3571. *
  3572. * Any tasks you define here will be run, in order, after the installer has
  3573. * finished the site configuration step but before it has moved on to the
  3574. * final import of languages and the end of the installation. You can have any
  3575. * number of custom tasks to perform during this phase.
  3576. *
  3577. * Each task you define here corresponds to a callback function which you must
  3578. * separately define and which is called when your task is run. This function
  3579. * will receive the global installation state variable, $install_state, as
  3580. * input, and has the opportunity to access or modify any of its settings. See
  3581. * the install_state_defaults() function in the installer for the list of
  3582. * $install_state settings used by Drupal core.
  3583. *
  3584. * At the end of your task function, you can indicate that you want the
  3585. * installer to pause and display a page to the user by returning any themed
  3586. * output that should be displayed on that page (but see below for tasks that
  3587. * use the form API or batch API; the return values of these task functions are
  3588. * handled differently). You should also use drupal_set_title() within the task
  3589. * callback function to set a custom page title. For some tasks, however, you
  3590. * may want to simply do some processing and pass control to the next task
  3591. * without ending the page request; to indicate this, simply do not send back
  3592. * a return value from your task function at all. This can be used, for
  3593. * example, by installation profiles that need to configure certain site
  3594. * settings in the database without obtaining any input from the user.
  3595. *
  3596. * The task function is treated specially if it defines a form or requires
  3597. * batch processing; in that case, you should return either the form API
  3598. * definition or batch API array, as appropriate. See below for more
  3599. * information on the 'type' key that you must define in the task definition
  3600. * to inform the installer that your task falls into one of those two
  3601. * categories. It is important to use these APIs directly, since the installer
  3602. * may be run non-interactively (for example, via a command line script), all
  3603. * in one page request; in that case, the installer will automatically take
  3604. * care of submitting forms and processing batches correctly for both types of
  3605. * installations. You can inspect the $install_state['interactive'] boolean to
  3606. * see whether or not the current installation is interactive, if you need
  3607. * access to this information.
  3608. *
  3609. * Remember that a user installing Drupal interactively will be able to reload
  3610. * an installation page multiple times, so you should use variable_set() and
  3611. * variable_get() if you are collecting any data that you need to store and
  3612. * inspect later. It is important to remove any temporary variables using
  3613. * variable_del() before your last task has completed and control is handed
  3614. * back to the installer.
  3615. *
  3616. * @param array $install_state
  3617. * An array of information about the current installation state.
  3618. *
  3619. * @return array
  3620. * A keyed array of tasks the profile will perform during the final stage of
  3621. * the installation. Each key represents the name of a function (usually a
  3622. * function defined by this profile, although that is not strictly required)
  3623. * that is called when that task is run. The values are associative arrays
  3624. * containing the following key-value pairs (all of which are optional):
  3625. * - display_name: The human-readable name of the task. This will be
  3626. * displayed to the user while the installer is running, along with a list
  3627. * of other tasks that are being run. Leave this unset to prevent the task
  3628. * from appearing in the list.
  3629. * - display: This is a boolean which can be used to provide finer-grained
  3630. * control over whether or not the task will display. This is mostly useful
  3631. * for tasks that are intended to display only under certain conditions;
  3632. * for these tasks, you can set 'display_name' to the name that you want to
  3633. * display, but then use this boolean to hide the task only when certain
  3634. * conditions apply.
  3635. * - type: A string representing the type of task. This parameter has three
  3636. * possible values:
  3637. * - normal: (default) This indicates that the task will be treated as a
  3638. * regular callback function, which does its processing and optionally
  3639. * returns HTML output.
  3640. * - batch: This indicates that the task function will return a batch API
  3641. * definition suitable for batch_set(). The installer will then take care
  3642. * of automatically running the task via batch processing.
  3643. * - form: This indicates that the task function will return a standard
  3644. * form API definition (and separately define validation and submit
  3645. * handlers, as appropriate). The installer will then take care of
  3646. * automatically directing the user through the form submission process.
  3647. * - run: A constant representing the manner in which the task will be run.
  3648. * This parameter has three possible values:
  3649. * - INSTALL_TASK_RUN_IF_NOT_COMPLETED: (default) This indicates that the
  3650. * task will run once during the installation of the profile.
  3651. * - INSTALL_TASK_SKIP: This indicates that the task will not run during
  3652. * the current installation page request. It can be used to skip running
  3653. * an installation task when certain conditions are met, even though the
  3654. * task may still show on the list of installation tasks presented to the
  3655. * user.
  3656. * - INSTALL_TASK_RUN_IF_REACHED: This indicates that the task will run on
  3657. * each installation page request that reaches it. This is rarely
  3658. * necessary for an installation profile to use; it is primarily used by
  3659. * the Drupal installer for bootstrap-related tasks.
  3660. * - function: Normally this does not need to be set, but it can be used to
  3661. * force the installer to call a different function when the task is run
  3662. * (rather than the function whose name is given by the array key). This
  3663. * could be used, for example, to allow the same function to be called by
  3664. * two different tasks.
  3665. *
  3666. * @see install_state_defaults()
  3667. * @see batch_set()
  3668. */
  3669. function hook_install_tasks(&$install_state) {
  3670. // Here, we define a variable to allow tasks to indicate that a particular,
  3671. // processor-intensive batch process needs to be triggered later on in the
  3672. // installation.
  3673. $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE);
  3674. $tasks = array(
  3675. // This is an example of a task that defines a form which the user who is
  3676. // installing the site will be asked to fill out. To implement this task,
  3677. // your profile would define a function named myprofile_data_import_form()
  3678. // as a normal form API callback function, with associated validation and
  3679. // submit handlers. In the submit handler, in addition to saving whatever
  3680. // other data you have collected from the user, you might also call
  3681. // variable_set('myprofile_needs_batch_processing', TRUE) if the user has
  3682. // entered data which requires that batch processing will need to occur
  3683. // later on.
  3684. 'myprofile_data_import_form' => array(
  3685. 'display_name' => st('Data import options'),
  3686. 'type' => 'form',
  3687. ),
  3688. // Similarly, to implement this task, your profile would define a function
  3689. // named myprofile_settings_form() with associated validation and submit
  3690. // handlers. This form might be used to collect and save additional
  3691. // information from the user that your profile needs. There are no extra
  3692. // steps required for your profile to act as an "installation wizard"; you
  3693. // can simply define as many tasks of type 'form' as you wish to execute,
  3694. // and the forms will be presented to the user, one after another.
  3695. 'myprofile_settings_form' => array(
  3696. 'display_name' => st('Additional options'),
  3697. 'type' => 'form',
  3698. ),
  3699. // This is an example of a task that performs batch operations. To
  3700. // implement this task, your profile would define a function named
  3701. // myprofile_batch_processing() which returns a batch API array definition
  3702. // that the installer will use to execute your batch operations. Due to the
  3703. // 'myprofile_needs_batch_processing' variable used here, this task will be
  3704. // hidden and skipped unless your profile set it to TRUE in one of the
  3705. // previous tasks.
  3706. 'myprofile_batch_processing' => array(
  3707. 'display_name' => st('Import additional data'),
  3708. 'display' => $myprofile_needs_batch_processing,
  3709. 'type' => 'batch',
  3710. 'run' => $myprofile_needs_batch_processing ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
  3711. ),
  3712. // This is an example of a task that will not be displayed in the list that
  3713. // the user sees. To implement this task, your profile would define a
  3714. // function named myprofile_final_site_setup(), in which additional,
  3715. // automated site setup operations would be performed. Since this is the
  3716. // last task defined by your profile, you should also use this function to
  3717. // call variable_del('myprofile_needs_batch_processing') and clean up the
  3718. // variable that was used above. If you want the user to pass to the final
  3719. // Drupal installation tasks uninterrupted, return no output from this
  3720. // function. Otherwise, return themed output that the user will see (for
  3721. // example, a confirmation page explaining that your profile's tasks are
  3722. // complete, with a link to reload the current page and therefore pass on
  3723. // to the final Drupal installation tasks when the user is ready to do so).
  3724. 'myprofile_final_site_setup' => array(
  3725. ),
  3726. );
  3727. return $tasks;
  3728. }
  3729. /**
  3730. * Change the page the user is sent to by drupal_goto().
  3731. *
  3732. * @param $path
  3733. * A Drupal path or a full URL.
  3734. * @param $options
  3735. * An associative array of additional URL options to pass to url().
  3736. * @param $http_response_code
  3737. * The HTTP status code to use for the redirection. See drupal_goto() for more
  3738. * information.
  3739. */
  3740. function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) {
  3741. // A good addition to misery module.
  3742. $http_response_code = 500;
  3743. }
  3744. /**
  3745. * Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().
  3746. *
  3747. * Elements available to be altered are only those added using
  3748. * drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files
  3749. * are handled using drupal_add_css() and drupal_add_js(), so the head links
  3750. * for those files will not appear in the $head_elements array.
  3751. *
  3752. * @param $head_elements
  3753. * An array of renderable elements. Generally the values of the #attributes
  3754. * array will be the most likely target for changes.
  3755. */
  3756. function hook_html_head_alter(&$head_elements) {
  3757. foreach ($head_elements as $key => $element) {
  3758. if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
  3759. // I want a custom canonical URL.
  3760. $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
  3761. }
  3762. }
  3763. }
  3764. /**
  3765. * Alter the full list of installation tasks.
  3766. *
  3767. * @param $tasks
  3768. * An array of all available installation tasks, including those provided by
  3769. * Drupal core. You can modify this array to change or replace any part of
  3770. * the Drupal installation process that occurs after the installation profile
  3771. * is selected.
  3772. * @param $install_state
  3773. * An array of information about the current installation state.
  3774. */
  3775. function hook_install_tasks_alter(&$tasks, $install_state) {
  3776. // Replace the "Choose language" installation task provided by Drupal core
  3777. // with a custom callback function defined by this installation profile.
  3778. $tasks['install_select_locale']['function'] = 'myprofile_locale_selection';
  3779. }
  3780. /**
  3781. * Alter MIME type mappings used to determine MIME type from a file extension.
  3782. *
  3783. * This hook is run when file_mimetype_mapping() is called. It is used to
  3784. * allow modules to add to or modify the default mapping from
  3785. * file_default_mimetype_mapping().
  3786. *
  3787. * @param $mapping
  3788. * An array of mimetypes correlated to the extensions that relate to them.
  3789. * The array has 'mimetypes' and 'extensions' elements, each of which is an
  3790. * array.
  3791. *
  3792. * @see file_default_mimetype_mapping()
  3793. */
  3794. function hook_file_mimetype_mapping_alter(&$mapping) {
  3795. // Add new MIME type 'drupal/info'.
  3796. $mapping['mimetypes']['example_info'] = 'drupal/info';
  3797. // Add new extension '.info' and map it to the 'drupal/info' MIME type.
  3798. $mapping['extensions']['info'] = 'example_info';
  3799. // Override existing extension mapping for '.ogg' files.
  3800. $mapping['extensions']['ogg'] = 189;
  3801. }
  3802. /**
  3803. * Declares information about actions.
  3804. *
  3805. * Any module can define actions, and then call actions_do() to make those
  3806. * actions happen in response to events. The trigger module provides a user
  3807. * interface for associating actions with module-defined triggers, and it makes
  3808. * sure the core triggers fire off actions when their events happen.
  3809. *
  3810. * An action consists of two or three parts:
  3811. * - an action definition (returned by this hook)
  3812. * - a function which performs the action (which by convention is named
  3813. * MODULE_description-of-function_action)
  3814. * - an optional form definition function that defines a configuration form
  3815. * (which has the name of the action function with '_form' appended to it.)
  3816. *
  3817. * The action function takes two to four arguments, which come from the input
  3818. * arguments to actions_do().
  3819. *
  3820. * @return
  3821. * An associative array of action descriptions. The keys of the array
  3822. * are the names of the action functions, and each corresponding value
  3823. * is an associative array with the following key-value pairs:
  3824. * - 'type': The type of object this action acts upon. Core actions have types
  3825. * 'node', 'user', 'comment', and 'system'.
  3826. * - 'label': The human-readable name of the action, which should be passed
  3827. * through the t() function for translation.
  3828. * - 'configurable': If FALSE, then the action doesn't require any extra
  3829. * configuration. If TRUE, then your module must define a form function with
  3830. * the same name as the action function with '_form' appended (e.g., the
  3831. * form for 'node_assign_owner_action' is 'node_assign_owner_action_form'.)
  3832. * This function takes $context as its only parameter, and is paired with
  3833. * the usual _submit function, and possibly a _validate function.
  3834. * - 'triggers': An array of the events (that is, hooks) that can trigger this
  3835. * action. For example: array('node_insert', 'user_update'). You can also
  3836. * declare support for any trigger by returning array('any') for this value.
  3837. * - 'behavior': (optional) A machine-readable array of behaviors of this
  3838. * action, used to signal additionally required actions that may need to be
  3839. * triggered. Currently recognized behaviors by Trigger module:
  3840. * - 'changes_property': If an action with this behavior is assigned to a
  3841. * trigger other than a "presave" hook, any save actions also assigned to
  3842. * this trigger are moved later in the list. If no save action is present,
  3843. * one will be added.
  3844. * Modules that are processing actions (like Trigger module) should take
  3845. * special care for the "presave" hook, in which case a dependent "save"
  3846. * action should NOT be invoked.
  3847. *
  3848. * @ingroup actions
  3849. */
  3850. function hook_action_info() {
  3851. return array(
  3852. 'comment_unpublish_action' => array(
  3853. 'type' => 'comment',
  3854. 'label' => t('Unpublish comment'),
  3855. 'configurable' => FALSE,
  3856. 'behavior' => array('changes_property'),
  3857. 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
  3858. ),
  3859. 'comment_unpublish_by_keyword_action' => array(
  3860. 'type' => 'comment',
  3861. 'label' => t('Unpublish comment containing keyword(s)'),
  3862. 'configurable' => TRUE,
  3863. 'behavior' => array('changes_property'),
  3864. 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
  3865. ),
  3866. 'comment_save_action' => array(
  3867. 'type' => 'comment',
  3868. 'label' => t('Save comment'),
  3869. 'configurable' => FALSE,
  3870. 'triggers' => array('comment_insert', 'comment_update'),
  3871. ),
  3872. );
  3873. }
  3874. /**
  3875. * Executes code after an action is deleted.
  3876. *
  3877. * @param $aid
  3878. * The action ID.
  3879. */
  3880. function hook_actions_delete($aid) {
  3881. db_delete('actions_assignments')
  3882. ->condition('aid', $aid)
  3883. ->execute();
  3884. }
  3885. /**
  3886. * Alters the actions declared by another module.
  3887. *
  3888. * Called by actions_list() to allow modules to alter the return values from
  3889. * implementations of hook_action_info().
  3890. *
  3891. * @see trigger_example_action_info_alter()
  3892. */
  3893. function hook_action_info_alter(&$actions) {
  3894. $actions['node_unpublish_action']['label'] = t('Unpublish and remove from public view.');
  3895. }
  3896. /**
  3897. * Declare archivers to the system.
  3898. *
  3899. * An archiver is a class that is able to package and unpackage one or more files
  3900. * into a single possibly compressed file. Common examples of such files are
  3901. * zip files and tar.gz files. All archiver classes must implement
  3902. * ArchiverInterface.
  3903. *
  3904. * Each entry should be keyed on a unique value, and specify three
  3905. * additional keys:
  3906. * - class: The name of the PHP class for this archiver.
  3907. * - extensions: An array of file extensions that this archiver supports.
  3908. * - weight: This optional key specifies the weight of this archiver.
  3909. * When mapping file extensions to archivers, the first archiver by
  3910. * weight found that supports the requested extension will be used.
  3911. *
  3912. * @see hook_archiver_info_alter()
  3913. */
  3914. function hook_archiver_info() {
  3915. return array(
  3916. 'tar' => array(
  3917. 'class' => 'ArchiverTar',
  3918. 'extensions' => array('tar', 'tar.gz', 'tar.bz2'),
  3919. ),
  3920. );
  3921. }
  3922. /**
  3923. * Alter archiver information declared by other modules.
  3924. *
  3925. * See hook_archiver_info() for a description of archivers and the archiver
  3926. * information structure.
  3927. *
  3928. * @param $info
  3929. * Archiver information to alter (return values from hook_archiver_info()).
  3930. */
  3931. function hook_archiver_info_alter(&$info) {
  3932. $info['tar']['extensions'][] = 'tgz';
  3933. }
  3934. /**
  3935. * Define additional date types.
  3936. *
  3937. * Next to the 'long', 'medium' and 'short' date types defined in core, any
  3938. * module can define additional types that can be used when displaying dates,
  3939. * by implementing this hook. A date type is basically just a name for a date
  3940. * format.
  3941. *
  3942. * Date types are used in the administration interface: a user can assign
  3943. * date format types defined in hook_date_formats() to date types defined in
  3944. * this hook. Once a format has been assigned by a user, the machine name of a
  3945. * type can be used in the format_date() function to format a date using the
  3946. * chosen formatting.
  3947. *
  3948. * To define a date type in a module and make sure a format has been assigned to
  3949. * it, without requiring a user to visit the administrative interface, use
  3950. * @code variable_set('date_format_' . $type, $format); @endcode
  3951. * where $type is the machine-readable name defined here, and $format is a PHP
  3952. * date format string.
  3953. *
  3954. * To avoid namespace collisions with date types defined by other modules, it is
  3955. * recommended that each date type starts with the module name. A date type
  3956. * can consist of letters, numbers and underscores.
  3957. *
  3958. * @return
  3959. * An array of date types where the keys are the machine-readable names and
  3960. * the values are the human-readable labels.
  3961. *
  3962. * @see hook_date_formats()
  3963. * @see format_date()
  3964. */
  3965. function hook_date_format_types() {
  3966. // Define the core date format types.
  3967. return array(
  3968. 'long' => t('Long'),
  3969. 'medium' => t('Medium'),
  3970. 'short' => t('Short'),
  3971. );
  3972. }
  3973. /**
  3974. * Modify existing date types.
  3975. *
  3976. * Allows other modules to modify existing date types like 'long'. Called by
  3977. * _system_date_format_types_build(). For instance, A module may use this hook
  3978. * to apply settings across all date types, such as locking all date types so
  3979. * they appear to be provided by the system.
  3980. *
  3981. * @param $types
  3982. * A list of date types. Each date type is keyed by the machine-readable name
  3983. * and the values are associative arrays containing:
  3984. * - is_new: Set to FALSE to override previous settings.
  3985. * - module: The name of the module that created the date type.
  3986. * - type: The machine-readable date type name.
  3987. * - title: The human-readable date type name.
  3988. * - locked: Specifies that the date type is system-provided.
  3989. */
  3990. function hook_date_format_types_alter(&$types) {
  3991. foreach ($types as $name => $type) {
  3992. $types[$name]['locked'] = 1;
  3993. }
  3994. }
  3995. /**
  3996. * Define additional date formats.
  3997. *
  3998. * This hook is used to define the PHP date format strings that can be assigned
  3999. * to date types in the administrative interface. A module can provide date
  4000. * format strings for the core-provided date types ('long', 'medium', and
  4001. * 'short'), or for date types defined in hook_date_format_types() by itself
  4002. * or another module.
  4003. *
  4004. * Since date formats can be locale-specific, you can specify the locales that
  4005. * each date format string applies to. There may be more than one locale for a
  4006. * format. There may also be more than one format for the same locale. For
  4007. * example d/m/Y and Y/m/d work equally well in some locales. You may wish to
  4008. * define some additional date formats that aren't specific to any one locale,
  4009. * for example, "Y m". For these cases, the 'locales' component of the return
  4010. * value should be omitted.
  4011. *
  4012. * Providing a date format here does not normally assign the format to be
  4013. * used with the associated date type -- a user has to choose a format for each
  4014. * date type in the administrative interface. There is one exception: locale
  4015. * initialization chooses a locale-specific format for the three core-provided
  4016. * types (see locale_get_localized_date_format() for details). If your module
  4017. * needs to ensure that a date type it defines has a format associated with it,
  4018. * call @code variable_set('date_format_' . $type, $format); @endcode
  4019. * where $type is the machine-readable name defined in hook_date_format_types(),
  4020. * and $format is a PHP date format string.
  4021. *
  4022. * @return
  4023. * A list of date formats to offer as choices in the administrative
  4024. * interface. Each date format is a keyed array consisting of three elements:
  4025. * - 'type': The date type name that this format can be used with, as
  4026. * declared in an implementation of hook_date_format_types().
  4027. * - 'format': A PHP date format string to use when formatting dates. It
  4028. * can contain any of the formatting options described at
  4029. * http://php.net/manual/function.date.php
  4030. * - 'locales': (optional) An array of 2 and 5 character locale codes,
  4031. * defining which locales this format applies to (for example, 'en',
  4032. * 'en-us', etc.). If your date format is not language-specific, leave this
  4033. * array empty.
  4034. *
  4035. * @see hook_date_format_types()
  4036. */
  4037. function hook_date_formats() {
  4038. return array(
  4039. array(
  4040. 'type' => 'mymodule_extra_long',
  4041. 'format' => 'l jS F Y H:i:s e',
  4042. 'locales' => array('en-ie'),
  4043. ),
  4044. array(
  4045. 'type' => 'mymodule_extra_long',
  4046. 'format' => 'l jS F Y h:i:sa',
  4047. 'locales' => array('en', 'en-us'),
  4048. ),
  4049. array(
  4050. 'type' => 'short',
  4051. 'format' => 'F Y',
  4052. 'locales' => array(),
  4053. ),
  4054. );
  4055. }
  4056. /**
  4057. * Alter date formats declared by another module.
  4058. *
  4059. * Called by _system_date_format_types_build() to allow modules to alter the
  4060. * return values from implementations of hook_date_formats().
  4061. */
  4062. function hook_date_formats_alter(&$formats) {
  4063. foreach ($formats as $id => $format) {
  4064. $formats[$id]['locales'][] = 'en-ca';
  4065. }
  4066. }
  4067. /**
  4068. * Alters the delivery callback used to send the result of the page callback to the browser.
  4069. *
  4070. * Called by drupal_deliver_page() to allow modules to alter how the
  4071. * page is delivered to the browser.
  4072. *
  4073. * This hook is intended for altering the delivery callback based on
  4074. * information unrelated to the path of the page accessed. For example,
  4075. * it can be used to set the delivery callback based on a HTTP request
  4076. * header (as shown in the code sample). To specify a delivery callback
  4077. * based on path information, use hook_menu() or hook_menu_alter().
  4078. *
  4079. * This hook can also be used as an API function that can be used to explicitly
  4080. * set the delivery callback from some other function. For example, for a module
  4081. * named MODULE:
  4082. * @code
  4083. * function MODULE_page_delivery_callback_alter(&$callback, $set = FALSE) {
  4084. * static $stored_callback;
  4085. * if ($set) {
  4086. * $stored_callback = $callback;
  4087. * }
  4088. * elseif (isset($stored_callback)) {
  4089. * $callback = $stored_callback;
  4090. * }
  4091. * }
  4092. * function SOMEWHERE_ELSE() {
  4093. * $desired_delivery_callback = 'foo';
  4094. * MODULE_page_delivery_callback_alter($desired_delivery_callback, TRUE);
  4095. * }
  4096. * @endcode
  4097. *
  4098. * @param $callback
  4099. * The name of a function.
  4100. *
  4101. * @see drupal_deliver_page()
  4102. */
  4103. function hook_page_delivery_callback_alter(&$callback) {
  4104. // jQuery sets a HTTP_X_REQUESTED_WITH header of 'XMLHttpRequest'.
  4105. // If a page would normally be delivered as an html page, and it is called
  4106. // from jQuery, deliver it instead as an Ajax response.
  4107. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $callback == 'drupal_deliver_html_page') {
  4108. $callback = 'ajax_deliver';
  4109. }
  4110. }
  4111. /**
  4112. * Alters theme operation links.
  4113. *
  4114. * @param $theme_groups
  4115. * An associative array containing groups of themes.
  4116. *
  4117. * @see system_themes_page()
  4118. */
  4119. function hook_system_themes_page_alter(&$theme_groups) {
  4120. foreach ($theme_groups as $state => &$group) {
  4121. foreach ($theme_groups[$state] as &$theme) {
  4122. // Add a foo link to each list of theme operations.
  4123. $theme->operations[] = array(
  4124. 'title' => t('Foo'),
  4125. 'href' => 'admin/appearance/foo',
  4126. 'query' => array('theme' => $theme->name)
  4127. );
  4128. }
  4129. }
  4130. }
  4131. /**
  4132. * Alters inbound URL requests.
  4133. *
  4134. * @param $path
  4135. * The path being constructed, which, if a path alias, has been resolved to a
  4136. * Drupal path by the database, and which also may have been altered by other
  4137. * modules before this one.
  4138. * @param $original_path
  4139. * The original path, before being checked for path aliases or altered by any
  4140. * modules.
  4141. * @param $path_language
  4142. * The language of the path.
  4143. *
  4144. * @see drupal_get_normal_path()
  4145. */
  4146. function hook_url_inbound_alter(&$path, $original_path, $path_language) {
  4147. // Create the path user/me/edit, which allows a user to edit their account.
  4148. if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) {
  4149. global $user;
  4150. $path = 'user/' . $user->uid . '/edit' . $matches[1];
  4151. }
  4152. }
  4153. /**
  4154. * Alters outbound URLs.
  4155. *
  4156. * @param $path
  4157. * The outbound path to alter, not adjusted for path aliases yet. It won't be
  4158. * adjusted for path aliases until all modules are finished altering it, thus
  4159. * being consistent with hook_url_inbound_alter(), which adjusts for all path
  4160. * aliases before allowing modules to alter it. This may have been altered by
  4161. * other modules before this one.
  4162. * @param $options
  4163. * A set of URL options for the URL so elements such as a fragment or a query
  4164. * string can be added to the URL.
  4165. * @param $original_path
  4166. * The original path, before being altered by any modules.
  4167. *
  4168. * @see url()
  4169. */
  4170. function hook_url_outbound_alter(&$path, &$options, $original_path) {
  4171. // Use an external RSS feed rather than the Drupal one.
  4172. if ($path == 'rss.xml') {
  4173. $path = 'http://example.com/rss.xml';
  4174. $options['external'] = TRUE;
  4175. }
  4176. // Instead of pointing to user/[uid]/edit, point to user/me/edit.
  4177. if (preg_match('|^user/([0-9]*)/edit(/.*)?|', $path, $matches)) {
  4178. global $user;
  4179. if ($user->uid == $matches[1]) {
  4180. $path = 'user/me/edit' . $matches[2];
  4181. }
  4182. }
  4183. }
  4184. /**
  4185. * Alter the username that is displayed for a user.
  4186. *
  4187. * Called by format_username() to allow modules to alter the username that's
  4188. * displayed. Can be used to ensure user privacy in situations where
  4189. * $account->name is too revealing.
  4190. *
  4191. * @param $name
  4192. * The string that format_username() will return.
  4193. *
  4194. * @param $account
  4195. * The account object passed to format_username().
  4196. *
  4197. * @see format_username()
  4198. */
  4199. function hook_username_alter(&$name, $account) {
  4200. // Display the user's uid instead of name.
  4201. if (isset($account->uid)) {
  4202. $name = t('User !uid', array('!uid' => $account->uid));
  4203. }
  4204. }
  4205. /**
  4206. * Provide replacement values for placeholder tokens.
  4207. *
  4208. * This hook is invoked when someone calls token_replace(). That function first
  4209. * scans the text for [type:token] patterns, and splits the needed tokens into
  4210. * groups by type. Then hook_tokens() is invoked on each token-type group,
  4211. * allowing your module to respond by providing replacement text for any of
  4212. * the tokens in the group that your module knows how to process.
  4213. *
  4214. * A module implementing this hook should also implement hook_token_info() in
  4215. * order to list its available tokens on editing screens.
  4216. *
  4217. * @param $type
  4218. * The machine-readable name of the type (group) of token being replaced, such
  4219. * as 'node', 'user', or another type defined by a hook_token_info()
  4220. * implementation.
  4221. * @param $tokens
  4222. * An array of tokens to be replaced. The keys are the machine-readable token
  4223. * names, and the values are the raw [type:token] strings that appeared in the
  4224. * original text.
  4225. * @param $data
  4226. * (optional) An associative array of data objects to be used when generating
  4227. * replacement values, as supplied in the $data parameter to token_replace().
  4228. * @param $options
  4229. * (optional) An associative array of options for token replacement; see
  4230. * token_replace() for possible values.
  4231. *
  4232. * @return
  4233. * An associative array of replacement values, keyed by the raw [type:token]
  4234. * strings from the original text.
  4235. *
  4236. * @see hook_token_info()
  4237. * @see hook_tokens_alter()
  4238. */
  4239. function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
  4240. $url_options = array('absolute' => TRUE);
  4241. if (isset($options['language'])) {
  4242. $url_options['language'] = $options['language'];
  4243. $language_code = $options['language']->language;
  4244. }
  4245. else {
  4246. $language_code = NULL;
  4247. }
  4248. $sanitize = !empty($options['sanitize']);
  4249. $replacements = array();
  4250. if ($type == 'node' && !empty($data['node'])) {
  4251. $node = $data['node'];
  4252. foreach ($tokens as $name => $original) {
  4253. switch ($name) {
  4254. // Simple key values on the node.
  4255. case 'nid':
  4256. $replacements[$original] = $node->nid;
  4257. break;
  4258. case 'title':
  4259. $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title;
  4260. break;
  4261. case 'edit-url':
  4262. $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options);
  4263. break;
  4264. // Default values for the chained tokens handled below.
  4265. case 'author':
  4266. $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
  4267. $replacements[$original] = $sanitize ? filter_xss($name) : $name;
  4268. break;
  4269. case 'created':
  4270. $replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code);
  4271. break;
  4272. }
  4273. }
  4274. if ($author_tokens = token_find_with_prefix($tokens, 'author')) {
  4275. $author = user_load($node->uid);
  4276. $replacements += token_generate('user', $author_tokens, array('user' => $author), $options);
  4277. }
  4278. if ($created_tokens = token_find_with_prefix($tokens, 'created')) {
  4279. $replacements += token_generate('date', $created_tokens, array('date' => $node->created), $options);
  4280. }
  4281. }
  4282. return $replacements;
  4283. }
  4284. /**
  4285. * Alter replacement values for placeholder tokens.
  4286. *
  4287. * @param $replacements
  4288. * An associative array of replacements returned by hook_tokens().
  4289. * @param $context
  4290. * The context in which hook_tokens() was called. An associative array with
  4291. * the following keys, which have the same meaning as the corresponding
  4292. * parameters of hook_tokens():
  4293. * - 'type'
  4294. * - 'tokens'
  4295. * - 'data'
  4296. * - 'options'
  4297. *
  4298. * @see hook_tokens()
  4299. */
  4300. function hook_tokens_alter(array &$replacements, array $context) {
  4301. $options = $context['options'];
  4302. if (isset($options['language'])) {
  4303. $url_options['language'] = $options['language'];
  4304. $language_code = $options['language']->language;
  4305. }
  4306. else {
  4307. $language_code = NULL;
  4308. }
  4309. $sanitize = !empty($options['sanitize']);
  4310. if ($context['type'] == 'node' && !empty($context['data']['node'])) {
  4311. $node = $context['data']['node'];
  4312. // Alter the [node:title] token, and replace it with the rendered content
  4313. // of a field (field_title).
  4314. if (isset($context['tokens']['title'])) {
  4315. $title = field_view_field('node', $node, 'field_title', 'default', $language_code);
  4316. $replacements[$context['tokens']['title']] = drupal_render($title);
  4317. }
  4318. }
  4319. }
  4320. /**
  4321. * Provide information about available placeholder tokens and token types.
  4322. *
  4323. * Tokens are placeholders that can be put into text by using the syntax
  4324. * [type:token], where type is the machine-readable name of a token type, and
  4325. * token is the machine-readable name of a token within this group. This hook
  4326. * provides a list of types and tokens to be displayed on text editing screens,
  4327. * so that people editing text can see what their token options are.
  4328. *
  4329. * The actual token replacement is done by token_replace(), which invokes
  4330. * hook_tokens(). Your module will need to implement that hook in order to
  4331. * generate token replacements from the tokens defined here.
  4332. *
  4333. * @return
  4334. * An associative array of available tokens and token types. The outer array
  4335. * has two components:
  4336. * - types: An associative array of token types (groups). Each token type is
  4337. * an associative array with the following components:
  4338. * - name: The translated human-readable short name of the token type.
  4339. * - description: A translated longer description of the token type.
  4340. * - needs-data: The type of data that must be provided to token_replace()
  4341. * in the $data argument (i.e., the key name in $data) in order for tokens
  4342. * of this type to be used in the $text being processed. For instance, if
  4343. * the token needs a node object, 'needs-data' should be 'node', and to
  4344. * use this token in token_replace(), the caller needs to supply a node
  4345. * object as $data['node']. Some token data can also be supplied
  4346. * indirectly; for instance, a node object in $data supplies a user object
  4347. * (the author of the node), allowing user tokens to be used when only
  4348. * a node data object is supplied.
  4349. * - tokens: An associative array of tokens. The outer array is keyed by the
  4350. * group name (the same key as in the types array). Within each group of
  4351. * tokens, each token item is keyed by the machine name of the token, and
  4352. * each token item has the following components:
  4353. * - name: The translated human-readable short name of the token.
  4354. * - description: A translated longer description of the token.
  4355. * - type (optional): A 'needs-data' data type supplied by this token, which
  4356. * should match a 'needs-data' value from another token type. For example,
  4357. * the node author token provides a user object, which can then be used
  4358. * for token replacement data in token_replace() without having to supply
  4359. * a separate user object.
  4360. *
  4361. * @see hook_token_info_alter()
  4362. * @see hook_tokens()
  4363. */
  4364. function hook_token_info() {
  4365. $type = array(
  4366. 'name' => t('Nodes'),
  4367. 'description' => t('Tokens related to individual nodes.'),
  4368. 'needs-data' => 'node',
  4369. );
  4370. // Core tokens for nodes.
  4371. $node['nid'] = array(
  4372. 'name' => t("Node ID"),
  4373. 'description' => t("The unique ID of the node."),
  4374. );
  4375. $node['title'] = array(
  4376. 'name' => t("Title"),
  4377. 'description' => t("The title of the node."),
  4378. );
  4379. $node['edit-url'] = array(
  4380. 'name' => t("Edit URL"),
  4381. 'description' => t("The URL of the node's edit page."),
  4382. );
  4383. // Chained tokens for nodes.
  4384. $node['created'] = array(
  4385. 'name' => t("Date created"),
  4386. 'description' => t("The date the node was posted."),
  4387. 'type' => 'date',
  4388. );
  4389. $node['author'] = array(
  4390. 'name' => t("Author"),
  4391. 'description' => t("The author of the node."),
  4392. 'type' => 'user',
  4393. );
  4394. return array(
  4395. 'types' => array('node' => $type),
  4396. 'tokens' => array('node' => $node),
  4397. );
  4398. }
  4399. /**
  4400. * Alter the metadata about available placeholder tokens and token types.
  4401. *
  4402. * @param $data
  4403. * The associative array of token definitions from hook_token_info().
  4404. *
  4405. * @see hook_token_info()
  4406. */
  4407. function hook_token_info_alter(&$data) {
  4408. // Modify description of node tokens for our site.
  4409. $data['tokens']['node']['nid'] = array(
  4410. 'name' => t("Node ID"),
  4411. 'description' => t("The unique ID of the article."),
  4412. );
  4413. $data['tokens']['node']['title'] = array(
  4414. 'name' => t("Title"),
  4415. 'description' => t("The title of the article."),
  4416. );
  4417. // Chained tokens for nodes.
  4418. $data['tokens']['node']['created'] = array(
  4419. 'name' => t("Date created"),
  4420. 'description' => t("The date the article was posted."),
  4421. 'type' => 'date',
  4422. );
  4423. }
  4424. /**
  4425. * Alter batch information before a batch is processed.
  4426. *
  4427. * Called by batch_process() to allow modules to alter a batch before it is
  4428. * processed.
  4429. *
  4430. * @param $batch
  4431. * The associative array of batch information. See batch_set() for details on
  4432. * what this could contain.
  4433. *
  4434. * @see batch_set()
  4435. * @see batch_process()
  4436. *
  4437. * @ingroup batch
  4438. */
  4439. function hook_batch_alter(&$batch) {
  4440. // If the current page request is inside the overlay, add ?render=overlay to
  4441. // the success callback URL, so that it appears correctly within the overlay.
  4442. if (overlay_get_mode() == 'child') {
  4443. if (isset($batch['url_options']['query'])) {
  4444. $batch['url_options']['query']['render'] = 'overlay';
  4445. }
  4446. else {
  4447. $batch['url_options']['query'] = array('render' => 'overlay');
  4448. }
  4449. }
  4450. }
  4451. /**
  4452. * Provide information on Updaters (classes that can update Drupal).
  4453. *
  4454. * An Updater is a class that knows how to update various parts of the Drupal
  4455. * file system, for example to update modules that have newer releases, or to
  4456. * install a new theme.
  4457. *
  4458. * @return
  4459. * An associative array of information about the updater(s) being provided.
  4460. * This array is keyed by a unique identifier for each updater, and the
  4461. * values are subarrays that can contain the following keys:
  4462. * - class: The name of the PHP class which implements this updater.
  4463. * - name: Human-readable name of this updater.
  4464. * - weight: Controls what order the Updater classes are consulted to decide
  4465. * which one should handle a given task. When an update task is being run,
  4466. * the system will loop through all the Updater classes defined in this
  4467. * registry in weight order and let each class respond to the task and
  4468. * decide if each Updater wants to handle the task. In general, this
  4469. * doesn't matter, but if you need to override an existing Updater, make
  4470. * sure your Updater has a lighter weight so that it comes first.
  4471. *
  4472. * @see drupal_get_updaters()
  4473. * @see hook_updater_info_alter()
  4474. */
  4475. function hook_updater_info() {
  4476. return array(
  4477. 'module' => array(
  4478. 'class' => 'ModuleUpdater',
  4479. 'name' => t('Update modules'),
  4480. 'weight' => 0,
  4481. ),
  4482. 'theme' => array(
  4483. 'class' => 'ThemeUpdater',
  4484. 'name' => t('Update themes'),
  4485. 'weight' => 0,
  4486. ),
  4487. );
  4488. }
  4489. /**
  4490. * Alter the Updater information array.
  4491. *
  4492. * An Updater is a class that knows how to update various parts of the Drupal
  4493. * file system, for example to update modules that have newer releases, or to
  4494. * install a new theme.
  4495. *
  4496. * @param array $updaters
  4497. * Associative array of updaters as defined through hook_updater_info().
  4498. * Alter this array directly.
  4499. *
  4500. * @see drupal_get_updaters()
  4501. * @see hook_updater_info()
  4502. */
  4503. function hook_updater_info_alter(&$updaters) {
  4504. // Adjust weight so that the theme Updater gets a chance to handle a given
  4505. // update task before module updaters.
  4506. $updaters['theme']['weight'] = -1;
  4507. }
  4508. /**
  4509. * Alter the default country list.
  4510. *
  4511. * @param $countries
  4512. * The associative array of countries keyed by ISO 3166-1 country code.
  4513. *
  4514. * @see country_get_list()
  4515. * @see _country_get_predefined_list()
  4516. */
  4517. function hook_countries_alter(&$countries) {
  4518. // Elbonia is now independent, so add it to the country list.
  4519. $countries['EB'] = 'Elbonia';
  4520. }
  4521. /**
  4522. * Control site status before menu dispatching.
  4523. *
  4524. * The hook is called after checking whether the site is offline but before
  4525. * the current router item is retrieved and executed by
  4526. * menu_execute_active_handler(). If the site is in offline mode,
  4527. * $menu_site_status is set to MENU_SITE_OFFLINE.
  4528. *
  4529. * @param $menu_site_status
  4530. * Supported values are MENU_SITE_OFFLINE, MENU_ACCESS_DENIED,
  4531. * MENU_NOT_FOUND and MENU_SITE_ONLINE. Any other value than
  4532. * MENU_SITE_ONLINE will skip the default menu handling system and be passed
  4533. * for delivery to drupal_deliver_page() with a NULL
  4534. * $default_delivery_callback.
  4535. * @param $path
  4536. * Contains the system path that is going to be loaded. This is read only,
  4537. * use hook_url_inbound_alter() to change the path.
  4538. */
  4539. function hook_menu_site_status_alter(&$menu_site_status, $path) {
  4540. // Allow access to my_module/authentication even if site is in offline mode.
  4541. if ($menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'my_module/authentication') {
  4542. $menu_site_status = MENU_SITE_ONLINE;
  4543. }
  4544. }
  4545. /**
  4546. * Register information about FileTransfer classes provided by a module.
  4547. *
  4548. * The FileTransfer class allows transferring files over a specific type of
  4549. * connection. Core provides classes for FTP and SSH. Contributed modules are
  4550. * free to extend the FileTransfer base class to add other connection types,
  4551. * and if these classes are registered via hook_filetransfer_info(), those
  4552. * connection types will be available to site administrators using the Update
  4553. * manager when they are redirected to the authorize.php script to authorize
  4554. * the file operations.
  4555. *
  4556. * @return array
  4557. * Nested array of information about FileTransfer classes. Each key is a
  4558. * FileTransfer type (not human readable, used for form elements and
  4559. * variable names, etc), and the values are subarrays that define properties
  4560. * of that type. The keys in each subarray are:
  4561. * - 'title': Required. The human-readable name of the connection type.
  4562. * - 'class': Required. The name of the FileTransfer class. The constructor
  4563. * will always be passed the full path to the root of the site that should
  4564. * be used to restrict where file transfer operations can occur (the $jail)
  4565. * and an array of settings values returned by the settings form.
  4566. * - 'file': Required. The include file containing the FileTransfer class.
  4567. * This should be a separate .inc file, not just the .module file, so that
  4568. * the minimum possible code is loaded when authorize.php is running.
  4569. * - 'file path': Optional. The directory (relative to the Drupal root)
  4570. * where the include file lives. If not defined, defaults to the base
  4571. * directory of the module implementing the hook.
  4572. * - 'weight': Optional. Integer weight used for sorting connection types on
  4573. * the authorize.php form.
  4574. *
  4575. * @see FileTransfer
  4576. * @see authorize.php
  4577. * @see hook_filetransfer_info_alter()
  4578. * @see drupal_get_filetransfer_info()
  4579. */
  4580. function hook_filetransfer_info() {
  4581. $info['sftp'] = array(
  4582. 'title' => t('SFTP (Secure FTP)'),
  4583. 'file' => 'sftp.filetransfer.inc',
  4584. 'class' => 'FileTransferSFTP',
  4585. 'weight' => 10,
  4586. );
  4587. return $info;
  4588. }
  4589. /**
  4590. * Alter the FileTransfer class registry.
  4591. *
  4592. * @param array $filetransfer_info
  4593. * Reference to a nested array containing information about the FileTransfer
  4594. * class registry.
  4595. *
  4596. * @see hook_filetransfer_info()
  4597. */
  4598. function hook_filetransfer_info_alter(&$filetransfer_info) {
  4599. if (variable_get('paranoia', FALSE)) {
  4600. // Remove the FTP option entirely.
  4601. unset($filetransfer_info['ftp']);
  4602. // Make sure the SSH option is listed first.
  4603. $filetransfer_info['ssh']['weight'] = -10;
  4604. }
  4605. }
  4606. /**
  4607. * @} End of "addtogroup hooks".
  4608. */
  4609. /**
  4610. * @addtogroup callbacks
  4611. * @{
  4612. */
  4613. /**
  4614. * Return the URI for an entity.
  4615. *
  4616. * Callback for hook_entity_info().
  4617. *
  4618. * @param $entity
  4619. * The entity to return the URI for.
  4620. *
  4621. * @return
  4622. * An associative array with the following elements:
  4623. * - 'path': The URL path for the entity.
  4624. * - 'options': (optional) An array of options for the url() function.
  4625. * The actual entity URI can be constructed by passing these elements to
  4626. * url().
  4627. */
  4628. function callback_entity_info_uri($entity) {
  4629. return array(
  4630. 'path' => 'node/' . $entity->nid,
  4631. );
  4632. }
  4633. /**
  4634. * Return the label of an entity.
  4635. *
  4636. * Callback for hook_entity_info().
  4637. *
  4638. * @param $entity
  4639. * The entity for which to generate the label.
  4640. * @param $entity_type
  4641. * The entity type; e.g., 'node' or 'user'.
  4642. *
  4643. * @return
  4644. * An unsanitized string with the label of the entity.
  4645. *
  4646. * @see entity_label()
  4647. */
  4648. function callback_entity_info_label($entity, $entity_type) {
  4649. return empty($entity->title) ? 'Untitled entity' : $entity->title;
  4650. }
  4651. /**
  4652. * Return the language code of the entity.
  4653. *
  4654. * Callback for hook_entity_info().
  4655. *
  4656. * The language callback is meant to be used primarily for temporary alterations
  4657. * of the property value.
  4658. *
  4659. * @param $entity
  4660. * The entity for which to return the language.
  4661. * @param $entity_type
  4662. * The entity type; e.g., 'node' or 'user'.
  4663. *
  4664. * @return
  4665. * The language code for the language of the entity.
  4666. *
  4667. * @see entity_language()
  4668. */
  4669. function callback_entity_info_language($entity, $entity_type) {
  4670. return $entity->language;
  4671. }
  4672. /**
  4673. * @} End of "addtogroup callbacks".
  4674. */
  4675. /**
  4676. * @defgroup update_api Update versions of API functions
  4677. * @{
  4678. * Functions that are similar to normal API functions, but do not invoke hooks.
  4679. *
  4680. * These simplified versions of core API functions are provided for use by
  4681. * update functions (hook_update_N() implementations).
  4682. *
  4683. * During database updates the schema of any module could be out of date. For
  4684. * this reason, caution is needed when using any API function within an update
  4685. * function - particularly CRUD functions, functions that depend on the schema
  4686. * (for example by using drupal_write_record()), and any functions that invoke
  4687. * hooks.
  4688. *
  4689. * Instead, a simplified utility function should be used. If a utility version
  4690. * of the API function you require does not already exist, then you should
  4691. * create a new function. The new utility function should be named
  4692. * _update_N_mymodule_my_function(). N is the schema version the function acts
  4693. * on (the schema version is the number N from the hook_update_N()
  4694. * implementation where this schema was introduced, or a number following the
  4695. * same numbering scheme), and mymodule_my_function is the name of the original
  4696. * API function including the module's name.
  4697. *
  4698. * Examples:
  4699. * - _update_6000_mymodule_save(): This function performs a save operation
  4700. * without invoking any hooks using the 6.x schema.
  4701. * - _update_7000_mymodule_save(): This function performs the same save
  4702. * operation using the 7.x schema.
  4703. *
  4704. * The utility function should not invoke any hooks, and should perform database
  4705. * operations using functions from the
  4706. * @link database Database abstraction layer, @endlink
  4707. * like db_insert(), db_update(), db_delete(), db_query(), and so on.
  4708. *
  4709. * If a change to the schema necessitates a change to the utility function, a
  4710. * new function should be created with a name based on the version of the schema
  4711. * it acts on. See _update_7000_bar_get_types() and _update_7001_bar_get_types()
  4712. * in the code examples that follow.
  4713. *
  4714. * For example, foo.install could contain:
  4715. * @code
  4716. * function foo_update_dependencies() {
  4717. * // foo_update_7010() needs to run after bar_update_7000().
  4718. * $dependencies['foo'][7010] = array(
  4719. * 'bar' => 7000,
  4720. * );
  4721. *
  4722. * // foo_update_7036() needs to run after bar_update_7001().
  4723. * $dependencies['foo'][7036] = array(
  4724. * 'bar' => 7001,
  4725. * );
  4726. *
  4727. * return $dependencies;
  4728. * }
  4729. *
  4730. * function foo_update_7000() {
  4731. * // No updates have been run on the {bar_types} table yet, so this needs
  4732. * // to work with the 6.x schema.
  4733. * foreach (_update_6000_bar_get_types() as $type) {
  4734. * // Rename a variable.
  4735. * }
  4736. * }
  4737. *
  4738. * function foo_update_7010() {
  4739. * // Since foo_update_7010() is going to run after bar_update_7000(), it
  4740. * // needs to operate on the new schema, not the old one.
  4741. * foreach (_update_7000_bar_get_types() as $type) {
  4742. * // Rename a different variable.
  4743. * }
  4744. * }
  4745. *
  4746. * function foo_update_7036() {
  4747. * // This update will run after bar_update_7001().
  4748. * foreach (_update_7001_bar_get_types() as $type) {
  4749. * }
  4750. * }
  4751. * @endcode
  4752. *
  4753. * And bar.install could contain:
  4754. * @code
  4755. * function bar_update_7000() {
  4756. * // Type and bundle are confusing, so we renamed the table.
  4757. * db_rename_table('bar_types', 'bar_bundles');
  4758. * }
  4759. *
  4760. * function bar_update_7001() {
  4761. * // Database table names should be singular when possible.
  4762. * db_rename_table('bar_bundles', 'bar_bundle');
  4763. * }
  4764. *
  4765. * function _update_6000_bar_get_types() {
  4766. * db_query('SELECT * FROM {bar_types}')->fetchAll();
  4767. * }
  4768. *
  4769. * function _update_7000_bar_get_types() {
  4770. * db_query('SELECT * FROM {bar_bundles'})->fetchAll();
  4771. * }
  4772. *
  4773. * function _update_7001_bar_get_types() {
  4774. * db_query('SELECT * FROM {bar_bundle}')->fetchAll();
  4775. * }
  4776. * @endcode
  4777. *
  4778. * @see hook_update_N()
  4779. * @see hook_update_dependencies()
  4780. */
  4781. /**
  4782. * @} End of "defgroup update_api".
  4783. */