table of contentsdrupal blocks are best described as content containers. they are the primary tool...

66
1.1 1.2 1.3 2.1 2.2 3.1 3.1.1 3.1.2 3.2 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.3 3.3.1 3.3.2 3.4 3.4.1 3.5 3.5.1 3.5.2 3.5.3 3.6 3.6.1 4.1 4.2 Table of Contents Part 0: Getting Started Cover sheet CERN: Working with WebDAV CERN: Working with the Cloud Editor Part 1: Migration Background Information What can be migrated? Additional Resources Part 2: Site Building Blocks Working with Blocks and Theme Regions Working with Custom Block Types Content Types and Fields Working with Content Types Working with Fields Working with View Modes Working with Paragraphs Working with CERN Patterns Views Working with Views Working with Views Display Types Workflows Working with Workflows Roles and Permissions Working with User Accounts Working with Roles and Permissions CERN: Linking User Roles with EGroups CERN Page Types CERN Landing Page Part 3: Site Styling Working with Themes Theme Inheritance 1

Upload: others

Post on 15-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

1.1

1.2

1.3

2.1

2.2

3.1

3.1.1

3.1.2

3.2

3.2.1

3.2.2

3.2.3

3.2.4

3.2.5

3.3

3.3.1

3.3.2

3.4

3.4.1

3.5

3.5.1

3.5.2

3.5.3

3.6

3.6.1

4.1

4.2

TableofContents

Part0:GettingStarted

Coversheet

CERN:WorkingwithWebDAV

CERN:WorkingwiththeCloudEditor

Part1:MigrationBackgroundInformation

Whatcanbemigrated?

AdditionalResources

Part2:SiteBuilding

Blocks

WorkingwithBlocksandThemeRegions

WorkingwithCustomBlockTypes

ContentTypesandFields

WorkingwithContentTypes

WorkingwithFields

WorkingwithViewModes

WorkingwithParagraphs

WorkingwithCERNPatterns

Views

WorkingwithViews

WorkingwithViewsDisplayTypes

Workflows

WorkingwithWorkflows

RolesandPermissions

WorkingwithUserAccounts

WorkingwithRolesandPermissions

CERN:LinkingUserRoleswithEGroups

CERNPageTypes

CERNLandingPage

Part3:SiteStyling

WorkingwithThemes

ThemeInheritance

1

Page 2: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

4.3

4.4

4.5

4.5.1

4.5.2

4.5.3

4.6

4.6.1

4.6.2

5.1

5.2

5.3

CERNBaseandCERNOverride

ThemeConfigurationSettings

AssetLibraries

AssetLibraries:Introduction

AssetLibraries:Dependencies

AssetLibraries:Properties

Twig

Twig:TemplateFilenameConventions

Twig:AddingAssetLibraries

Part4:BonusMaterial

WorkingwithMultipleLanguages

WritingCustomMigrations

AdditionalResources

2

Page 3: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

CERN-WorkingwithamigratedD8siteDrupalversion:8.7.0Curriculumversion:3Documentversion:1

Credits:Thisguideisbasedinpartonthefollowingmaterial:

http://drupal.org/documentation

Coversheet

3

Page 4: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithCERNWebDAVTomanuallyuploadmodulesorthemestoyourCERNDrupalsiteyouneedtoaccessyoursite'ssourcecodedirectoryononeofCERN'sservers.

YoucandothisviatheWebDAVprotocoldescribedhere:https://information-technology.web.cern.ch/book/drupal-infrastructure-services/site-management/file-access

Inshort:

