56
HOW TO CREATE RICH WEB STORIES WITH PARAGRAPHS AND DRUPAL 8 Created by / Tassos Koutlas @akoutlas

Create rich web stories with Drupal 8 and paragraphs

Embed Size (px)

Citation preview

Page 1: Create rich web stories with Drupal 8 and paragraphs

HOW TO CREATE RICH WEB STORIESWITH PARAGRAPHS AND DRUPAL 8

Created by / Tassos Koutlas @akoutlas

Page 2: Create rich web stories with Drupal 8 and paragraphs

CONTENTSWho am I

Code examples in github

Introduction to paragraphs

Advanced use cases

Contributions

Discussion

Page 3: Create rich web stories with Drupal 8 and paragraphs

WHO AM I

Page 4: Create rich web stories with Drupal 8 and paragraphs

TASSOS KOUTLAS

Senior Technical Consultant @ C&Wweb projects / machine learning / image processing algorithms / administering IT

systems / scrum master

Page 5: Create rich web stories with Drupal 8 and paragraphs

CODE EXAMPLES

Page 6: Create rich web stories with Drupal 8 and paragraphs

On githubhttps://github.com/tassoskoutlas/drupalcamplondon2016

Page 7: Create rich web stories with Drupal 8 and paragraphs

Setup running:git clone https://github.com/tassoskoutlas/drupalcamplondon2016.gitcd drupalcamplondon2016 && ./init.sh

Page 8: Create rich web stories with Drupal 8 and paragraphs

Different functionality per branchgit branch -vva 01-Create_a_custom_paragraph_type_and_templates 02-Create_an_entity_reference_component 03-Create_a_view_display_component

Checkout branches to get more features:git checkout BRANCH && ./init.sh

Page 9: Create rich web stories with Drupal 8 and paragraphs

For multiple drush versions:./init.sh drush8

Page 10: Create rich web stories with Drupal 8 and paragraphs

INTRODUCTION TOPARAGRAPHS

Page 11: Create rich web stories with Drupal 8 and paragraphs

Paragraphs provide a way to add components ofcontent without adding individual fields.

Like field collections only better.

Page 12: Create rich web stories with Drupal 8 and paragraphs

Control structure and useful editing experience.

Page 13: Create rich web stories with Drupal 8 and paragraphs

Allow creativity in assebling a page.

Page 14: Create rich web stories with Drupal 8 and paragraphs

Work with components that tie in well in atomicdesing and agile delivery.

Page 15: Create rich web stories with Drupal 8 and paragraphs

LET'S LOOK AT AN EXAMPLE

AN IMAGE COMPONENT

image field which is a standard image fieldcaption field which is a text field

Page 16: Create rich web stories with Drupal 8 and paragraphs
Page 17: Create rich web stories with Drupal 8 and paragraphs

COMPONENTS (PARAGRAPH TYPES)A new menu item within Structure

Page 18: Create rich web stories with Drupal 8 and paragraphs
Page 19: Create rich web stories with Drupal 8 and paragraphs

PUTTING IT TOGETHER AT THE NODE

Page 20: Create rich web stories with Drupal 8 and paragraphs
Page 21: Create rich web stories with Drupal 8 and paragraphs

LET'S EXTEND THIS FURTHER

The blockquote element represents content that isquoted from another source, optionally with a citation

which must be within a footer or cite element, andoptionally with in-line changes such as annotations

and abbreviations. - 4.4.4, The blockquote elementHTML5.1

Page 22: Create rich web stories with Drupal 8 and paragraphs

BLOCKQUOTE STRUCTUREWe would need to replicate the following structure<blockquote> <p> The text of the quote.</p> - <cite>Tassos Koutlas</cite> </blockquote>

Page 23: Create rich web stories with Drupal 8 and paragraphs

Let's add another component.

Page 24: Create rich web stories with Drupal 8 and paragraphs

TWO TEXT FIELDS

Page 25: Create rich web stories with Drupal 8 and paragraphs

NODE EDIT FORM

Page 26: Create rich web stories with Drupal 8 and paragraphs

NODE PAGE

Page 27: Create rich web stories with Drupal 8 and paragraphs

But we want this:<blockquote> <p> The text of the quote.</p> - <cite>Tassos Koutlas</cite> </blockquote>

Page 28: Create rich web stories with Drupal 8 and paragraphs

