D8DX: Improving the D8 developer experience

The Goal

One of the things that makes Drupal great is the power it puts into the hands of non-developers to do awesome and amazing things on the web. A large portion of our community made a transition from non-developer to developer thanks to the accessibility/hackability of Drupal from an API perspective in Drupal 7 and below. In Drupal 8, however, things have become more... complicated. While flexibility is greatly increased, so too is the mental overhead as well as verbosity for doing even simple tasks.

This initiative is about making some key changes to the "DX" (developer experience) of Drupal in order to make it more accessible to people who need to extend Drupal to make it do cool things, but don't necessarily have a background in programming.

Reporting DX Issues

I tried porting my module to Drupal 8, and I'm concerned about D8's developer experience. How can I help fix it?

Please tell the core developers about it; we'd love for you to love Drupal 8 as much as we do!

  1. Search for open or all 8.x issues with the DX (Developer Experience) tag.

Namespaces

PHP 5.3 introduces namespaces to the language. This page documents how namespaces should be referenced within Drupal and it assumes that you are familiar with the concept of namespaces. (If not, you can have a look to this article introducing namespaces.)

Not all files in Drupal declare a namespace. As of Drupal 8 an increasing number of files do, but not all. Prior to Drupal 8 virtually no code used namespaces, in order to remain compatible with PHP 5.2. There are therefore two slightly different standards.

"use"-ing classes

  • Classes and interfaces with a backslash \ inside their fully-qualified name (for example: Drupal\simpletest\WebTestBase) must not use their fully-qualified name inside the code. If the namespace differs from the namespace of the current file, put a use statement on the top of the file. For example:
    <?php
    namespace Drupal\mymodule\Tests\Foo;

    use
    Drupal\simpletest\WebTestBase;

    /**
     * Tests that the foo bars.
     */
    class BarTest extends WebTestBase {
    ?>
  • Classes and interfaces without a backslash \ inside their fully-qualified name (for example, the built-in PHP Exception class) must be fully qualified when used in a namespaced file. For example: new \Exception();. Do not use global classes.

Object-oriented code

Drupal follows common PHP conventions for object-oriented code, and established industry best practices. As always, though, there are Drupal-specific considerations.

Subscribe with RSS Subscribe to RSS - Object Oriented Programming