Skip to content

Instantly share code, notes, and snippets.

@ornj
Created May 21, 2013 22:52
Show Gist options
  • Save ornj/5623917 to your computer and use it in GitHub Desktop.
Save ornj/5623917 to your computer and use it in GitHub Desktop.
My notes from the first day of presentations at Drupalcon Portland 2013

Notes from Drupalcon Portland, Tuesday May 21, 2013

General Drupal 8 Stuff

  • Top level libraries, modules, themes, and profiles directories are where you should put all shared modules. Core stuff is in core/
  • Hooks are replaced by annotations
  • Can have custom block types, blocks have fields now
  • Tour module lets you add hints as to what the UI/page is supposed to do

Future of Views

  • Views are saved to disk, not database.
  • Views will export/render JSON
  • Info hooks should instead be in YAML config (Views plugins work the same as any other D8 plugin)
  • Views UI can be replaced by contrib modules
  • Configuration information like enabled modules, field instances, menus, and settings are in sites/*/config_*/active instead of the database. Destroy this and your site will not work.
  • uuid in core so you don't need to worry about syncing

Get your data into Drupal with Feeds (Drupal 7)

  • Project page, has a dependency on job_scheduler
  • Import 3rd party data in many formats including xml, html, rss, etc and save it as nodes, terms, users, whatever.
  • Can schedule imports which will recognize data that has changed (can update entities)
  • Parsers can use xPath, QueryPath, etc to transform raw data to make it useable by Drupal. Good for scraping data from xml, html, etc.
  • This looks like a helpful Chrome plugin for writing and evaluating xPath queries, https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en
  • Processors are available for most entities
  • Mappers provide links between parsed data and Drupal objects (fields mostly)

Dependency Injection in Drupal 8

Dependency Injection as a Design Pattern

  • Goal is to be clutter-free, reusable, testable. Create functions where the bulk is specific to the task being handled. Write code that is "ignorant"
  • The more your class knows about other classes, the more dependent it is that they stay the same.
  • Constructor Injection: Avoid tightly coupled dependencies and having to handle instantiating objects by passing dependencies as parameters in the constructor.
  • Good to expect an interface (eg: MailerInterface) instead of a specific class.
  • Setter Injection: pass dependency through a setter (eg: $class->setMailer())
  • Framework is the active party, your code is passive and called by the framework. Inverted control (Hollywood principle, "Don't call us, we'll call you.").

Where does injection happen?

  • Manual injection, factory, container/injector
  • In framwework, Service Container assumes responsibility for constructing object graphs. Keeps infrastructure seperate from logic
  • A service is not a data object
  • "The scope of a service is the context under which the service key refers to the same instance."

Symfony Dependency Injection Component

  • Service keys are strings
  • Service definitions allow you to specify additional methods to be called on the object after it's been instantiated.
  • Default scope: container
  • Symfony's DI component parses config and outputs compiled PHP.
  • Compiler passes are classes that process the container and give you a way to manipulate existing services
  • Add tags to services to flag them for certain compiler passes
  • Add compiler passes in class that extends BundleInterface

Dependency Injection in Drupal 8

  • Default db connection: database
  • Module handler module_handler
  • HTTP request object (synthetic) request
  • To use a core service either...
  • Service locator anti-pattern (procedural): Drupal::service('some_service')
  • Prefered method: drupal_container()->get('some_service')
  • Controllers shouldn't be made services themselves, instead implement an interface that has a factory method which accepts the container
  • Don't inject the container... unless you absolutely need to.

Easy Testability With DI and PHPUnit

  • You probably don't want to be loading/testing the dependencies as well as your own code. PHPUnit will allow you to mock up the dependency and tell it how to behave

Misc

  • Some hooks have been replaced by Symfony's EventDispatcher. Currently something being worked on. Go to http://drupal.org/list-changes to see if a hook has been converted
  • Slides for DI talk are available at http://katbailey.github.io
  • Everything after mymodule/lib/ is the PHP namespace. Vendors go in lib. There is a composer manager module attempting to solve the issue of having duplicate vendors

Secrets to Awesomizing® Your Editor's Back-end Drupal Experience

  • Rules or Login Redirect module to take user away from default post-login page.
  • Use Drupal's core dashboard and customize with Views
  • In views, enable global contextual links
  • Enabled revisions on your content types
  • "Don't make a Drupal site that sucks.", lulz.

Modules to Improve Workflow

Mentioned by Commentors

  • Override Node Options: allows permissions to be set to each field within the Authoring information and Publishing options field sets on the node form
  • Conditional Fields: Define dependencies between fields based on their states and values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment