SlideShare a Scribd company logo
1 of 27
Download to read offline
More code, less spaghetti
Using services to structure your code.
2
About Wizzlern
3
Wizzlern
‣ 100% Drupal

‣ Drupal training and consultancy

‣ Front-, backend-development 

‣ Dev-ops and editorial

‣ Advanced subjects

‣ Since 2009

‣ Active in the Drupal community
4
Wizzlern trainingen
‣ Backend track

‣ Basistraining (2d)

‣ Drupal architecture (2d)

‣ Drupal 8 development (3d)

‣ Drupal deployment (1d)

‣ Frontend track

‣ Basistraining (2d)

‣ Theme development (2d)

‣ Drupal deployment (1d)

‣ Systeembeheer

‣ Basistraining (1d)

‣ Functioneel beheer (2d)

‣ Content management

‣ Basistraining (1d)

‣ Redactie (1d)







5
Program
6
Program
‣ Why services

‣ About the exercises

‣ Services

‣ Refactoring code

‣ When to use services

‣ Alternatives
7
Why services
8
Why using a service?
9
Why services
‣ A solution to organise your code.

‣ Drupal 8 brings new possibilities, lets explore
them!

‣ For the beauty of the code.

‣ Service are unit-testable.

‣ Better code structure 

= easier maintenance & scaling = cheaper.
10
About the exercises
11
Exercises use case
‣ A news website

‣ Content

‣ News (nodes)

‣ News categories
(terms)

‣ Front page

‣ Popular- & Tech
news (block)

‣ News page

‣ News content

‣ Related news
(extra field)

‣ Latest news (block)
12
Exercise code
‣ https://github.com/wizzlern/drupal-service-structure

‣ starter-kit
‣ Drupal core + install profile + modules

‣ exercises
‣ One folder per exercise. Detail description + code.

‣ Additional code code_snippets.php 

‣ final-result
‣ Working code. For learning by reading or copy/paste.
13
Exercise
‣ Get familiar with the News custom code in:

‣ Plugin/Block/WeNewsRecentNews

‣ Plugin/Block/WeNewsRecentNewsByGroup

‣ Plugin/ExtraField/RelatedNews

‣ we_news.module: we_news_cron()
14
Services
15
Services
‣ Service = Software design pattern.

‣ Service = Provides a globally usable
functionality.

‣ Examples: Database, URL generator,
TranslationManager

‣ Advantages: Decoupled, Lazy loading.
16
Services
‣ Better structure, scaling and maintenance.

‣ Breaking code into smaller chunks makes it
more self-documenting.

‣ Let go of your procedural habits.

‣ Give it an interface!
17
Services
‣ Use a service for:

‣ Business logic from hooks

‣ Business logic from preprocess

‣ Business logic for custom content entities

‣ Helpers that require other service. 

‣ Repeated or similar business logic from blocks,
controllers, plugins, etc.

‣ For independent logic

‣ API communication, Larger logic structures, etc.
18
As a developer I want to structure the code of the Recent
news block.
Exercise
‣ Are there parts in WeNewsRecentNews that can be
moved to a service?

‣ Create a service that contains business logic related
to the News content type.

‣ Details in: 01-recent-news/exercise.md
19
Service layers
‣ Grouping services into functional layers
reduces the impact of change.

‣ A service should contain only a specific type
of logic. Example: either reusable or process-
specific logic.
20
More structures
‣ Constants defined in an interface

‣ Decorator

‣ Trait

‣ A class that groups static helper methods
21
As a developer I want to structure the code of the News by
category group block.
Exercise
‣ What parts in WeNewsRecentNewsByGroup that can
be moved to a service?

‣ Create a service that contains business logic related
to the News Category vocabulary.

‣ Details in: 02-news-by-group/exercise.md
22
As a developer I want to structure code of the Related
news extra field.
Exercise
‣ Are there parts in the code that can be moved to a
service? 

‣ Can we re-use an existing service or do we create a
new one?

‣ Details in: 03-related-news/exercise.md
23
As a developer I want to structure code of the news cron
task.
Exercise
‣ Are there parts in we_news_cron() that can be moved
to a service?

‣ Create a service that contains business logic related
to the news archive.

‣ Details in: 04-cron-service/exercise.md
24
Summary
25
Summary
‣ Structure for maintainability.

‣ Larger projects require more structure. 

‣ Group related business logic.

‣ Services and interfaces are one of the tools.
Ask yourself what pattern matches best.
26
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
http://wizzlern.nl
@wizzlern
27

More Related Content

Similar to Drupal jam 2017 services

Anypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupAnypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupMergeStack
 
