47
Building rednoseday.com on Drupal 8 Peter Vanhee Tech Lead at Comic Relief @pvhee DrupalCamp London 2017

Building rednoseday.com on Drupal 8

Embed Size (px)

Citation preview

Page 1: Building rednoseday.com on Drupal 8

Building rednoseday.com on Drupal 8

Peter VanheeTech Lead at Comic Relief@pvhee

DrupalCamp London 2017

Page 2: Building rednoseday.com on Drupal 8

• Comic Relief strives to create a just world free from poverty

• We raise millions of pounds through two big fundraising campaigns – Red Nose Day and Sport Relief.

• We spend that money in the best possible way to tackle the root causes of poverty and social injustice.

• We use the power of our brand to raise awareness of the issues that we care most about.

Page 3: Building rednoseday.com on Drupal 8

Who am I?

• Tech Lead at Comic Relief https://technology.comicrelief.com

• Founder of Marzee Labs, a tech shop from Barcelona @marzeelabs

• Long-time Drupal contributor @pvhee

Page 4: Building rednoseday.com on Drupal 8

Drupal at Comic Relief

• 2014: comicrelief.com

• 2015: 2015.rednoseday.com

• 2016: sportrelief.com

Page 5: Building rednoseday.com on Drupal 8
Page 6: Building rednoseday.com on Drupal 8

Drupal at Comic Relief

• 2014: comicrelief.com

• 2015: 2015.rednoseday.com

• 2016: sportrelief.com

• 2017: rednoseday.com

Page 7: Building rednoseday.com on Drupal 8

A fresh start?

• Build a campaign website

• Build a product that can build campaign websites

• Build a product that allows editors to reorganise row components to build a website

• Continuously iterate over our codebase

Page 8: Building rednoseday.com on Drupal 8

A product should…• support iterative development

• have a clear versioning scheme

• have tests to guarantee quality

• provide a sensible default start for any campaign

• allow for customisation

Page 9: Building rednoseday.com on Drupal 8

Technology Choice?Drupal 8, because of

• embracing industry PHP standards

• built on top of Symfony, use of Twig and Composer

• editorial features “out of the box”

• accessibility features

• built-in REST capabilities

• a development challenge

Page 10: Building rednoseday.com on Drupal 8

You can’t be that kid standing at the top of the waterslide,

overthinking it. You have to go

down the chute.Tina Fey

Page 11: Building rednoseday.com on Drupal 8

Ingredients to build our product

• Focus on Editor Experience

• Automate and streamline

• Decoupled services

Page 12: Building rednoseday.com on Drupal 8

Editor Experience

Page 13: Building rednoseday.com on Drupal 8

Landing pages as the norm

• First iteration: panels with panelizer

• Second iteration: panels with panelizer and embedded paragraphs

• Third iteration: paragraphs with block reference

Page 14: Building rednoseday.com on Drupal 8

Header with Menu

Footer

Paragraph 1

Paragraph 2

Paragraph 3

Paragraph n

… library of blocks

custom blocks (like email signup)

Editorial blocks

Paragraph types

“content wall”(rows + teasers are blocks)

Cards

blocks are reusable

paragraphs are not reusable

QuotesEmbed

Node Block reference

Page 15: Building rednoseday.com on Drupal 8

BLOCKS

PARAGRAPHS

reusable

not reusable

libraryquick editcontextual links

only editable via nodeno quick-edit

(see node …)

content fields

layout fields

refe

renc

e

Page 16: Building rednoseday.com on Drupal 8

Living Style Guide

Page 17: Building rednoseday.com on Drupal 8
Page 18: Building rednoseday.com on Drupal 8
Page 19: Building rednoseday.com on Drupal 8

Living Style Guide

• Using KSS, “a documentation syntax for CSS”

• Our new “incubation area”

• Code and style guide are one — no need to update one or the other independently thus guaranteeing it stays fresh!

Page 20: Building rednoseday.com on Drupal 8

Style-guide driven development

Component idea

Style Guide(or Pattern Lab)

HTML, SCSS, JS

ReviewMulti-device QA

Sign-off

Drupal development

Content modelView modes

Component moduleTwig / PHP

Page 21: Building rednoseday.com on Drupal 8

Improved editor experience

Red Nose Day 2015(Drupal 7)

Red Nose Day 2017(Drupal 8)

Page 22: Building rednoseday.com on Drupal 8
Page 23: Building rednoseday.com on Drupal 8
Page 24: Building rednoseday.com on Drupal 8
Page 25: Building rednoseday.com on Drupal 8
Page 26: Building rednoseday.com on Drupal 8
Page 27: Building rednoseday.com on Drupal 8

Automate & streamline everything

Page 28: Building rednoseday.com on Drupal 8