useyourWebDAVclientofchoicefortheoperatingsystemyouuseconnectto: YOURSITENAME.web.cern/_webdav(replaceYOURSITENAMEwithyoursite'sname)protocol:securewebdav(sometimescalledwebdavs)provideyourCERNusernameandpassword

Youcannowcopyfilestoandfromyoursite'ssourcecodedirectory.

WARNING:

Donotremoveanythingunlessyou'reabsolutelysurewhatyou'redoing.Ifyoudoremovemodulesorthemes,onlydosoAFTERyou'veCOMPLETELYuninstalledthem.

CERN:WorkingwithWebDAV

4

Page 5: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwiththeCloudEditorTrainingsites:

TRN1

https://test-d8-migration-trn1.web.cern.chusername:yourCERNusernamepassword:yourCERNpassword

https://ide-trn1.pathwayx.iousername:cernpassword:cern

TRN2

https://test-d8-migration-trn2.web.cern.chusername:yourCERNusernamepassword:yourCERNpassword

https://ide-trn2.pathwayx.iousername:cernpassword:cern

...

TRN10

https://test-d8-migration-trn10.web.cern.chusername:yourCERNusernamepassword:yourCERNpassword

https://ide-trn10.pathwayx.iousername:cernpassword:cern

CERN:WorkingwiththeCloudEditor

5

Page 6: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Whatcanbemigrated?manuallycreatedcontenttypesvocabulariesmenus

nodesmenususerstaxonomytermsmanuallycreatedblockscomments

sitenamesitesloganfrontpagesettingroles

Whatcannotbemigrated?moduleswithoutamigrationpathviews

Whatcanbemigrated?

6

Page 7: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

AdditionalResourceshttps://www.drupal.org/docs/8/upgradehttps://thinktandem.io/blog/2018/07/24/writing-a-custom-drupal-8-module-upgrade-path/

AdditionalResources

7

Page 8: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Blocks

Blocks

8

Page 9: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithBlocksandThemeRegionsTheBlocksadministrationpagecanbefoundathttp://example.com/admin/structure/block,alsoavailableatAdministration>Structure>BlockLayout.

Drupalblocksarebestdescribedascontentcontainers.Theyaretheprimarytooltoorganizeyoursite'scontent.

Blockscanholdstaticcontent,dynamiclistsofcontentandfunctionalitysuchasaloginformwithusernameandpasswordfields.

Blocksareeitheraddedmanuallyorprovidedbyamodule.Themoremodulesyouenable,themoreblockswillbecomeavaillableforyoutoplaceinthethemeregionsofyourchoosing.

Assigningblockstoregions

Oncedefined,blockscanbeplacedinanyoftheregionsyourthemeprovides,suchasasidebarorthefooterregion:

CreatingnewblocksToaddacustomablockwithstaticcontent:

1. clickontheCustomblocklibrarylinkatthetopoftheBlockLayoutadministrationpage.2. ClickontheAddcustomblockbutton

WorkingwithBlocksandThemeRegions

9

Page 10: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Theinterfacetomanagecustomblocksisquitesimilartotheinterfacetomanagecontent.AsofDrupal8,blocksarefieldable.Asaresult,thesameFieldUIisusedtomanageblocksand,shouldyouwishtodoso,addfieldstocustomblocktypes:

Blockdescription:Blocklabel(title)displayedontheBlockadministrationpage.Blockbody:theinformationdisplayedbytheblock

Blockinstanceoptions

Oncecreated,yourcustomblockisavailabletobeassignedtoaregionviaAdministration>Structure>BlockLayout:

WorkingwithBlocksandThemeRegions

10

Page 11: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

You'venowplacedaninstance(acopy)ofthatblockinacertainregion.Whenyougoandconfigurethatinstance,additionalblockoptionsbecomeavailable:

title:Blocklabel(title)displayedtositevisitorsafteryouplacetheblockinaregion.

Contenttypes:showthisblockonlyonpagesthatdisplaycontentofthegiventype(s).Ifyoudon'tselectanycontenttypes,theblockwillbeshownonallpagesthatmeetyourotherdisplayconditionregardlessofcontenttype.

Visibilitysettings:

Pages-setwhichpagestheblockshouldorshouldnotbedisplayedon.

Roles:showthisblockonlytouserswiththeselectedrole(s).Ifyoudon'tselectanyroles,theblockwillbevisibletoallusers.

Region:settheblockregionwheretheblockshouldappearonyoursite.YoucanalsosetthisdirectlyonthemainBlocksadministrationpage.

WorkingwithBlocksandThemeRegions

11

Page 12: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithBlocksandThemeRegions

12

Page 13: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithCustomBlockTypesInDrupal8blockshavebecomemuchmorepowerfulthaninDrupal7.

Theycannowweplacedindifferentregionsatthesametime,andtheyhavebecomefieldable,whichmeansyoucanaddcustomfieldstothemandusethemasminicontenttypes.

Howtocreatecustomblocktypes

AsofDrupal8,blockshaveblocktypes,sobeforeyoucancreateacustomblock,youfirstneedtocreateacustomblocktype,andthencreateablockofthattype.Thisprocessisidenticaltoworkingwithcustomcontenttypes.

1. CreateanewcustomblocktypeatAdmin>Structure>BlockLayout>CustomBlockLibrary>BlockTypes(/admin/structure/block/block-content/types)

2. Thenewblocktypenowappearsinthelistofcustomblocktypes.3. Addfieldstothenewblocktypeviaits"managefields"link.4. CreateanewblockatAdmin>Structure>BlockLayout>CustomBlockLibrary(/admin/structure/block/block-

content/types)5. Choosethenewlycreatedcustomblocktypefromthelistofavailableblocktypes.

Whentocreatecustomblocktypes

Itcanbedifficulttodecidewhethertobuildacustomcontenttypeoraacustomblocktypesinceyoucanaddfieldstobothofthem.

Afewrulesofthumbtohelpyoudecide:

iftheinformationshouldbeviewablestand-alone,withitsownaddress,useacontenttypeiftheinformationismeanttobeshownalongside(many)otherpages(mostlyinasidebar),useablocktype.iftheinformationfeelsmorelikeabuildingblocktobeusedtocreatelandingpages,anddoesn'treallystandonitsown,useablocktype.

WorkingwithCustomBlockTypes

13

Page 14: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

ContentTypesandFields

ContentTypesandFields

14

Page 15: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithContentTypesUserswiththeAdministercontenttypespermissionhavetheabilitytocreatenewcontenttypesandaddmodifyexistingones.

Customcontenttypesgiveyoutheflexibilitytoaddanddeletefieldsandconfiguredefaultsettingsthatsuitthedifferentneedsofvarioustypesofsitecontent.

ToaddnewcontenttypesinDrupal8,navigatetoAdministration>Structure>ContentTypes>Addcontenttype(http://example.com/admin/structure/types/add).

InDrupal8,aContentType'sconfigurationconsistsoftwoparts:

baseconfigurationfieldconfiguration

Thebaseconfigurationofacontenttypedefinesthedefaultbehaviorandpropertiesofthecontenttype.

Examplesinclude:

statuspublishedbydefaultornot?associatedwithoneormoremenus?display"Authoredby{name}on{date}"?...

ThefieldconfigurationdefineswhichadditionalfieldsareaddedtotheContentType,ifany,andhowtheyshouldbedisplayed.

FieldsarediscussedinmoredetailintheWorkingwithFieldssection.

WorkingwithContentTypes

15

Page 16: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithFieldsContentTypesarefieldable,aDrupalismwhichmeansthatthroughDrupal'sFieldUIyoucanaddadditionalfields,reorganisefields,anddefinehowthefieldsshouldbedisplayed.

Addingafield

Thereareseveraldecisionsyouwillneedtomakewhendefiningafield:

Namingafield

Afieldhasalabel(thenamedisplayedintheuserinterface)andamachinename(auniqueidentifierusedinternally).

Note:thelabelcanbechangedatwilllateron,butthemachinenamecannot.

Definingwhattypeofdatathefieldwillcontain

Thechoiceoffieldtypeisdrivenbythetypeofdatayouwantthefieldtostore.Eachfieldtypehasspecificfeaturesyouwon'tfindonotherfields.

Example:

"Integernumber"fieldshavebuilt-invalidationrulestoensureentereddataisnumericalandonlycontainswholenumbers.Datefieldshaveabuilt-incalendarwidgetforeasydateselectionandhavedate-relatedvalidationrules.

Note:

afteryou'vecreatedthefieldyoucannolongerchangeitstype.

Defininghowthedatawillbeenteredanddisplayed

Eachfieldtypehasoneormoreassociated"displaywidgets",eachofwhichprovidesamechanismfordatainputwhenyouareediting(textbox,selectlist,checkboxes,fileupload,...).

Eachfieldtypealsohasoneormoredisplayoptions,whichdeterminehowthefieldisdisplayedtositevisitors.Thewidgetanddisplayoptionscanbechangedafteryouhavecreatedthefield.

Defininghowmanyvaluesthefieldcancontain

Foreachfieldyoumustdefinethenumberofvaluesitcanstore:

WorkingwithFields

16

Page 17: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

onevalueaspecificmaximumnumberofvaluesanunlimitednumberofvalues.

Example:AProductIDfield(SKU)willonlyholdasinglevaluewhileaphonenumberfieldmigghtstoremultiplevalues-oneforeachnumber.

Thissettingcanbechangedafteryouhavecreatedthefield,butifyoureducethemaximumnumberofvaluesafterdatahasalreadybeenentered,youmayloseinformation.

ReusingafieldPreviouslydefinedfieldscanbereused.

Example:Ifyoudefineacustomimagefieldforonecontenttype,andyouneedtohaveanimagefieldwiththesamesettingsonanothercontenttype,youcanaddthesamefieldtothesecondcontenttype.

Caution:Somesettingsofareusedfieldaresharedacrossallofitsinstances,whileothersettingsareuniquetoeachinstance.Forexample,thelabelofatextfieldisuniquetoeachinstance(youcannamethefield"BookTitle"ononeContentType,whilecallingit"ProductionTitle"onanother),whilethesettingforthenumberofvaluesisshared(changeitforoneinstanceandalloftheotherinstancesofthesharedfieldaremodifiedaswell).

Whyreuseafield

Reusingfieldscansaveyoutimeasitavoidsredefiningthesamefieldsoverandoveragain.

Reusingfieldscanbeadvantageousasitallowsyoutoreusespecificcustomthemecodeandthemelogicusedtodefinehowthatfieldshouldbedisplayed.

WhyNOTtoreuseafield

Advancedfield-levelconfiguration

Ifyou'reunsureofcertainadvancedconfigurationsyoumaywanttodoonafieldlevelinthefuture,it'sbetternottoreusefieldstoomuch.

Example:Withtheuseofadditionalmodulesit'spossibletoconfigurefield-levelpermissionsandsetupscenariossuchas"Onlyuserswiththe'Staff'rolecanuseandseethe'Internalcomment"field.Thesepermissionswillapplyacrossallinstancesofthatfield-itwon'tbepossibletoturnthemonoroffonaper-contenttypebasis.

Feature-baseddeployment

Theoften-usedconfigurationdeploymentmechanismFeatures(offeredbytheFeaturesmodulepackagessetsconfigurationtogetherintofeaturemodules.Ifafieldisreusedaccrossmultiplecontenttypes,thatfielddefinitionbecomesadependencyoftwodifferentsetsofconfigurations-ascenariowhichFeatureshassometroublewith.

WorkingwithFields

17

Page 18: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithViewModes

WhatisaViewmode?

Howanentity(suchascontent,auseroracomment)isdisplayed,dependsonthecontextinwhichitisshown.Thiscontextisknownasaviewmode.

Examplesofviewmodesare:

afullpageofthecontentwithallthefieldvaluesateaserofthecontentwithathumbnailimageandaReadmorelinkafulluserprofilewithazoomableportraitphotoauseravatarwithusernameandalinktotheprofile

WorkingwithViewModes

18

Page 19: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Everyviewmodecanbeconfiguredthroughtheadministrationpages.ToseetheconfigurationoptionsfortheviewmodesoftheRecipecontenttype,navigatetoStructure>Contenttypes(admin/structure/types)andclickManagedisplayfromthedropdownbutton.

Ineachviewmode,allfieldscanbehiddenordisplayed.Iftheyaredisplayed,youcanchooseandconfigurethefieldformatter.

Whatisafieldformatter?

Afieldformatterisasettingfordisplayingthefieldvalues.Forexample,longtextfieldscanbedisplayedtrimmedorfull-length,andtaxonomytermreferencefieldscanbedisplayedinplaintextorlinkedtothetaxonomytermpage.ConsulttheManagedisplaypagetoseethefieldformattersforthefieldsoftheRecipecontenttype.

WorkingwithViewModes

19

Page 20: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithParagraphsTheusualwayofconstructingthecontentofapageinDrupalisbyusingthe"body"fieldtostoreallpageheaders,content,images,links,andsoon.Typically,onanygivenDrupalpageeverythingrevolvesaroundthe"body"field.

Whilethisisavalidapproach,itdoesn'tworkwellinallscenarios.It'strickytobuildresponsive,complex,mediaheavypagesthisway.

Anotherdisadvantageisthatit'sdifficulttoreuseexistingcontentwithinthebodyfield.

The"Paragraphs"approachisanalternativewayofassemblingpagecontent:Drupal’s"body"fieldisremoved,andinitsplacesitebuilderscanchoosefromanumberofpredefinedcomponents,

Paragraphtypes

It'suptothesite'sdevelopmentteamtodecidewhichtypesofparagraphs(components)tocreateandmakeavailabletoindividualsitebuilders.

Theseparagraphtypesofteninclude:

textwithalignedimagefull-widthimageslideshowlistofitems

TheseParagraphseffectivelybecomecomponentsthatsitebuilderscanusetoassemblepages.

Recap

Contenttypesareusedtodefinedifferenttypesofcontent,andtheirproperties.Displaymodesareusedtodefinedifferentwaysinwhicheachcontenttypecanbedisplayed.Complexpagesareassembledfromexistingcontent,usingaselectionofcomponents.

WorkingwithParagraphs

20

Page 21: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithCERNPatternsDocumentation:https://webtools.web.cern.ch/technologies/drupal/expansion/cern-components

Patterns

Atthetimeofwriting(June2019),thefollowingCERNPatternsareavailable:

PreviewCardPreviewListFAQListAgendaBoxAgendaComingsoon

WorkingwithCERNPatterns

21

Page 22: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Views

Views

22

Page 23: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithViews

Viewsisaquerybuilder

ThefirstfundamentalthingyouneedtoknowaboutViewsisthatitisatooltobuilddatabasequerieswithoutwritingasinglelineofSQLcode.

ThenextthingyouneedtounderstandistheUserInterface.WefindtheViewsinitial"wizard"doesconfusenewlearners,thoughitismeanttobeaquick-startsimplifieduserinterface.

Justkeepinmind,likeanygoodwizard,onceit'sdoneitsmagic,itvanishes.Thewizardallowsyoutoselectsomeofthesettingsquickly.

ThemainViewsadministrativeinterfaceiswhereeveryviewiseditedandmaintained,oncecreatedwiththeinitialwizard.Theadministrativeinterfacecontainsavastamountofoptions.

WorkingwithViews

23

Page 24: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Tostartmakingsenseofeverythingthat'sgoingonhere,trytothinkofthemastwogroupsofactions:

whatdatatoselectfromthedatabasehowtodisplaythedatafetchedfromthedatabase:

Redarea:whattoselectandfilterfromthedatabase.

DisplaysFormatSortCriteriaPageSettingsPager

Greenarea:howtoformattheinformationandwheretodisplayit.

FieldsFilterCriteraContextualFiltersRelationshipsExposedForm

Whatdoyouwanttoselect?

Selectbasetabletostart(youcancombinetableswithrelationships).ApplyfiltersSelectfieldsor

Whereandhowshoulditappear?

Chooseaformatsuchaslist,table,etc.Chooseadisplaysuchaspages,blocks,RSSfeeds.WithadditionalmodulesmoreViewsdisplaytypesareavailable.

WorkingwithViews

24

Page 25: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithViewsDisplayTypesOneViewoftencontainsmorethanoneDisplay,eachservingadifferentpurpose,andeachhavingdifferentsettings.

InadditiontothedefaultMasterdisplay,aviewusuallycontainsdisplaysofthetypePageorBlock.LesscommonlyusedDisplayTypesincludeFeed,Attachment,Embed,andEntityReference.

MasterDisplay

TheMasterdisplaycontainsthedefaultsettingforagivenview.Everyadditionaldisplay,regardlessoftheDisplayType,willinherititsdefaultsettingsfromtheMasterdisplay.

TheMasterdisplayishiddenbydefault.It'sonlyvisibleifyouhaven'tcreatedanyotherdisplaysyet,orifyouhaveenabledthe"Alwaysshowthemaster(default)display"optionintheoveralViewssettingsatStructure>Views>Settings(admin/structure/views/settings):

PageDisplay

Pagedisplaysreturntheviewresultasapage,availableatagivenURL.

WorkingwithViewsDisplayTypes

25

Page 26: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Block

Blockdisplaysreturntheviewresultasablock:

BlocksgeneratedbytheViewsmodulearenodifferentfromtheotherDrupalblocksavailableatStructure>Blocklayout(admin/structure/block).

Feed

FeeddisplaysreturntheviewresultasanXMLfeed,availableatagivenURL.

Thefollowingfeedformatsareavailablebydefault:

RSSOPML

WorkingwithViewsDisplayTypes

26

Page 27: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Attachment

WithAttachmentDisplaysyoucanattachoutputtoanyoftheotherdisplaysinthesameview.

Theattachmentsettingsletyouspecify:

whichdisplaytoattachtowheretoattachit:before,after,orboth

EntityReferenceEntityReferenceDisplaysreturnalistofentitieswhichcanbeusedasthelistofpotentialvaluesforEntityReferencefields.

UsuallywhenyoucreateanEntityReferencefieldyouonlyindicatewhichtypesofentitiescanbereferenced(Users,Articles,...).

Ifyouwantmorecontroloverexactlywhichentitiescanbereferenced,oryouwanttoinfluencetheorderinwhichtheyappearintheEntityReferencefield'slistofoptions,youcanuseanEntityReferenceDisplay.

Examplescenario:

YouwanttoBasicPagestobeabletorefertooneormoreexistingArticlessoyoucanhaveablock"RelatedArticles"oneachBasicPage.

However,youonlywantpeopletobeabletoreferencecertainArticles,ratherthananyarticle.

Step1:createaviewwithanEntityReferencedisplay,andgiveitthetitle"Articles".

Step2:addanEntityReferencefield(Contentreference)totheBasicPageContentType,andcallit"RelatedArticles".

Step3:changetheReferencemethodfrom"Default"to"Views:Filterbyanentityreferenceview",andselecttheviewwiththeEntityReferencedisplayyoucreatedinstep1.

WorkingwithViewsDisplayTypes

27

Page 28: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Embed

EmbedDisplaysaremeanttobeprogrammaticallyincludedsomewhere.

Assuchtheydodon'thavean"EmbedSettings"configurationsectionthewaytheotherdisplaysdo.Anysettingssuchasfiltervaluesarepassedinprogrammatically.

Intheoryeverytypeofdisplaycanbeprogrammaticallyembedded.TheadvantagesoftheEmbedDisplaytypeare:

itsoutputcontainslessmarkup,sothere'slessmarkuptooverrideitssimplernaturemeansDrupalcanusefewerresourcestofullyrenderit,comparedtotheotherdisplaytypes.

ProgrammaticallyEmbeddingViewDisplays

Possiblewaystousecodetoembedaviewsdisplayinclude:

usingacustommodule,usingthe views_embed_view()PHPfunction.Seeapi.drupal.orgfordetails.usingaTwigtemplatefile,usingthe drupal_view()TwigfunctionprovidedbytheTwigTweakmodule.

WorkingwithViewsDisplayTypes

28

Page 29: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithViewsDisplayTypes

29

Page 30: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Workflows

Workflows

30

Page 31: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithWorkflowsThecoreWorkflowsModuleprovidesagenericworkflowengineontopwhichyoucandefinedifferentworkflows,eachwiththeirownworkflowstatesandworkflowtransitions.

Workflowsapplytoentities.Whichexactentitytypesagivenworkflowappliestodependsonthatworkflow'ssettings.

WorkflowsModule

ToenableworkflowsfunctionalityyoumustfirstinstalltheWorkflowsModule,whichispartofDrupalcorebutnotinstalledbydefault.

OncetheWorkflowsModuleisinstalled,youcanseetheavailableworkflowsatConfiguration>Workflow>Workflows(admin/config/workflow/workflows):

ContentModerationModuleBydefaulttherearenoworkflowtypesavailable.Youmustinstallamodulethatprovidesoneormoreworkflowtypes,suchasthecoreContentModerationModule:

WorkingwithWorkflows

31

Page 32: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Onceinstalled,theEditorialworkflowbecomesavailable:

NOTEatthetimeofwriting(D8.6.10)newworkflowtypescanonlybecreatedincode,bywritingacustommodule.Thismaychangeinthefuture.

WorkflowComponents

YoucanfindtheEditorialworkflow'scomponentsatConfig>Workflow>Workflows>Editorial(admin/config/workflow/workflows/manage/editorial)

Workflowshavethreemaincomponents:states,transitions,andtargetitems.

States

Anitemtowhichaworkflowappliesalwaysfindsitselfinoneofthedefinedworkflowstatesananygiventime.

TheEditorialworkflowhastheDraft,Published,andArchivedstates.IfthisworkflowisenabledfortheArticlecontenttype,atanygiventimeeacharticleisintheDraft,Published,orArchivedstate.

WorkingwithWorkflows

32

Page 33: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Foranygivenworkflowyoucanadd,rename,andremoveworkflowstates.

Transitions

Transitionsdefinebetweenwhichofthedefinedstatesanentitycanchange.

ConsidertheEditorialworkflow,withstatesDraft,Published,andArchived,andthefollowingtransitions:

CreateNewDraftPublishArchiveRestoretoDraftRestore

Youwon'tbeabletochangeanentitydirectlyfromDrafttoArchived,becausenotransitionbetweenthosetwostatesexists.You'llneedtodothisinmultiplesteps:

DrafttoPublishedPublishedtoArchived

WorkingwithWorkflows

33

Page 34: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Alsonotthatyouwon'tbeabletomakechangeswhilekeepinganentityintheArchivedstate,becausenotransitionbetweenthosetwostatesexists.Thestepsyou'llneedwillbe:

ArchivedtoDraftDrafttoPublishedPublishedtoArchived

Howfaryouwanttogoinenforcingamulti-stepworkfloworprovidingtransitionstoallowdirectchangesbetweenallstatesdependsentirelyonyoureditorialteam'sneeds.

TargetItems

Theentitytypesaworkflowcanbeappliedtoarelistedatthebottom:

AcommonconfigurationscenarioistoapplytheEditorialworkflowtooneormoreContenttypes.

Changinganindividualentity'sWorkflowState

Ifyou'veappliedtheEditorialworkflowtoaContenttype,forinstanceArticles,amoderationstatefieldappearsoneacharticle'scontenteditform(node/add/article),replacingthedefaultPublishedcheckbox:

WorkingwithWorkflows

34

Page 35: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithWorkflows

35

Page 36: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

RolesandPermissions

RolesandPermissions

36

Page 37: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithUserAccounts

Managinguseraccounts

Thelistofalltheuseraccountsislocatedathttp://example.com/admin/peopleorviaAdministration>People:

SimilarlytotheadministrativeContentlisting,thisscreenletsyoutoviewalluseraccounts,filterthemonrole,permissionandstatus,andperformbulkoperationssuchasdelete,blockandunblockonthem.

Viaauser'seditlinkyoucangoinandeditanindividualuser'saccountdetails,includingtheirusername,password,statusandassignedroles:

CreatingauserisdonethroughtheAdduserlinklocatedinthetoplefthandsideofthescreenabovethefiltersettings.Theentryformisidenticaltotheoneusedforeditingusersandprocessisstraightforward:fillinthemandatoryfields(username,password,emailaddress)andanyoftheoptionalonesandsave.

Managinggeneralaccountsettings

WorkingwithUserAccounts

37

Page 38: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Managinggeneralaccountsettings

Whilemanagingindividualuseraccountdetailsisdonethroughhttp://example.com/admin/admin/people,definingtheglobalcharacteristicsandsettingsofalluseraccountsisdoneathttp://example.com/admin/config/people/accounts,alsoavailableviaAdministration>Configuration>People>Accountsettings:

1. Definetheusernametodisplaywhenshowingcontentand/orcommentsbyanonymous(non-authenticated)users.

2. Definewhichroleshouldbeconsideredtheadministratorrole

3. Settingsrelatedtotheregistrationandcancellationofuseraccounts.Mainly:canuserscreatetheirownaccountsorcanonlyadministratorsdoso.

4. Whenauseraccountiscancelled,whatshouldhappentothecontentcreatedbythatuser?

5. Definethecontentoftheemailsthataresentoutuponvarioususerrelatedeventssuchasaccountcreation,accountcancellationandpasswordrecovery.

6. SinceusersareentitieswithinDrupal7,theyarefieldable-fieldscanbeattachedtothemsoyoucanbuildmoreextensiveuserprofiles.

Extendinguseraccountswithnewfields

Themanagefieldstabonhttp://example.com/admin/config/people/accounts/fieldsopensupthefamiliarFieldUIscreenthatisalsousedtoaddfieldstoContentTypes:

WorkingwithUserAccounts

38

Page 39: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Toaddfieldstousers,followthesamestepsasyouwouldwhenaddingfieldstoContentTypesorotherentitytypes.

WorkingwithUserAccounts

39

Page 40: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithRolesandPermissions

Understandingrolesandpermissions

Drupalprovidesasystembasedonrolesandpermissionstoallowyoutolimitaccesstoadministrativefeaturesandotherfunctionalitytocertaingroupsofpeople.

Theprincipleisstraightforward:

1. addarole(e.g.'editor')2. assignpermissionstothatrole(e.g.'cancreatearticles'and'candeletearticles')3. assignoneormoreuserstothatrole

Howrolesarenamedandhowmanyrolesyoucreateiscompletelyuptoyou:

youcouldhaverolesthataremodelledonexistingreal-worlddepartmentsinyourorganisation,suchas'editors','translators','management'.youcouldhaverolesnamed'members','partners','vendors'.youcouldhaveasingle'administrator'roleifonlyyouandahandfulofpeoplemanagethewholesite.

Oncearoleisadded,oneormorepermissionscanbeassignedtoit.PermissionsaredefinedbyDrupalitselfaswellasbyadditionalmodulesyouenable.If,forinstance,youweretoenabletheContactmodulewhichletsyoucreatecontactforms,anewsetofpermissionswillbecomeavailable.Inthisparticularcasethosewouldbe:

AdministercontactformsandcontactformsettingsUsethesite-widecontactformUseusers'personalcontactforms

Note:

Drupal'srolesandpermissionsarecumulative.negativepermissions(restrictions)arenotpossible.

Themorerolesapersonhas,themorepermissionsheorsheisgranted.Aspermissionscannotberestrictive,arolecannottakeawaypermissions,onlygiveapersonmorepermissions.

ThisalsomeansthatitisimpossibleforDrupalrolestoconflictwitheachother,asisbethecaseinothersystemswhereonerolecangrantaspecificpermissionandanotherrolecandenythatsamepermission,effectivelycausingaconflictifauserisassignedboththoseroles.

Drupalhastwospecial,system-definedroleswhichcannotberemoved:

TheAnonymoususerrole,assignedtoeveryvisitortothesitewhohasnot(yet)loggedin.Sinceeverynon-authenticatedvisitortothesitewillhaveallthepermissionsassignedtothisrole,itisimportanttobeverycarefulwhenconfiguringthisrole

TheAuthenticatedUserrole,assignedtoeveryuserwhologsintothesite,regardlessofanyotherrolethatmightbeassignedtothatuser.Assignpermissionsthatarecommontoall(non-anonymous)rolestotheAuthenticatedUserrole,andtheninadditionaddspecificpermissionstospecificrolesinagranularfashion.

ManagingrolesRolesandpermissionsaremanagedviatherolesandpermissionstabsrespectively,foundathttp://example.com/admin/config/people/permissions,alsoavailableatAdministration>people.

WorkingwithRolesandPermissions

40

Page 41: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Rolesaremanagedathttp://example.com/admin/people/permissions/roles:

Assigningpermissionstoroles

Clickingtheeditpermissionslinknexttoaroleleadstoalistofallthepermissionscurrentlydefinedinthesystem.Simplyselectthepermissionsyouwanttoassigntothatparticularroleandsave:

AssigningrolestousersRolescanbeassignedtousersintwoways:

WorkingwithRolesandPermissions

41

Page 42: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

1. througheachindividualuser'sprofilesettings:

2. bygoingtoAdministration>People,selectinganumberofusersandperformingtheupdateactionAddaroletotheselectedusers:

WorkingwithRolesandPermissions

42

Page 43: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

LinkingUserRolesandEGroupsWhileit'spossibleforyoutomanuallyassignpeopletothoseDrupalrolesyoucreated,atCERNyoushouldNOTdothis.

Ifyouneedtogivedifferentgroupsofpeopledifferentsetsofpermissions,useEGroups:

1. CreateanewEGroup2. CreateanewDrupalrole3. AssignthedesiredpermissionstothenewDrupalrole4. LinktheDrupalroletotheEGroupatAdmin>Configuration>Simplesamlphpauthsettings>Userinfoandsyncing

(/admin/config/people/simplesamlphp_auth/sync)

Syntax

Whilethissyntaxcanbecomequitecomplex,here'sanexampleitssimplestform:

administrator:egroups,=,drupal-admins-test-d8training-demo

Theabovestatementassignsthe'administrator'Drupalroltotheegroup'drupal-admins-test-d8training-demo'.

Whenindoubt,don'thesitatetoraiseasupportticket.

CERN:LinkingUserRoleswithEGroups

43

Page 44: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

CERNPageTypes

CERNPageTypes

44

Page 45: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

LandingPageLandingpagesareusedaseye-catchingpagesthatleadavisitordeeperdownintoyoursite.Theyarerarelythefinaldestinationofauser'sjourney,andassuchtendtobeusedfornavigationratherthanasaplaceholderforimportantcontent.

Documentation:https://webtools.web.cern.ch/technologies/drupal/expansion/landing-page

Sections&Components

AftercreatingaLandingPage,thefirstthingyouaddisoneormoresections.Youcanthinkofeachsectionasapage-widerow.

Insideeachsectionyouwillplaceoneormorecomponents.Youcanthinkofcomponentsaswidgetssuchas"blockoftext","slideshow"and"bannerimage".

Fromatechnicalpointofview,CERNcomponentsareParagraphtypes.IfyouknowhowtoworkwiththeParagraphsystem,youknowhowtoworkwithCERNcomponents.

CERNLandingPage

45

Page 46: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithThemesAthemeprovidesaparticularlookandfeelforyourDrupalsiteandismeanttobecompletelyindependentofyoursite'soverallconfiguration.Assuchyoushouldbeabletoswitchfromonethemetoanotherwithoutlosinganyfunctionality.

CoreThemes

Drupalcorecontainsfourthemes:

BartikSevenStark

Bartik

DrupalenablesBartikasthedefaultuser-facingthemeuponinstallation.Itisacleanandsimplethemethatsupportsthecolormoduleandmakesexcellentuseofregions.InadditiontothedefaultregionsDrupalrecommends,theBartikthemehassevencustomregionsforlayingoutblocksinthefooterandsub-footer.

Seven

SevenisDrupal'sdefaultadministrativetheme.BornoutoftheDrupal7UserExperienceproject,SevendrovemanyofDrupal'suserinterfaceimprovementsbetweenDrupal6andDrupal7.Itcontainsveryfewregions;itsfocusisonperformingadministrativetasks.

Stark

StarkisaminimalDrupaltheme.ItsmainpurposeistoexposeDrupal'sdefaultHTMLmarkupandCSS.ItdoesnotprovideanytemplatefilesandbarelyprovidesanyCSSatall,otherthanbasiclayoutstylesthatplacethedefaultsidebarregions.

StarkisagoodthemefordeveloperstocodeagainstwhenwritingCSSfortheirmodules.Itcanalsoassistthemedeveloperswhentryingtotroubleshootissueswherethey'renotpositiveiftheproblemiswiththeirthemeoranothermodule.

EnablinganddisablingthemesDownloadedorcustombuiltthemesshouldbeplacedin:

<drupal-root>/themes/contrib/

and

<drupal-root>/themes/custom/

respectively.

Enablinganddisablingthemesisdoneinawaysimilartoenablinganddisablingmodules.Thelistofavailablethemescanbefoundathttp://example.com/admin/appearence,alsoavailableatAdministration>Appearance:

WorkingwithThemes

46

Page 47: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Anyoftheenabledthemescanbesetasthedefaulttheme(alsoreferredtoastheactivetheme).Clickingonatheme'ssettingslinkleadstotheconfigurationscreenofthatparticulartheme.

DefininganAdministrationtheme

Inadditiontothedefaulttheme,youcanalsoindicatewhichoftheavailablethemesshouldbeusedastheadministrationtheme.Oftenthethemeyouchooseforthepublicfacingpartofthesiteisnotparticularlysuitedforadministrationscreenswhichtendtorequireasimpleandcleaninterfacewithasmuch'screenrealestate'possible.

Globalthemesettingsvs.per-themesettings

Theconfigurationoptionsforaparticularthemeconsistoftwoparts:

Generalsettings,inheritedfromtheGlobalthemesettings,thatcanbeoverriddenonaper-themebasis.

Examplesincludesettingsforacolourschemeandwhichimagetouseforthesitelogo:

WorkingwithThemes

47

Page 48: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Settingsprovidedbythecreatorofthetheme,specifictothatparticularthemealone.

Let'ssayyouinstallathemethathasafocusonbeingusableonmobiledevices.Suchathemecouldprovidesettingsrelatedtohowthelayoutofthesiteshouldbehaveonasmallsmartphoneasopposedtoalargertabletdevice.

WorkingwithThemes

48

Page 49: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Themeinheritance

Basethemesandsub-themes

Drupalthemescan,andoftenare,basedonotherthemes.Anoftenusedscenarioisanorganisationcreatingaso-calledbasethemethatcontainsanumberofpossiblelayoutsforaseveralpagesandelements,anddefinesangenericlook-and-feelandbranding.EachoftheindividualdepartmentscouldhavetheirownDrupalsite(oransiteinstanceinamultisitesetup)andhavetheirowncustomisedtheme.

Oneapproachwouldbefor,say,theHRdepartmenttosimplycopythethemeandadaptittotheirneeds.However,ifchangesaremadetotheoriginalthemetheywon'tautomaticallyappearintothecopies.

Drupal'ssolutiontothisistheconceptofbasethemesandsub-themes.Basethemescanbethoughtofasparentthemes,sub-themesaschildthemes.

Themeinheritanceandtraversal

AswasthecaseinDrupal7,variousbitsandpiecesinDrupalarethemedwithdedicatedtemplatefiles:pages,views,nodes,users,blocks,etc...allhaveoneormorecorrespondingtemplatefiles.

Whenit'spreparingtotheme,say,anode,Drupalcheckswhetherthecurrentlyactivethemecontainsthefile node.html.twig.

Ifthecurrentlyactivethemecontainsthatfile,it'sused

Ifthecurrentlyactivethemedoesnotcontainthatfile,Drupalchecksifabasethemeisdefinedanifso,ifthatbasethemecontainsthatfile.Ifthatbasethemeinturnisasub-themeofyetanotherbasetheme(agrand-paranttheme),thatoneissearchedaswellforthe node.html.twigfile.

Thisprocessendswhenthehierarchicalchainofbasethemesandsub-themesends,orwhena node.html.twigfileisencountered.

Iftraversingthroughthechainofthemeshasnotyieldedanyresult,thecoretemplatefileprovidedbythenodemoduleat/core/modules/node/templates/node.html.twigisused.

Thistraversalofthemes,andfallingbacktoacoretemplatefileisunchangedfromDrupal7,onlynowthetemplatefilesarecalled *.html.twigratherthan *.tpl.php,andtheycontaintwigmarkupratherthanhtmlandphp.

ThemeInheritance

49

Page 50: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

CERNThemes:CERNBaseandCERNOverride

CERNBase

CERNBaseisthedefaulttheme,enabledwhenyoucreateanewCERND8site.Unlessyouhaveaspecificthemeneedthatcan'tbefulfilledbyusingCERNBase,thisisthethemeyouuse.

ThisthemeisbuiltfollowingCERN'sbrandinganddesignguidelines,anditscolourconfigurationoptionssuitmostsitebuilders.

ForsitebuilderswhowanttogofurtherandwanttomaketheirownDrupaltemplatefilesandprovidetheirowncssandjavascript,CERNhasbuilttheCERNOverridetheme.

CERNOverride

CERNoverrideisachildthemeofCERNBase:itisanexactcopyofCERNBase,readyforyoutomakeyourchangesbyoverridingorextendingthebasetheme.

TogetstartedwithCERNOverride:

1. RequestaccesstotheGitlab"CERNOverride"project2. DownloadacopyoftheCERNOverridesourcecode(orclonetherepoifyouarefamiliarwithgit)3. Uploadthethemetoyoursite's"/themes/"directory4. GotoAdmin>Appearance(/admin/appearance),findtheCERNOverridethemeamongthelistedthemes,andclick

"enableandsetasdefault".

Youcannowstartmakingchangestotemplatefilesanduploadthemodifiedfilestoyoursite's"/themes/cernoverride"directory.

Themostcommonchangesitebuildersmakeisusingcustomcssclassesintheirpagecontent,andcreatecustomCSScodeintheCERNOverridethemetomatchtheclassnames.

It'sinterestingtoknowthatCERNBaseisbuiltontopoftheBootstrapCSSFrameworkwhichalreadyprovidesready-to-useclassnamesandfacilitiesforeffects,responsivedesign,andaccessibility.Tolearnmoreaboutthis,visithttps://getbootstrap.com/docs/3.3/.

CERNBaseandCERNOverride

50

Page 51: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

ThemeConfigurationSettingsEverythemehasitsownsettingspageat admin/appearance/settings/THEMENAME,withsettingssuchas"Logoimagesettings"and"Shortcuticonsettings."

Yourthemecanprovidedefaultvaluesforthesesettingsinafilenamed THEMENAME.settings.yml.

Thefollowexamplesetsthe"usedefaultlogosuppliedbythetheme"and"userpicturesinposts"settings(foundat/admin/appearance/settingsto1(TRUE)whenthethemeisenabledforthefirsttime.

→/themes/custom/THEMENAME/config/install/THEMENAME.settings.yml:

default_logo:1toggle_node_user_picture:1

ThemeConfigurationSettings

51

Page 52: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

AssetLibraries

AssetLibraries

52

Page 53: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Assetlibraries:IntroductionD8introducestheconceptofassetlibraries,usedtospecifytheloadingofcustomcssandjsfiles.

Librariescanbedefinedbymodulesandbythemes.

Todefinealibraryinyourtheme,addafilenamed THEMENAME.libraries.ymlinyourthemedirectory,replacingTHEMENAMEwiththenameofyourtheme.

Yourfirststepistodefinealibraryinyour THEMENAME.libraries.ymlfile.Thesecondstepistospecifywhen/wherethislibraryshouldbeincluded;youusuallydothisin THEMENAME.info.yml(discussedbelow).

Basiclibrarysyntax

Example1:alibrarythatreferencesasinglecssfile

library-name:css:theme:css/mycomponent.css:{}js:js/mycomponent.js:{}

Example2:alibrarythatreferencesmultiplecssfiles

library-name:css:theme:css/mycomponent-colors.css:{}css/mycomponent-typography.css:{}css/mycomponent-structure.css:{}

Example3:alibrarythatreferencescssandjsfiles

library-name:css:theme:css/mycomponent.css:{}js:js/mycomponent.js:{}js/otherstuff.js:{}

Example4:alibraryforaslideshow

slideshow:css:theme:css/slideshow.css:{}js:js/slideshow.js:{}

Globalassets

AssetLibraries:Introduction

53

Page 54: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Byconvention,allscriptsandstylesthatshouldbeloadedoneverypageshouldbegroupedintolibrariesnamedglobal-stylingandglobal_scripts:

Example5:globalassets

global-styling:css:theme:css/style.css:{}css/colors.css:{}

global-scripts:js:js/trackers.js:{}js/advertising.js:{}js/animations.js:{}

Addingalibrarytothe.info.ymlfile

Thebasicpropertiesofeverytheme,includingtheassetlibrariestouse,aredefinedintheir THEMENAME.info.ymlfile.

Assumingyour THEMENAME.libraries.ymlfilecontainstheglobal-stylingexamplementionedinexample5,thefollowingshouldbeaddedto THEMENAME.info.yml:

libraries:-THEMENAME/global-styling-THEMENAME/global-scripts

Fullexample

Assumingyourthemeisnamedcorporate:

→/themes/custom/corporate/corporate.libraries.yml:

global-styling:css:theme:css/corpstyle.css:{}

global-scripts:js:js/somescript.js:{}js/otherscript.js:{}

→/themes/custom/corporate/corporate.info.yml:

libraries:-corporate/global-styling-corporate/global-scripts

Loadingassetsfromabasetheme

Ifyourthemeisbuiltontopofabasetheme(seesectionThemeInheritance),yourassetlibrarycanloadfilesfromyourbasethemeaswell.

AssetLibraries:Introduction

54

Page 55: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Thefollowingexampleloads css/components/accordion/accordion.cssfromthebasetheme,and css/style.cssfromthecurrenttheme:

global-styling:base:css/components/accordion/accordion.css:{}theme:css/style.css:{}

AssetLibraries:Introduction

55

Page 56: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

AssetLibraries:Dependencies

Dependencies

Incaseswhereyourcustomjavascriptdependsonotherjavascriptfilestobeloadedfirst,youcanspecifiesdependenciesinyourassetlibraries:

Thefollowingexampleensuresthatthefollowinglibrariesareloadedaswell:

thejquerylibrary,providedbyDrupalcorethebasic-sliderlibrary,providedbythesuper_slideshowmodule

slideshow:js:js/slideshow.js:{}dependencies:-core/jquery-super_slideshow/basic-slider

Youwoulddothisifyouwantedtobuilduponthejavascriptprovidedbysuper_slideshow/basic-slider,andwouldusejQueryfunctionstodoso.

Note:inDrupal8jQueryisnolongerloadedbydefaultonallpages.IfyourcustomjavascriptreliesonjQueryyoumustspecifythisdependencyinyourlibrarydefinition.

AssetLibraries:Dependencies

56

Page 57: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

AssetLibraries:PropertiesYoucanaddpropertiestoeachassetinyourassetlibraryinsidethecurlybracketsfollowingassetyourtheme'sTHEMENAME.libraries.ymlfile.

Propertyexamples

Conditionalloadingbasedonbrowsertype

Thefollowingexamplespecifies:

load css/style.cssonallpagesonlyload css/style-ie9.csswhenthebrowserisIE9(orlower).Don'tloadonbrowsersthatarenotIE.

global-styling:css:theme:css/style.css:{}css/style-ie9.css:{browsers:{IE:'lteIE9','!IE':false}}

Conditionalloadingbasedonmediatype

global-styling:css:theme:css/style.css:{}css/print.css:{media:print}

FurtherReading

AllD8libraryproperties

https://www.drupal.org/docs/8/theming/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme#libraries-options-details

CSSMediaproperties

https://developer.mozilla.org/en-US/docs/Web/CSS/@media

AssetLibraries:Properties

57

Page 58: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Twig

Twig

58

Page 59: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

TemplateFilenameConventionsDrupalloadstemplatesbasedoncertainnamingconventions.Youcanoverridetemplatesbyaddingthemtoyourthemeandgivingthemspecificnamesfollowingafilenameconvention.

Note:AfteraddinganewtemplateyoumustclearthecachetomakeDrupalawareofyouraddition.

Thefollowingisashortlistofthemostoftenusedtemplates.PleaserefertoAdditionalReadingformoreexamplesandin-depthinformation.

Note:Youmustreplaceunderscoreswithhyphensinyourplaceholders.

Example:ifthepatternis'page--[nodetype].html.twig'andyournodetype'smachinenameis'promo_events',yourtemplatefilenamemustbe page--promo-events.html.twig.

HTML<head>templatesBasetemplate: html.html.twig

Patternexamples:

html--[internalviewpath].html.twig

html--node--[nodeid].html.twig

html.html.twig

Pagetemplates

Basetemplate: page.html.twig

Pattern: page--[front|internal/path].html.twig

Patternexamples:

page--node--edit.html.twig

page--node--1.html.twig

page--[nodetype].html.twig

page--node.html.twig

page.html.twig

RegiontemplatesBasetemplate: region.html.twig

Pattern: region--[region].html.twig

Patternexamples:

region--highlighted.html.twig

region--footer.html.twig

Blocktemplates

Twig:TemplateFilenameConventions

59

Page 60: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Basetemplate: block.html.twig

Pattern: block--[module|delta].html.twig

Patternexamples:

block--[module]--[delta].html.twig

block--[module].html.twig

block.html.twig

Nodetemplates

Basetemplate: node.html.twig

Pattern: node--[content-type|nodeid]--[viewmode].html.twig

Patternexamples:

node--[nodeid]--[viewmode].html.twig

node--[nodeid].html.twig

node--[content-type]--[viewmode].html.twig

node--[content-type].html.twig

node--[viewmode].html.twig

node.html.twig

Fieldtemplates

Basetemplate: field.html.twig

Pattern: field--[type|name[--content-type]|content-type].html.twig

Patternexamples:

field--node--[field-name]--[content-type].html.twig

field--node--[field-name].html.twig

field--node--[content-type].html.twig

field--node--[field-name].html.twig

field--[field-type].html.twig

field.html.twig

TaxonomyTermtemplatesBasetemplate: taxonomy-term.html.twig

Pattern: taxonomy-term--[vocabulary-machine-name|tid].html.twig

Patternexamples:

taxonomy-term--[tid].html.twig

taxonomy-term--[vocabulary-machine-name].html.twig

taxonomy-term.html.twig

Viewstemplates

Twig:TemplateFilenameConventions

60

Page 61: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Basetemplate: views-view.html.twig

Patternexamples:

views-view--[viewid]--[view-display-id].html.twig

views-view--[viewid]--[view-display-type].html.twig

views-view--[view-display-type].html.twig

views-view--[viewid].html.twig

views-view.html.twig

ViewsFieldtemplatesBasetemplate: views-view-field.html.twig

Patternexamples:

views-view-field--[viewid]--[view-display-id]--[fieldid].html.twig

views-view-field--[viewid]--page--[fieldid].html.twig

views-view-field--block--[fieldid].html.twig

views-view-field--[fieldid].html.twig

views-view-field.html.twig

AdditionalReadingPathbasednamingconventions:https://www.drupal.org/docs/8/theming/twig/working-with-twig-templates#path-based-page-theme-hook-suggestions

Twig:TemplateFilenameConventions

61

Page 62: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

Twig:AddingAssetLibrariesYoucanattachanassetlibrarytoaTwigtemplatewiththe ̀ attach_library()functioninany*.html.twigfile.

ExampleAssumingyourthemeisnamedcorporateandhasa corporate.libraries.ymlfilewhichcontainsalibrarydefinitionnamedslideshow:

→/themes/mytheme/templates/mytemplate.html.twig:

{{attach_library('corporate/slideshow')}}

<div>Slideshowtemplatestuffgoeshere</div>...

Twig:AddingAssetLibraries

62

Page 63: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WorkingwithMultipleLanguages

AddingaNewLanguage

InstallthecoreLanguageModule.

GotoAdmin>Configuration>Regionalandlanguage(config/regional/language)toaddadditionallanguages.

EnablingContentTranslationInstallthecoreContentTranslationModule.

TheconfigurationsettingsofseveralEntityTypesnowhaveanadditionalLanguageSettingsfieldsetwhereyoucanenabletranslationandconfiguretranslationoptions.

ThetranslatableEntityTypesinclude:

nodes(contenttypes)customblockstaxonomytermsmenus

OncetranslationisenabledforagivenEntityType,allentitiesofthattypebecometranslatable.

AddtheLanguageSwitcherblock

AtthispointtheLanguageSwitcherblockhasbecomeavailableforyouuse.It'sagoodideatoaddittooneofyoursite'sthemeregionssoyoucanexperimentmoreeasilywithcontenttranslationandinterfacetranslation.

TranslatingContent

Youcanenableandconfiguretranslationsettingsoneachcontenttype'sconfigurationsettingspage.

TranslatablenodeshaveanadditionalTranslateLocalTasktabwhereyoucantrackthetranslationintoeachdefinedlanguage.

TranslatingTaxonomytermsYoucanenableandconfiguretranslationsettingsoneachvocabulary'sconfigurationsettingspage.

TranslatingBlocksYoucanenableandconfiguretranslationsettingsoneachcustomblocktype'sconfigurationsettingspage.

TranslatingMenusYoucanenableandconfiguretranslationsettingsoneachmenu'sconfigurationsettingspage.

WorkingwithMultipleLanguages

63

Page 64: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

EnablingInterfaceTranslation

InstallthecoreContentTranslationModule.

AtAdmin>Configuration>RegionalandLanguage>UserInterfaceTranslation(/admin/config/regional/translate)youcanprovidecustomstringtranslationsorimport .potranslationfilesdownloadedfromhttps://localize.drupal.org.

Onhttps://localize.drupal.org:

FindandclickthelanguageforwhichyouwanttodownloadthetranslationsClickontheOverviewtabClickontheDrupalcoreDownloadlinkforDrupal8todownloadthe .pofile

Importthe .pofileatAdmin>Configuration>RegionalandLanguage>UserInterfaceTranslation/>Import(/admin/config/regional/translate/import).

LanguageDetectionandSelection

Wheneveryouloadapage,Drupalneedstodecidewhichlanguageisusedtodisplaypageelements(primarilytextprovidedbymodules,suchasfieldlabelsandhelptext).

ItdoessobasedonthetheLanguageandDetectionsettingsatAdmin>Configuration>Regionalandlanguage>Detectionandselection(config/regional/language/detection).

WorkingwithMultipleLanguages

64

Page 65: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

WritingCustomMigrationsPresentation:https://gitlab.com/jpoesen/introduction-to-d8-migrations

Samplecode:https://gitlab.com/jpoesen/product_migration

WritingCustomMigrations

65

Page 66: Table of ContentsDrupal blocks are best described as content containers. They are the primary tool to organize your site's content. Blocks can hold static content, dynamic lists of

AdditionalResourceshttps://webtools.web.cern.ch/technologies/drupalhttps://test-d8-migration-trn1.web.cern.ch(trn1-trn10)https://www.drupal.org/docs/8https://api.drupal.org

AdditionalResources

66