Drupal Feeds

KnackForge: How to update Drupal 8 core?

Planet Drupal - Sat, 2018-03-24 05:01
How to update Drupal 8 core?

Let's see how to update your Drupal site between 8.x.x minor and patch versions. For example, from 8.1.2 to 8.1.3, or from 8.3.5 to 8.4.0. I hope this will help you.

  • If you are upgrading to Drupal version x.y.z

           x -> is known as the major version number

           y -> is known as the minor version number

           z -> is known as the patch version number.

Sat, 03/24/2018 - 10:31

KnackForge: How to update Drupal 8 core?

Feeds from Drupal.org - Sat, 2018-03-24 05:01
How to update Drupal 8 core?

Let's see how to update your Drupal site between 8.x.x minor and patch versions. For example, from 8.1.2 to 8.1.3, or from 8.3.5 to 8.4.0. I hope this will help you.

  • If you are upgrading to Drupal version x.y.z

           x -> is known as the major version number

           y -> is known as the minor version number

           z -> is known as the patch version number.

Sat, 03/24/2018 - 10:31
Categories: Straight From Drupal

Migrate SQL Sub Row

Latest Drupal Modules - Tue, 2017-03-28 19:21

Provides two migrate source plugins & one process plugin for doing migrations from an SQL database.

The source plugins are both base plugins (like the SqlBase plugin and in fact extending from it), and require similar local implementation to the SqlBase plugin to use in your migration.

Categories: Straight From Drupal

React & Share

Latest Drupal Modules - Tue, 2017-03-28 17:25

Enables sitebuilder to add React & Share as a block.

Categories: Straight From Drupal

James Oakley: hook_uninstall not running? Drupal schoolboy errors #1

Planet Drupal - Tue, 2017-03-28 16:04
(Uninstall) Hook\

I'll put this here, in case it helps anyone else.

I'm owning up to Drupal Schoolboy Error #1.

I was writing a very simple module. It did so little, that I wanted to keep things as simple as possible — just a .info file, and a .module file.

Blog Category: Drupal Planet

James Oakley: hook_uninstall not running? Drupal schoolboy errors #1

Feeds from Drupal.org - Tue, 2017-03-28 16:04
(Uninstall) Hook\

I'll put this here, in case it helps anyone else.

I'm owning up to Drupal Schoolboy Error #1.

I was writing a very simple module. It did so little, that I wanted to keep things as simple as possible — just a .info file, and a .module file.

Blog Category: Drupal Planet
Categories: Straight From Drupal

myDropWizard.com: Most common Drupal site building pitfalls and how to avoid them! (Part 3 of 3)

Planet Drupal - Tue, 2017-03-28 14:58

This is the third in a series of articles, in which I'd like to share the most common pitfalls we've seen, so that you can avoid making the same mistakes when building your sites!

myDropWizard offers support and maintenance for Drupal sites that we didn't build initially. We've learned the hard way which site building mistakes have the greatest potential for creating issues later.

And we've seen a lot of sites! Besides our clients, we also do a FREE in-depth site audit as the first step when talking to a potential client, so we've seen loads of additional sites that didn't become customers.

In the first article, we looked at security updates, badly installed module code and challenges ith "patching" modules and themes, as well as specific strategies for addressing each of those problems. In the second article, we looked at how to do the most common Drupal customizations without patching.

In this article, we're going to look at some common misconfigurations that make a site less secure, and how to avoid them!

NOTE: even though they might take a slightly different form depending on the version, most of these same pitfalls apply equally to Drupal 6, 7 and 8! It turns out that bad practices are quite compatible with multiple Drupal versions ;-)

myDropWizard.com: Most common Drupal site building pitfalls and how to avoid them! (Part 3 of 3)

Feeds from Drupal.org - Tue, 2017-03-28 14:58

This is the third in a series of articles, in which I'd like to share the most common pitfalls we've seen, so that you can avoid making the same mistakes when building your sites!

myDropWizard offers support and maintenance for Drupal sites that we didn't build initially. We've learned the hard way which site building mistakes have the greatest potential for creating issues later.