A build in one step

• Package up our website product using an installation profile and using CMI, via config_devel

• Default content in JSON

• Use a build tool — we use Phing and run phing build often

Page 29: Building rednoseday.com on Drupal 8

Config modules

Page 30: Building rednoseday.com on Drupal 8

Collaborative coding

Page 31: Building rednoseday.com on Drupal 8

No automation without tests

• Code quality checks using CodeSniffer, phpmd, phpcpd

• Configuration checks using config_devel

• Distribution installation tests using phing build

• Behavior tests on distribution using Behat

• Drupal log checks (no errors, warnings generated by Behat)

• Visual regression tests using BBC Wraith

Page 32: Building rednoseday.com on Drupal 8

BehatBehat tests

Page 33: Building rednoseday.com on Drupal 8

Continuous Integration

Page 34: Building rednoseday.com on Drupal 8

Preview branches

Page 35: Building rednoseday.com on Drupal 8

Decoupled services

Page 36: Building rednoseday.com on Drupal 8

Slide from Chet Haase

Page 37: Building rednoseday.com on Drupal 8

Minimise custom code

• we have around 2000 custom lines of PHP code (options callbacks, custom Display Suite fields, Solr tweaks)

• “Non-glue code” is contributed back as standalone Drupal modules: rabbitmq, social_links

Page 38: Building rednoseday.com on Drupal 8

The Embed Pattern

Page 39: Building rednoseday.com on Drupal 8

The Queue Pattern

Producer = Drupal Queue Consumer = 3rd party

an example: email list subscription - Producer: Email Signup Form- Queue: holds email address, template ID, etc.- Consumer: PHP / nodejs app talking to MailChimp

Page 40: Building rednoseday.com on Drupal 8

Drupal Producer/** * Our signup form. */ class ExampleForm extends FormBase {

public function buildForm(array $form, Form…face $form_state) { $form['email'] = [ '#type' => 'email', '#title' => $this->t(‘Your email address.'), ]; $form['show'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), ]; return $form; }

public function submitForm(array &$form, Form…face $form_state) { // Get the data you want to send to the queue. $data = $form_state->getValue('email');

// Get the queue config and send it to the data to the queue. $queue_name = 'queue1'; $queue_factory = \Drupal::service('queue'); $queue = $queue_factory->get($queue_name); $queue->createItem($data);

// Send some feedback. drupal_set_message( $this->t(‘Added data to queue @queue: @email', [ '@queue' => $queue_name, '@email' => $form_state->getValue('email'), ]) ); }

}

// Our rabbitmq.config.yml configuration exchanges: my_exchange: type: 'direct' passive: false durable: true auto_delete: false internal: false nowait: false

queues: my_queue: passive: false durable: false exclusive: false auto_delete: true nowait: false routing_keys: - 'my_exchange.my_queue'

// Add to settings.php $settings['queue_service_queue1'] = 'queue.rabbitmq';

rabbitmq module at drupal.org/project/rabbitmq

using Drupal 8 Queue API

Page 41: Building rednoseday.com on Drupal 8

RabbitMQ Queue

Page 42: Building rednoseday.com on Drupal 8

3-rd party Consumerclass QueueConsumer implements ConsumerInterface { /* @var \stdClass */ private $processingService;

/** * Parse message as JSON and send to processor * * @param AMQPMessage $msg * @return bool */ public function execute(AMQPMessage $msg) { if ($decodedMessage = json_decode($msg->body)) { try { return $this->processingService->process($decodedMessage); } catch (\Exception $e) { $this->logger->alert(‘Queue process error:' . $e->getMessage()); } } else { $this->logger->info(sprintf('Unable to parse as JSON: "%s"', $msg->body)); } return false; } }

Page 43: Building rednoseday.com on Drupal 8

Towards micro-services

• oEmbed / iFrame for integrating 3rd-party apps in the CMS

• Message Queues for decoupling logic

Page 44: Building rednoseday.com on Drupal 8

What about rednoseday.com?

Page 45: Building rednoseday.com on Drupal 8

From product to websitecampaign distribution- v1.1 - … - v1.36- … - v2.x

rednoseday.com

comicrelief.com

rednoseday.org (USA)

sportrelief.com

Page 46: Building rednoseday.com on Drupal 8

From product to websitecampaign distribution- v1.1 - … - v1.36- … - v2.x

rednoseday.com- campaign v1.36 as dependency - env vars (queue info, db info, …)- RND17 theme- YML site configuration sites/default/config

- composer / make- hook_update - drush config-devel-import

comicrelief.com

rednoseday.org (USA)

sportrelief.com

you?

Page 47: Building rednoseday.com on Drupal 8

Questions?

@pvheewww.rednoseday.com Friday 24 March