Whats new BPC 10.1 NW
Whats new BPC 10.1 NWWhats new BPC 10.1 NW
Whats new BPC 10.1 NWfernadabrum
 
Igor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best PracticesIgor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best PracticesAtwix
 
Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Apigee | Google Cloud
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationDivante
 
Software Development Prioritization Techniques PowerPoint Presentation Slides
Software Development Prioritization Techniques PowerPoint Presentation SlidesSoftware Development Prioritization Techniques PowerPoint Presentation Slides
Software Development Prioritization Techniques PowerPoint Presentation SlidesSlideTeam
 
Introduction to Serverless. Oracle Fn Project.
Introduction to Serverless. Oracle Fn Project.Introduction to Serverless. Oracle Fn Project.
Introduction to Serverless. Oracle Fn Project.Rolando Carrasco
 
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...QueBIT Consulting
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQLGeorgi Kodinov
 
Overview on What’s New in SAP Cloud Platform Business Rules
Overview on What’s New in SAP Cloud Platform Business RulesOverview on What’s New in SAP Cloud Platform Business Rules
Overview on What’s New in SAP Cloud Platform Business RulesSAP Cloud Platform
 
Exposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API ManagementExposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API ManagementWSO2
 
April Partner Bootcamp 2022
April Partner Bootcamp 2022April Partner Bootcamp 2022
April Partner Bootcamp 2022Acquia
 
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...MongoDB
 
PhillyForce 2018 - Salesforce Platform Keynote
PhillyForce 2018  - Salesforce Platform KeynotePhillyForce 2018  - Salesforce Platform Keynote
PhillyForce 2018 - Salesforce Platform Keynoteandyinthecloud
 
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity  and Performance Comparison AnalysisSOA Knowledge Kit, Developer Productivity  and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity and Performance Comparison AnalysisClever Moe
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLIgor Miniailo
 
UNV Are Dead - How to migrate to UNX in a few simple steps
UNV Are Dead - How to migrate to UNX in a few simple stepsUNV Are Dead - How to migrate to UNX in a few simple steps
UNV Are Dead - How to migrate to UNX in a few simple stepsWiiisdom
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsGraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsNicola Molinari
 
Customer FX Technical Reference Sheet
Customer FX Technical Reference SheetCustomer FX Technical Reference Sheet
Customer FX Technical Reference SheetGoodCustomers
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Igor Miniailo
 

Similar to Drupal jam 2017 services (20)

Anypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupAnypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetup
 
Whats new BPC 10.1 NW
Whats new BPC 10.1 NWWhats new BPC 10.1 NW
Whats new BPC 10.1 NW
 
Igor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best PracticesIgor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best Practices
 
Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
 
Software Development Prioritization Techniques PowerPoint Presentation Slides
Software Development Prioritization Techniques PowerPoint Presentation SlidesSoftware Development Prioritization Techniques PowerPoint Presentation Slides
Software Development Prioritization Techniques PowerPoint Presentation Slides
 
Introduction to Serverless. Oracle Fn Project.
Introduction to Serverless. Oracle Fn Project.Introduction to Serverless. Oracle Fn Project.
Introduction to Serverless. Oracle Fn Project.
 
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...
Preparing for Your Cognos Analytics Upgrade April 2017 Webinar - QueBIT Consu...
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQL
 
Overview on What’s New in SAP Cloud Platform Business Rules
Overview on What’s New in SAP Cloud Platform Business RulesOverview on What’s New in SAP Cloud Platform Business Rules
Overview on What’s New in SAP Cloud Platform Business Rules
 
Exposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API ManagementExposing Business Functionalities with SOA, Integration and API Management
Exposing Business Functionalities with SOA, Integration and API Management
 
April Partner Bootcamp 2022
April Partner Bootcamp 2022April Partner Bootcamp 2022
April Partner Bootcamp 2022
 
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
 
PhillyForce 2018 - Salesforce Platform Keynote
PhillyForce 2018  - Salesforce Platform KeynotePhillyForce 2018  - Salesforce Platform Keynote
PhillyForce 2018 - Salesforce Platform Keynote
 
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity  and Performance Comparison AnalysisSOA Knowledge Kit, Developer Productivity  and Performance Comparison Analysis
SOA Knowledge Kit, Developer Productivity and Performance Comparison Analysis
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
 
UNV Are Dead - How to migrate to UNX in a few simple steps
UNV Are Dead - How to migrate to UNX in a few simple stepsUNV Are Dead - How to migrate to UNX in a few simple steps
UNV Are Dead - How to migrate to UNX in a few simple steps
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsGraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
 
Customer FX Technical Reference Sheet
Customer FX Technical Reference SheetCustomer FX Technical Reference Sheet
Customer FX Technical Reference Sheet
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
 