And we've seen a lot of sites! Besides our clients, we also do a FREE in-depth site audit as the first step when talking to a potential client, so we've seen loads of additional sites that didn't become customers.

In the first article, we looked at security updates, badly installed module code and challenges ith "patching" modules and themes, as well as specific strategies for addressing each of those problems. In the second article, we looked at how to do the most common Drupal customizations without patching.

In this article, we're going to look at some common misconfigurations that make a site less secure, and how to avoid them!

NOTE: even though they might take a slightly different form depending on the version, most of these same pitfalls apply equally to Drupal 6, 7 and 8! It turns out that bad practices are quite compatible with multiple Drupal versions ;-)

Categories: Straight From Drupal

Masonry View Style

Latest Drupal Modules - Tue, 2017-03-28 14:50

This is a simplified Masonry Views output style without contrib module dependencies.

You're responsible for styling the grid -- something like this in your theme should get you started:

.mvs-grid { /* wrapper styling */ } .mvs-grid-item { /* grid item styling */ width: 33%; }

The underlying frontend libraries, which are included for convenience:

Categories: Straight From Drupal

MidCamp - Midwest Drupal Camp: Free Community Drupal Training at MidCamp 2017

Planet Drupal - Tue, 2017-03-28 13:38

It started as a question.  Why do Drupal camps only have trainings on a separate day?  The legitimate answer was that trainings and sessions should not compete for audiences for a normal Drupal camp audience.  But what if the trainings were not for that normal Drupal camp audience?

When all of the hard work was done by the MidCamp venue team to secure the DePaul University Student Center for MidCamp 2017, we immediately started exploring the idea of having half day Drupal training sessions for those that would nornally not attend a Drupal camp.  We reserved two extra rooms for this idea.

While I looked for interested parties who would be interested in attending the trainings, Joseph Purcell of Digital Bridge Solutions worked to organize an Introduction to Making Websites with Drupal itinerary and found great trainers to lead the event: Michael Chase, ‎Instructor at DePaul University College of Computing and Digital Media, and Aaron Meeuwsen, Web Developer at HS2 Solutions, along with several other volunteers, Scott Weston and Matt Ramir from HS2, and Doug Dobrzynski from PMMI Media Group.  Without them, we couldn't have made this happen. I would also like to thank my employer, Xeno Media for contributing some of my time to help organize these trainings.

We've reached out to, and are happy to be working with such great local Chicago technology groups.  Girl Develop It, which provides programs for adult women interested in learning web and software development in a judgment-free environment, the IT Knowledge and Abilities Network (ITKAN), which provides professional networking and growth organization with a focus on professionals and aspiring professionals with disabilities, and Women Who Code, a global non-profit dedicated to inspiring women to excel in technology careers all answered our call.

But we still have room for more.  Do you know of someone who would benefit from free Intro to Drupal Training?  We want you to invite them!

The trainings will cover basic CMS tasks like editing and publishing content, creating navigation menus, and placement of content on the site, and will approach into more complex tasks such as module installation and site configurations. Additionally, we’ll show the various ways the Drupal community can help through the issue queue, meetups, job boards, and mentorship.

The sessions are:

  • Friday March 31st - 9:00 am - 12:00 pm
  • Friday March 31st - 1:00 pm - 4:00 pm
  • Saturday April 1st - 9:00 am - 12:00 pm
  • Saturday April 1st - 1:00 pm - 4:00 pm

Get your free ticket today!

Don't be shy, please share and and invite anyone you think would benefit from these trainings.  Ticket enrollment is open, and we would love to have every seat filled!

MidCamp - Midwest Drupal Camp: Free Community Drupal Training at MidCamp 2017

Feeds from Drupal.org - Tue, 2017-03-28 13:38

It started as a question.  Why do Drupal camps only have trainings on a separate day?  The legitimate answer was that trainings and sessions should not compete for audiences for a normal Drupal camp audience.  But what if the trainings were not for that normal Drupal camp audience?

When all of the hard work was done by the MidCamp venue team to secure the DePaul University Student Center for MidCamp 2017, we immediately started exploring the idea of having half day Drupal training sessions for those that would nornally not attend a Drupal camp.  We reserved two extra rooms for this idea.

While I looked for interested parties who would be interested in attending the trainings, Joseph Purcell of Digital Bridge Solutions worked to organize an Introduction to Making Websites with Drupal itinerary and found great trainers to lead the event: Michael Chase, ‎Instructor at DePaul University College of Computing and Digital Media, and Aaron Meeuwsen, Web Developer at HS2 Solutions, along with several other volunteers, Scott Weston and Matt Ramir from HS2, and Doug Dobrzynski from PMMI Media Group.  Without them, we couldn't have made this happen. I would also like to thank my employer, Xeno Media for contributing some of my time to help organize these trainings.

We've reached out to, and are happy to be working with such great local Chicago technology groups.  Girl Develop It, which provides programs for adult women interested in learning web and software development in a judgment-free environment, the IT Knowledge and Abilities Network (ITKAN), which provides professional networking and growth organization with a focus on professionals and aspiring professionals with disabilities, and Women Who Code, a global non-profit dedicated to inspiring women to excel in technology careers all answered our call.

But we still have room for more.  Do you know of someone who would benefit from free Intro to Drupal Training?  We want you to invite them!

The trainings will cover basic CMS tasks like editing and publishing content, creating navigation menus, and placement of content on the site, and will approach into more complex tasks such as module installation and site configurations. Additionally, we’ll show the various ways the Drupal community can help through the issue queue, meetups, job boards, and mentorship.

The sessions are:

  • Friday March 31st - 9:00 am - 12:00 pm
  • Friday March 31st - 1:00 pm - 4:00 pm
  • Saturday April 1st - 9:00 am - 12:00 pm
  • Saturday April 1st - 1:00 pm - 4:00 pm

Get your free ticket today!

Don't be shy, please share and and invite anyone you think would benefit from these trainings.  Ticket enrollment is open, and we would love to have every seat filled!

Categories: Straight From Drupal

Chromatic: Configuring Redis Caching with Drupal 8

Planet Drupal - Tue, 2017-03-28 13:20

How to install and configure Redis caching for Drupal 8.

Chromatic: Configuring Redis Caching with Drupal 8

Feeds from Drupal.org - Tue, 2017-03-28 13:20

How to install and configure Redis caching for Drupal 8.

Categories: Straight From Drupal

Views right click

Latest Drupal Modules - Tue, 2017-03-28 11:32

Use this module to add a right click menu to view rows. The right click context menu that appears is derived from fields in the view that have a newly added "Right click" option checked.

Categories: Straight From Drupal

Stickyslot

Latest Drupal Modules - Tue, 2017-03-28 10:50

This module provides a new context and a DFP ad slot which will stick to your page as you scroll.

Categories: Straight From Drupal

Darren Mothersele: How to do Everything with PHP Middleware (DrupalCamp London)

Planet Drupal - Tue, 2017-03-28 09:30

At the DrupalCamp in London earlier this month I gave a talk about PHP Middleware. You can see a recording of the talk on YouTube. Here’s a summary, in case you don’t want to watch the whole talk, or the distorted audio upsets you, or if you want the links and references:

Simple vs Easy

I started with a reference to the important talk by Rich Hickey, Simple Made Easy. This is high up on my list of videos every software developer needs to watch. I began here because I think it’s important to identify the difference between simple and easy, to identify where complexity sneaks into our systems. I have found PHP Middleware to be an important tool in the fight against complexity.

“programming, when stripped of all its circumstantial irrelevancies, boils down to no more and no less than very effective thinking so as to avoid unmastered complexity, to very vigorous separation of your many different concerns.

Edsgar W. Dijkstra (1930 - 2002)

De-complecting PHP

I talked a bit about different ways to simplify development with PHP. Including: Domain-driven design, Hexagonal architecture (Ports and Adapters), Framework-independent code, Thin APIs, etc… In particular, I wanted to emphasise the importance of framework-independent code and the benefit of using common interfaces such as the ones developed as PSRs by PHP-FIG.

There was some discussion after about introducing unecessary abstractions, but I think this misses the point. Of course there is a trade off, but the key is to focus on the simplicity, on untwisting things (c.f. Rich Hickey).

De-coupled

Inspired by the Zend Expressive installation procedure, I imagined what Drupal 10 might look like, with fully-decoupled components.

Drupal Install

Interfaces

The widespread adoption of PSR7 by the PHP community has lead to the popularity of PHP Middleware-based systems.

Why PSR7 when Symfony HTTP components were so popular? Well, that is an implementation - and rather than standardise on implementation, we should standardise against interfaces.

This allows more interoperability. I showed this pseudocode:

// Take the incoming request from Diactoros $request = ServerRequestFactory::fromGlobals(); $client = new Client(); // Response comes back from Guzzle $response = $client->send($request->withUrl($dest)); $body = simplexml_load_string( $response->getBody()->getContents()); // pass back to Diactoros (new SapiEmitter)->emit($response->withBody($body));

The example uses HTTP requests from Zend Diactoros, forwards them using the Guzzle HTTP client, and returns the response object from Guzzle using the SAPI Emitter from Diactoros.

This demonstrates the power of sharing standard interfaces. Here two packages are used together, both provide an implementation of PSR7 HTTP messages, and they work seamlessly because they both conform to the same interface, despite the differing implementation details.

Decorating Web Apps

This is what a typical web app looks like:

Ball of Mud

Which can be simplified to this:

Web App

A web app takes a request and returns a response.

The concept behind PHP Middleware is that you can decorate the app, to add new functionality, by intercepting the request on the way in, and the response on the way out. This avoids the complexity of intertwining your code throughout the ball of mud.

Web App

Here’s an example (pseudocode) for adding CORS functionality to an existing app:

$cors = analyze($request); switch ($cors->getRequestType()) { Case ERR_NO_HOST_HEADER: Case ERR_ORIGIN_NOT_ALLOWED: Case ERR_METHOD_NOT_SUPPORTED: Case ERR_HEADERS_NOT_SUPPORTED: Return createResponse(403); Case TYPE_REQUEST_OUT_OF_CORS_SCOPE: return $APP->process($request); Case TYPE_PRE_FLIGHT_REQUEST: $response = Utils\Factory::createResponse(200); Return $response->withHeaders($cors->getHeaders); default: $response = $APP->process($request); Return $response->withHeaders($cors->getHeaders); }

StackPHP first popularised the concept of middleware in PHP. This diagram is from their website:

Web App

There are other popular micro-frameworks based on this concept, such as Slim.

The core of your app is just a thin layer of business logic. Just your domain specific code. The rest can be wrapped in layers which isolate and separate concerns nicely.

Single-pass vs Double-pass

The double pass approach became the most popularly used signature for HTTP middleware, based on Express middleware from the JS community.

It looks like this:

// DOUBLE PASS function __invoke($request, $response, $next) { }

The request and the response are both passed into the middleware, along with a $next delegate that is called to pass control and carry on processing down the chain of middleware.

This double-pass approach is much newer, but used by most of the early adopters of PSR-7.

A single pass approach, looks like this:

// SINGLE PASS / LAMBDA function process($request, $delegate) { }

The issue is with how the response object is dealt with. In the double-pass approach, both are provided. The argument is that this is better for dependency inversion. Using the single pass approach you either need to hard code a dependency on a HTTP message implementation into your middleware when the response is required, or you need to inject a factory for generating the response.

PSR-15 HTTP Middleware

After the success of PSR7, with it’s wide adoption leading to much standardisation and interoperability in PHP frameworks, the next step is to standardise the middleware interface.

This is not yet an accepted PSR. At the time of writing it is still in draft status. It is available for use in the http-interop/http-middleware repo.

Invoker

As an aside, I mentioned the Invoker Interface. As per the docs:

“Who doesn’t need an over-engineered call_user_func()?”

In particular this library really simplifies the process of calling things and injecting dependencies. It also allows to call things using named parameters. I make extensive use of this, and I find making calls with named parameters makes code much easier to understand.

PSR-15 Interfaces

PSR-15 has two interfaces. Both define a method called process. One is the signature that middleware must support, which takes a PSR7 request and a PSR15 delegate. The other interface defines the process method for the delegate. The method on both interfaces is defined as returning a PSR7 response.

