Slide 1

Slide 1 text

Mohit Aghera Drupal Developer Bundle Classes for the Win πŸ“¦

Slide 2

Slide 2 text

I’m Mohit Aghera Who am I? Today I’ll cover: Drupal Developer at PreviousNext. Drupal.org: mohit_aghera Twitter: mohit-rocks ● Introduction to Bundle classes ● How we can use the bundle classes ● Various methods to use the bundle classes

Slide 3

Slide 3 text

Established in early 2009 to provide full service consulting, design and development for large scale Drupal websites. Who is PreviousNext? Successfully delivered many Drupal based projects for Government, Higher Education, Media and Communications clients. Very experienced team with long term staff members. Strong contribution and involvement in the Drupal community.

Slide 4

Slide 4 text

Who have we worked with?

Slide 5

Slide 5 text

What are the bundle classes? ● Essentially they are business objects ● Unique class for each entity bundle

Slide 6

Slide 6 text

How to define Bundle Classes? Implement hook_entity_bundle_info_alter()

Slide 7

Slide 7 text

How to define Bundle Classes? ● Use β€œbca” contrib module ● Leverage annotation based discovery

Slide 8

Slide 8 text

Improvements in Twig templates 🌱

Slide 9

Slide 9 text

Using methods in Twig

Slide 10

Slide 10 text

Implementation in Bundle classes

Slide 11

Slide 11 text

Using methods in Twig & TwigSandboxPolicy ● Default allowed method prefixes β—‹ β€œget” β—‹ β€œhas” β—‹ β€œIs” ● Override β€œtwig_sandbox_allowed_prefixes” in settings.php for more

Slide 12

Slide 12 text

Improvements in Theming πŸŽ¨πŸ–Œ

Slide 13

Slide 13 text

Usage in template_preprocess methods node.html.twig Template pre-process in node.module

Slide 14

Slide 14 text

Usage in template_preprocess method ⚑ node.html.twig Bundle Class

Slide 15

Slide 15 text

Prepare additional template variables Method in Bundle class Preprocess function in theme/module

Slide 16

Slide 16 text

Encourages reusable methods β™»

Slide 17

Slide 17 text

Build abstract classes ● Introduce common functionality to abstract base classes ● Even define generic methods in the abstract class like β—‹ getBody β—‹ getTags

Slide 18

Slide 18 text

Generic methods ● A few more example of generic methods like: ● Fetch the file from the media entity ● Prepare the array for featured Header ● Get the generated image url from the media using image styles ● Get taxonomy tags

Slide 19

Slide 19 text

Traits ● Create generic traits that allows reusability ● Include traits in bundle classes whenever required ● https://github.com/dpi/drupal-entity-traits

Slide 20

Slide 20 text

Test improvements - Method in Bundle class

Slide 21

Slide 21 text

Test improvements - Method test case

Slide 22

Slide 22 text

Sample Repository https://github.com/mohit-rocks/bundle-classes-demo

Slide 23

Slide 23 text

Questions?