Drupal: Re-joining the Herd – PHP South Coast 2016 – Drupal via Composer



Drupal: Re-joining the Herd – PHP South Coast 2016 – Drupal via Composer

0 0


slides-drupal-rejoining-the-herd


On Github opdavies / slides-drupal-rejoining-the-herd

Drupal: Re-joining the Herd

PHP South Coast 2016

Oliver Davies / @opdavies

Drupal: Getting off the Island

PHP South Coast 2016

Oliver Davies / @opdavies

Drupal: Re-joining the Herd

PHP South Coast 2016

Oliver Davies / @opdavies

@opdavies

  • Senior Drupal Developer at Appnovation Technologies
  • Former Drupal Association employee
  • Symfony hobbyist
  • Drupal Bristol organiser, PHPSW and DrupalCamp Bristol co-organiser
  • First PHP conference!
  • IT guy turned Web Developer
  • Been doing Drupal since 2007, end of Drupal 5/beginning of Drupal 6
  • Drupal VM Generator - built on Symfony Console
  • First PHP conference!

Purpose

  • If you're new to Drupal, go and try it
  • If you've used it before, re-try it

About Drupal

  • Drupal is an open source, PHP content management system
  • 16 years old
  • Drupal 8 was released in November 2015
  • Non-BC changes between major versions
  • Mostly procedural code prior to D8
  • Drupalisms
  • Drupal was released on Jan 15, 2000
  • Drupal 8 took 4 years to complete - started in 2011

Entities(ish)

  • Everything uses stdClass
  • No consistency between models
nid for node ID, uid for user ID

Hooks

// hello.module

/**
 * Implements hook_menu()
 */
function hello_menu() {
  $items['hello-world'] = array(
    ...
  );

  return $items;
}

Theme functions

$items[
  l('Foo', 'foo'),
  l('Bar', 'bar'),
];

return theme('item_list', ['items' => $items]);
          

        

http://www.ekino.com/wp-content/uploads/2013/09/drupal8-meets-symfony.jpg

http://jmolivas.com/slides/drupalcon2015bogota/speeding-up-drupal-8-development-using-drupal-console/assets/images/larry-crell.jpg

  • Larry Garfield
  • Drupal 8 Web Services initiative lead
  • PHP-FIG representative

Symfony

  • Core developed using Symfony components
  • Minimum PHP version requirement
  • PHP code in classes
  • No more functions (almost)
  • Namespaces
  • PSR-0 PSR-4 Autoloading
  • Dependency injection
  • Full test coverage
  • Consistency!
  • .php files rather than .inc
  • 5.5.9 minimum

Symfony components

  • ClassLoader
  • Console
  • CssSelector
  • DependencyInjection
  • EventDispatcher
  • HttpFoundation
  • HttpKernel
  • Process
  • Routing
  • Serializer
  • Translation
  • Validator
  • Yaml

http://symfony.com/projects/drupal

  • Guzzle replacing drupal_http_request() - 311 lines removed

YAML

example.info (D7)

name = Example
core = 7.x
package = Custom

dependencies[] = entity

files[] = a.inc
files[] = b.inc
            

example.info.yml (D8)

name: Example
type: module
core: 8.x
package: Custom

dependencies:
- entity
            

Routing (D7)

hello.module

function hello_menu() {
  $items['hello-world'] = [
    'title' => 'Hello, PHPSC',
    'page callback' => 'hello_page_callback',
    'access arguments' => ['access content'],
  ];

  return $items;
}
            

Routing (D8)

hello.routing.yml

hello.view:
  path: /hello-world
  defaults:
    _title: 'Hello, PHPSC'
    _controller: '\Drupal\hello\Controller\PageController::helloView'
            

Annotations

Used in some places - e.g. plugin system

Twig

  • Default theme engine in D8
  • Replaces phptemplate
  • No more database queries in templates
  • No more theme functions

Not Invented Here

Not Invented Here

Proudly found elsewhere

  • jQuery *
  • Symfony
  • Symfony CMF
  • CKEditor
  • Zend
  • Composer
  • Stack
  • Guzzle
  • Twig
  • PhpUnit

http://cgit.drupalcode.org/drupal/tree/core/composer.json

Composer

  • Drupal 8 using Composer for dependency management and autoloading
  • Better Composer support since 8.1
  • Composer integration on Drupal.org
  • Drupal Composer projectroject template
    • Project template
    • Drupal Packagist

Drupal via Composer

"repositories": [
  {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
  }
],
require: {
  "drupal/core": "~8.0"
},
...
            

https://github.com/platformsh/platformsh-example-drupal/blob/8.x/composer.json

Contrib

Libraries first

  • Non-Drupal problems being fixed outside of Drupal
  • Framework agnostic PHP libraries
  • Better exposure
  • Production tested code
  • Allows for backports
  • Commerce Guys/Drupal Commerce
  • Non-Drupal problems fixed in libraries and Drupal modules were written with libraries as dependencies.

Libraries first

Libraries First

Drupal Console

  • A CLI tool for generating Drupal code and interacting with Drupal 8 websites
  • Based on Symfony Console component
  • PSR-2 coding style, outputs Drupal code style
  • http://drupalconsole.com

Going forward

  • Semantic versioning
  • Feature releases every 6 months
https://www.drupal.org/core/release-cycle-overview

More to do?

  • Still some Drupalisms
  • PSR-2
  • GitHub/Packagist
  • Drupal CI
  • Hooks, render arrays
  • Code repsositories and packaging still done on Drupal.org

In Summary

  • Lowered the barrier to entry for PHP Developers
  • Made me a better Developer
  • More transferable knowledge and skills
  • Changed perspective

Links

Questions?

DrupalCamp Bristol

22nd - 24th July

https://www.drupalcampbristol.co.uk

phpsc-fri - £20 off the business dayphpsc-sat - £5 off the conference day

## Feedback Joind.in: [https://joind.in/talk/41d0f](https://joind.in/talk/41d0f) Twitter: [@opdavies](https://www.twitter.com/opdavies)