Web App

So you can compose a chain of middleware, pass in a request and get a response. The request is passed down the chain of middleware until a response is generated which is then passed back up the chain, possibly being decorated along the way.

For want of a better name, I refer to this chain of middleware as a stack. And, I have created a simple Stack Runner to handle the processing of a stack of PSR-15 middleware.

class StackRunner implements DelegateInterface { public function __construct( array $stack, InvokerInterface $invoker, ResponseFactoryInterface $responseFactory ) { ... } public function process(ServerRequestInterface $request) { if (!isset($this->stack[$this->current])) { return $this->responseFactory->createResponse(); } $middleware = $this->stack[$this->current]; $this->current++; return $this->invoker->call([$middleware, 'process'], [ 'request' => $request, 'delegate' => $this, ]); } } ADR (Action Domain Responder)

I went on to talk about ADR as being an adaptation of MVC that is more suitable for use in Web Apps. I’ve found this particularly useful when using Domain-Driven Design, or when used to create thin APIs where you have just a thin layer of business logic on top of a data store.

The issue with MVC is that the template is not the view. The “view” of a web app is the HTTP response, and we split this across our layers, as the body of the response is typically generated by the view, with the knowledge of HTTP being encoded into our controllers. We also bundle together various actions into one controller, which means instantiating the whole thing when we want to run one of the actions.

ADR offers an alternative separation of concerns, where the action methods of the controller are their own separate classes (or in my case anything invokable via the InvokerInterface). I use an InputHandler to deal with parsing the input from the HTTP Request, which the Invoker can then use (via the magic of named arguments).

The domain (Model in MVC terminology) is where the business logic lives. This is called domain, rather than model, to suggest use of domain-driven design.

To use ADR with PHP Middleware, add a resolver to the end of the chain of middleware to dispatch the request to the appropriate Action.

Web App

Action

I’ve created a reference implementation of an invokable Action.

Web App

Demo!

At this point in my talk I planned to give a demo of how you compose ADR with Middleware to create a working API. Unfortunately, I had some tech issues getting my computer linked up to the projector, and I was starting to feel really ill (full of cold). By this time the caffeine was starting to wear off, and I needed the talk to end!

I’ve put the example code up in a GitHub repo.

References
  • Simple Made Easy - talk by Rich Hickey
  • HTTP Middleware and HTTP Factory interfaces.
  • PSR15 Middlewares a set of really useful middlewares that can be used with a PSR15 middleware dispatcher.
  • Stack Runner my reference implementation of a very simple stack runner for executing a chain of PSR15 middleware.
  • Wafer an experimental implementation of the ADR idea to be used along with PSR15 middleware and the stack runner.

Drop me a line with any feedback. Thanks!

Darren Mothersele: How to do Everything with PHP Middleware (DrupalCamp London)

Feeds from Drupal.org - Tue, 2017-03-28 09:30

At the DrupalCamp in London earlier this month I gave a talk about PHP Middleware. You can see a recording of the talk on YouTube. Here’s a summary, in case you don’t want to watch the whole talk, or the distorted audio upsets you, or if you want the links and references:

Simple vs Easy

I started with a reference to the important talk by Rich Hickey, Simple Made Easy. This is high up on my list of videos every software developer needs to watch. I began here because I think it’s important to identify the difference between simple and easy, to identify where complexity sneaks into our systems. I have found PHP Middleware to be an important tool in the fight against complexity.

“programming, when stripped of all its circumstantial irrelevancies, boils down to no more and no less than very effective thinking so as to avoid unmastered complexity, to very vigorous separation of your many different concerns.

Edsgar W. Dijkstra (1930 - 2002)

De-complecting PHP

I talked a bit about different ways to simplify development with PHP. Including: Domain-driven design, Hexagonal architecture (Ports and Adapters), Framework-independent code, Thin APIs, etc… In particular, I wanted to emphasise the importance of framework-independent code and the benefit of using common interfaces such as the ones developed as PSRs by PHP-FIG.