Recently uploaded

VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 

Recently uploaded (20)

VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 

Drupal jam 2017 services

  • 1.
  • 2. More code, less spaghetti Using services to structure your code. 2
  • 4. Wizzlern ‣ 100% Drupal ‣ Drupal training and consultancy ‣ Front-, backend-development ‣ Dev-ops and editorial ‣ Advanced subjects ‣ Since 2009 ‣ Active in the Drupal community 4
  • 5. Wizzlern trainingen ‣ Backend track ‣ Basistraining (2d) ‣ Drupal architecture (2d) ‣ Drupal 8 development (3d) ‣ Drupal deployment (1d)
 ‣ Frontend track ‣ Basistraining (2d) ‣ Theme development (2d) ‣ Drupal deployment (1d) ‣ Systeembeheer ‣ Basistraining (1d) ‣ Functioneel beheer (2d)
 ‣ Content management ‣ Basistraining (1d) ‣ Redactie (1d)
 
 
 
 5
  • 7. Program ‣ Why services ‣ About the exercises ‣ Services ‣ Refactoring code ‣ When to use services ‣ Alternatives 7
  • 9. Why using a service? 9
  • 10. Why services ‣ A solution to organise your code. ‣ Drupal 8 brings new possibilities, lets explore them! ‣ For the beauty of the code. ‣ Service are unit-testable. ‣ Better code structure 
 = easier maintenance & scaling = cheaper. 10
  • 12. Exercises use case ‣ A news website ‣ Content ‣ News (nodes) ‣ News categories (terms) ‣ Front page ‣ Popular- & Tech news (block) ‣ News page ‣ News content ‣ Related news (extra field) ‣ Latest news (block) 12
  • 13. Exercise code ‣ https://github.com/wizzlern/drupal-service-structure ‣ starter-kit ‣ Drupal core + install profile + modules ‣ exercises ‣ One folder per exercise. Detail description + code. ‣ Additional code code_snippets.php ‣ final-result ‣ Working code. For learning by reading or copy/paste. 13
  • 14. Exercise ‣ Get familiar with the News custom code in: ‣ Plugin/Block/WeNewsRecentNews ‣ Plugin/Block/WeNewsRecentNewsByGroup ‣ Plugin/ExtraField/RelatedNews ‣ we_news.module: we_news_cron() 14
  • 16. Services ‣ Service = Software design pattern. ‣ Service = Provides a globally usable functionality. ‣ Examples: Database, URL generator, TranslationManager ‣ Advantages: Decoupled, Lazy loading. 16
  • 17. Services ‣ Better structure, scaling and maintenance. ‣ Breaking code into smaller chunks makes it more self-documenting. ‣ Let go of your procedural habits. ‣ Give it an interface! 17
  • 18. Services ‣ Use a service for: ‣ Business logic from hooks ‣ Business logic from preprocess ‣ Business logic for custom content entities ‣ Helpers that require other service. ‣ Repeated or similar business logic from blocks, controllers, plugins, etc. ‣ For independent logic ‣ API communication, Larger logic structures, etc. 18
  • 19. As a developer I want to structure the code of the Recent news block. Exercise ‣ Are there parts in WeNewsRecentNews that can be moved to a service? ‣ Create a service that contains business logic related to the News content type. ‣ Details in: 01-recent-news/exercise.md 19
  • 20. Service layers ‣ Grouping services into functional layers reduces the impact of change. ‣ A service should contain only a specific type of logic. Example: either reusable or process- specific logic. 20
  • 21. More structures ‣ Constants defined in an interface ‣ Decorator ‣ Trait ‣ A class that groups static helper methods 21
  • 22. As a developer I want to structure the code of the News by category group block. Exercise ‣ What parts in WeNewsRecentNewsByGroup that can be moved to a service? ‣ Create a service that contains business logic related to the News Category vocabulary. ‣ Details in: 02-news-by-group/exercise.md 22
  • 23. As a developer I want to structure code of the Related news extra field. Exercise ‣ Are there parts in the code that can be moved to a service? ‣ Can we re-use an existing service or do we create a new one? ‣ Details in: 03-related-news/exercise.md 23
  • 24. As a developer I want to structure code of the news cron task. Exercise ‣ Are there parts in we_news_cron() that can be moved to a service? ‣ Create a service that contains business logic related to the news archive. ‣ Details in: 04-cron-service/exercise.md 24
  • 26. Summary ‣ Structure for maintainability. ‣ Larger projects require more structure. ‣ Group related business logic. ‣ Services and interfaces are one of the tools. Ask yourself what pattern matches best. 26
  • 27. This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. http://wizzlern.nl @wizzlern 27