POWER OF TWIG AND D8Everything is a templateEverything is overwritableEvery entity gets a templateEvery bundle gets a templateEvery view mode gets a template

Page 29: Create rich web stories with Drupal 8 and paragraphs

TWO TEMPLATES IN THE THEMEfield.html.twig

{% for item in items %} {{ item.content }} {% endfor %}

paragraph--blockquote.html.twig

<blockquote> {{ content.field_quote_text }} <cite>- {{ content.field_quote_citation }}</cite> </blockquote>

Rebuild your theme cachedrush8 cr

Page 30: Create rich web stories with Drupal 8 and paragraphs
Page 31: Create rich web stories with Drupal 8 and paragraphs

WHERE DOES THAT LEAD?A modular way to create content

<article> <h1></h1> <div class="paragraph paragraph--hero"><img></div> <div class="paragraph paragraph--subtitle"><h2></h2></div> <div class="paragraph paragraph--text"><p></p></div> <div class="paragraph paragraph--subtitle"><h2></h2></div> <div class="paragraph paragraph--text"><p></p></div> <div class="paragraph paragraph--image-full"><img></div> <div class="paragraph paragraph--text"><p></p></div> <div class="paragraph paragraph--blockquote"><q></q></div> <div class="paragraph paragraph--text"><p></p></div> <div class="paragraph paragraph--text-image-side"><img></div> <div class="paragraph paragraph--text"><p></p></div> </article>

Page 32: Create rich web stories with Drupal 8 and paragraphs

ADVANCES IN OTHER AREASCompartmentalise your codeAtomic design principlesReusablity of componentsBetter control on accessibility

Page 33: Create rich web stories with Drupal 8 and paragraphs

ADVANCED USE CASES

Page 34: Create rich web stories with Drupal 8 and paragraphs

LINKING CONTENT - MANUALAt a node level there are entity references.

At a site level there are views

Views are entities in D8

Page 35: Create rich web stories with Drupal 8 and paragraphs

EXAMPLE: REALTED CONTENT WIDGET

Page 36: Create rich web stories with Drupal 8 and paragraphs

DEFAULT RENDERBy default an entity reference renders as a link

Page 37: Create rich web stories with Drupal 8 and paragraphs

BUT ...

Page 38: Create rich web stories with Drupal 8 and paragraphs

VIEW MODES ON D8First class citizens

Page 39: Create rich web stories with Drupal 8 and paragraphs

PARAGRAPHS + ENTITY REFERENCES +VIEW MODES = BFE

Manually link content and create widgetsReplicate any markupCreate re-usable facets of data

Page 40: Create rich web stories with Drupal 8 and paragraphs

LINKING CONTENT - AUTOMATICViews are entities in D8

Not content entities so display format links orlabels the view

moduleviews field formatter

Page 41: Create rich web stories with Drupal 8 and paragraphs

Field

Field settings

Page 42: Create rich web stories with Drupal 8 and paragraphs

Manage field display

Page 43: Create rich web stories with Drupal 8 and paragraphs

On the node

Page 44: Create rich web stories with Drupal 8 and paragraphs

ONE BIG ADVANTAGE

Views like view modes already

Page 45: Create rich web stories with Drupal 8 and paragraphs

WHAT IS MISSINGViews field formatter orginate from D7 where views

weren't entities.

List all available views displays and pick one.

What if you could pick a display from thereferenced view?

Page 46: Create rich web stories with Drupal 8 and paragraphs

EXAMPLEShttp://www.baseballhall.org/discover/card-

corner/groovin-don-baylor

Page 47: Create rich web stories with Drupal 8 and paragraphs

HERO IMAGE

Page 48: Create rich web stories with Drupal 8 and paragraphs
Page 49: Create rich web stories with Drupal 8 and paragraphs

TEXT WITH IMAGE ON THE SIDE

Page 50: Create rich web stories with Drupal 8 and paragraphs
Page 51: Create rich web stories with Drupal 8 and paragraphs

SUBTITLE

Page 52: Create rich web stories with Drupal 8 and paragraphs
Page 53: Create rich web stories with Drupal 8 and paragraphs

REFERENCED CONTENT

Page 54: Create rich web stories with Drupal 8 and paragraphs
Page 55: Create rich web stories with Drupal 8 and paragraphs

HOW TO CONTRIBUTE1. issue queue2. issue queue3. Spread the word!

ParagraphsViews field formatter

Page 56: Create rich web stories with Drupal 8 and paragraphs

THANK YOU!