There was some discussion after about introducing unecessary abstractions, but I think this misses the point. Of course there is a trade off, but the key is to focus on the simplicity, on untwisting things (c.f. Rich Hickey).

De-coupled

Inspired by the Zend Expressive installation procedure, I imagined what Drupal 10 might look like, with fully-decoupled components.

Drupal Install

Interfaces

The widespread adoption of PSR7 by the PHP community has lead to the popularity of PHP Middleware-based systems.

Why PSR7 when Symfony HTTP components were so popular? Well, that is an implementation - and rather than standardise on implementation, we should standardise against interfaces.

This allows more interoperability. I showed this pseudocode:

// Take the incoming request from Diactoros $request = ServerRequestFactory::fromGlobals(); $client = new Client(); // Response comes back from Guzzle $response = $client->send($request->withUrl($dest)); $body = simplexml_load_string( $response->getBody()->getContents()); // pass back to Diactoros (new SapiEmitter)->emit($response->withBody($body));

The example uses HTTP requests from Zend Diactoros, forwards them using the Guzzle HTTP client, and returns the response object from Guzzle using the SAPI Emitter from Diactoros.

This demonstrates the power of sharing standard interfaces. Here two packages are used together, both provide an implementation of PSR7 HTTP messages, and they work seamlessly because they both conform to the same interface, despite the differing implementation details.

Decorating Web Apps

This is what a typical web app looks like:

Ball of Mud

Which can be simplified to this:

Web App

A web app takes a request and returns a response.

The concept behind PHP Middleware is that you can decorate the app, to add new functionality, by intercepting the request on the way in, and the response on the way out. This avoids the complexity of intertwining your code throughout the ball of mud.

Web App

Here’s an example (pseudocode) for adding CORS functionality to an existing app:

$cors = analyze($request); switch ($cors->getRequestType()) { Case ERR_NO_HOST_HEADER: Case ERR_ORIGIN_NOT_ALLOWED: Case ERR_METHOD_NOT_SUPPORTED: Case ERR_HEADERS_NOT_SUPPORTED: Return createResponse(403); Case TYPE_REQUEST_OUT_OF_CORS_SCOPE: return $APP->process($request); Case TYPE_PRE_FLIGHT_REQUEST: $response = Utils\Factory::createResponse(200); Return $response->withHeaders($cors->getHeaders); default: $response = $APP->process($request); Return $response->withHeaders($cors->getHeaders); }

StackPHP first popularised the concept of middleware in PHP. This diagram is from their website:

Web App

There are other popular micro-frameworks based on this concept, such as Slim.

The core of your app is just a thin layer of business logic. Just your domain specific code. The rest can be wrapped in layers which isolate and separate concerns nicely.

Single-pass vs Double-pass

The double pass approach became the most popularly used signature for HTTP middleware, based on Express middleware from the JS community.

It looks like this:

// DOUBLE PASS function __invoke($request, $response, $next) { }

The request and the response are both passed into the middleware, along with a $next delegate that is called to pass control and carry on processing down the chain of middleware.

This double-pass approach is much newer, but used by most of the early adopters of PSR-7.

A single pass approach, looks like this:

// SINGLE PASS / LAMBDA function process($request, $delegate) { }

The issue is with how the response object is dealt with. In the double-pass approach, both are provided. The argument is that this is better for dependency inversion. Using the single pass approach you either need to hard code a dependency on a HTTP message implementation into your middleware when the response is required, or you need to inject a factory for generating the response.

PSR-15 HTTP Middleware

After the success of PSR7, with it’s wide adoption leading to much standardisation and interoperability in PHP frameworks, the next step is to standardise the middleware interface.

This is not yet an accepted PSR. At the time of writing it is still in draft status. It is available for use in the http-interop/http-middleware repo.

Invoker

As an aside, I mentioned the Invoker Interface. As per the docs:

“Who doesn’t need an over-engineered call_user_func()?”

In particular this library really simplifies the process of calling things and injecting dependencies. It also allows to call things using named parameters. I make extensive use of this, and I find making calls with named parameters makes code much easier to understand.

PSR-15 Interfaces

