- Drupal 8 for site builders
- New concepts from PHP
- Architecture overview
- D8 building blocks
- Testing
- Drupal 8 is a modern, PHP 5.3 application
- We ported Drupal to a new language
- The end of "Not Invented Here"
- Playing nice with others
- Concepts you need to understand:
- Namespacing
- All classes must be named like:
\<Vendor Name>\(<Namcespace>)*\<Class Name> - Allows standard autoloading
- All classes must be named like:
- Interfaces
- Separate code design from code implementation
- Allow objects to be mocked (testable)
- Allow implementations to be swapped
- Look at these first in Drupal core code
- Annotations
- Docblocks as class definitions
- Parsed on execute
- Largely replaces
hook_*_info()blocks - Keeps definitions with the class that it defines
- Plugins
- Generic term for a "code model"
- Basically, a standardized CTools plugin system
- Autoloading
- Encourages library code
- See Views module in D7!
- YAML
- Generic, portable syntax for complex data
- Core of the CMI, and a bunch of other places
- Namespacing
- HTTP Architecture:
Request -> Your server -> Response - Symfony architecture:
Request -> HttpKernel -> Response
- Should be very thin.
- Request objects are passed in as a parameter named
$requestto a controller function - Note the order of the variables passed in doesn't really matter: as long as you name them the same as the
routing.ymlfile. - Routes have:
- machine names
- patterns (begin with leading slash)
- defaults (default values for parameters)
- requirements (permissions, regular expressions to apply to parameters)
- options
- Write 3 controllers:
- Return "Hello world" as Drupal page body
- Return "Hello world" as JSON response
- Return "Hello %name" as Drupal page body, where name was passed in.
- You can use https://github.com/palantirnet/hellodrupal (branch 01-initial) as a starting point.
- Built on listeners
- Using RouteEnhancers, you can wrap controller responses with other controller responses, allowing you to request a dialog version without the page stuff
- Another listener is Access control:
- Authentication = "Who are you?"
- Note:
$request->attributes->get('_account')replacesglobal $user
- Note:
- Authorization = "What are you allowed to do?"
- Multiple "checkers" per route
- Might apply or not
- Can return:
static::ALLOW= This checker passesstatic::DENY= This checker failsstatic::KILL= Immediately deny access
_access_modecan be:ANY=||= Allow if any checkers return TRUEALL=&&= Allow only if all checkers return TRUE
- Authentication = "Who are you?"
- Dependency = "An object on which your object depends"
- Always make your dependencies interfaces!
- Sucks to wire it up though. See "Dependency Injection Container""
- Service = "A generally-stateless "global" object"
- There should only be one of these (i.e.: singleton), but the system should enforce that.
- Dependency Injection Container" = "Place where you wire that stuff up in advance"
- "Scariest possible name for an array of objects"
- You'll almost never interact with it directly
- Configure via YAML
- Your classes should not know about it
- Define services in
modulename.services.yml.- Services have:
- Machine name
- Class that does the work
- Optional list of arguments it needs to instantiate
- Optional list of things that need to be called on it after it's created
- Services have:
- System will detect circular dependencies and prevent you from setting it, at compile time.