system.api.php 199 KB

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