PSR-15 has two interfaces. Both define a method called process. One is the signature that middleware must support, which takes a PSR7 request and a PSR15 delegate. The other interface defines the process method for the delegate. The method on both interfaces is defined as returning a PSR7 response.

Web App

So you can compose a chain of middleware, pass in a request and get a response. The request is passed down the chain of middleware until a response is generated which is then passed back up the chain, possibly being decorated along the way.

For want of a better name, I refer to this chain of middleware as a stack. And, I have created a simple Stack Runner to handle the processing of a stack of PSR-15 middleware.

class StackRunner implements DelegateInterface { public function __construct( array $stack, InvokerInterface $invoker, ResponseFactoryInterface $responseFactory ) { ... } public function process(ServerRequestInterface $request) { if (!isset($this->stack[$this->current])) { return $this->responseFactory->createResponse(); } $middleware = $this->stack[$this->current]; $this->current++; return $this->invoker->call([$middleware, 'process'], [ 'request' => $request, 'delegate' => $this, ]); } } ADR (Action Domain Responder)

I went on to talk about ADR as being an adaptation of MVC that is more suitable for use in Web Apps. I’ve found this particularly useful when using Domain-Driven Design, or when used to create thin APIs where you have just a thin layer of business logic on top of a data store.

The issue with MVC is that the template is not the view. The “view” of a web app is the HTTP response, and we split this across our layers, as the body of the response is typically generated by the view, with the knowledge of HTTP being encoded into our controllers. We also bundle together various actions into one controller, which means instantiating the whole thing when we want to run one of the actions.

ADR offers an alternative separation of concerns, where the action methods of the controller are their own separate classes (or in my case anything invokable via the InvokerInterface). I use an InputHandler to deal with parsing the input from the HTTP Request, which the Invoker can then use (via the magic of named arguments).

The domain (Model in MVC terminology) is where the business logic lives. This is called domain, rather than model, to suggest use of domain-driven design.

To use ADR with PHP Middleware, add a resolver to the end of the chain of middleware to dispatch the request to the appropriate Action.

Web App

Action

I’ve created a reference implementation of an invokable Action.

Web App

Demo!

At this point in my talk I planned to give a demo of how you compose ADR with Middleware to create a working API. Unfortunately, I had some tech issues getting my computer linked up to the projector, and I was starting to feel really ill (full of cold). By this time the caffeine was starting to wear off, and I needed the talk to end!

I’ve put the example code up in a GitHub repo.

References
  • Simple Made Easy - talk by Rich Hickey
  • HTTP Middleware and HTTP Factory interfaces.
  • PSR15 Middlewares a set of really useful middlewares that can be used with a PSR15 middleware dispatcher.
  • Stack Runner my reference implementation of a very simple stack runner for executing a chain of PSR15 middleware.
  • Wafer an experimental implementation of the ADR idea to be used along with PSR15 middleware and the stack runner.

Drop me a line with any feedback. Thanks!

Categories: Straight From Drupal

Agiledrop.com Blog: AGILEDROP: Responsive Images in Drupal 8

Planet Drupal - Tue, 2017-03-28 08:56
The days of fixed-width websites are long behind us, and with fluid widths came fluid images. In many cases, we don’t want to display the same image size on a mobile and on a desktop, because we truly don't need a 2000px wide image on a 480px device. Or we want to display a completely different image at some breakpoint. For this we have a HTML5 element which can contain a multiple elements with srcset and media attributes. The browsers choose the right source based on a media query. In my case, I had to show completely different image sizes on mobile vs.… READ MORE

Agiledrop.com Blog: AGILEDROP: Responsive Images in Drupal 8

Feeds from Drupal.org - Tue, 2017-03-28 08:56
The days of fixed-width websites are long behind us, and with fluid widths came fluid images. In many cases, we don’t want to display the same image size on a mobile and on a desktop, because we truly don't need a 2000px wide image on a 480px device. Or we want to display a completely different image at some breakpoint. For this we have a HTML5 element which can contain a multiple elements with srcset and media attributes. The browsers choose the right source based on a media query. In my case, I had to show completely different image sizes on mobile vs.… READ MORE
Categories: Straight From Drupal

Pages

Subscribe to My Drupal aggregator