StackStarter.io/spin
Spin Code: #trainingday

Exploring Drupal 8

Long Island
Training Day

Nick Selvaggio | Rich von Rauchhaupt | Mai Irie

A little about us.

Hi! I'm Nick.
I'm a Managing Partner @
Stony Brook Logo

Hi! I'm Rich.
I'm a Web Platform Strategist & Architect @
Stony Brook Logo

Hi! I'm Mai. I'm a senior developer @

About LIDUG

Join the local community!

Try Drupal

TryDrupal8.com

Our podcast series: Talking Drupal Podcast

A little about you.

Play Along!

StackStarter.io/spin
Spin Code: #trainingday

Let's talk Drupal...

What is Drupal?

Where have we come from?

Our many stages of evolution

Where are we going?

A revolution is happening!

Who uses Drupal?

Memorial Sloan Kettering Cancer Center (MSK)

One of the largest cancer centers in the United States, launched the new mskcc.org in May. It chose Drupal 8, even when the software was still in its beta phase, to help extend the reach of its "More Science. Less Fear" campaign.

CH2M

CH2M is a global corporation that works to keep governments, infrastructure, and environments sustainable. It uses Drupal 8 to present and prove its capabilities.

Many, Many, Many More

drupal.org/case-studies/featured/all/drupal-8.x

Lets step back...

Lets talk about the C in CMS

Content First

Structuring our content

What makes Drupal unique?

Some terminology

Entities

Nodes
Taxonomy
Users
Comments
...

Fields

Text
Numbers
Select Lists
...

Fields can be "bundled" with Entities

Nodes -> Content Types
Taxonomy -> Vocabularies

Views

Define Lists of Content
Define how to output the given list

Modules

Finding Modules
When to bring in a module

Themes

Finding Themes
Base themes

Regions

Blocks

Lets dive in!

Under the hood

We can do alot with just core. Let's see how we can extend.

File Structure

Settings.php and friends

Make our lives easier with Drush

What about Drupal Console?

Ok are you ready to go deeper?

Stucture of a module

/modules/custom/hello/hello.info.yml


name: Hello
description: A friendly Drupal 8 module
type: module
core: 8.x
            

Modules now live in the /modules directory

We don't need a .module file anymore!

Lets make a Page...

Without hook_menu!

/modules/custom/hello/src/Controller/HelloController.php

/**
 * Our first Drupal 8 controller.
 */
namespace Drupal\hello\Controller;

use Drupal\Core\Controller\ControllerBase;

class HelloController extends ControllerBase {
  public function sayHi() {

    return array(
        '#markup'=>"Why hello Drupal 8",
      );
  }
}
            

/modules/custom/hello/hello.routing.yml

              
              hello.sayHi:
  path: '/hello'
  defaults:
    _controller: '\Drupal\hello\Controller\HelloController::sayHi'
  requirements:
    _permission: 'access content'

              
            

What about Forms?

Very similar pattern!

/modules/custom/hello/src/Form/HelloRequestForm.php

              
/**
 * @file
 * Contains \Drupal\hello\Form\HelloRequestForm.
 */

namespace Drupal\hello\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class HelloRequestForm extends FormBase {
  /**
   * {@inheritdoc}.
   */
  public function getFormId() {
    return 'hello_request';
  }

  /**
   * {@inheritdoc}.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['phone_number'] = array(
      '#type' => 'tel',
      '#title' => $this->t('Your phone number')
    );
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => $this->t('Give me a call'),
      '#button_type' => 'primary',
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    if (strlen($form_state->getValue('phone_number')) < 3) {
      $form_state->setErrorByName('phone_number', $this->t('The phone number is too short. Please enter a full phone number.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    drupal_set_message($this->t('Your phone number is @number', array('@number' => $form_state->getValue('phone_number'))));
  }
}

              
            

/modules/custom/hello/hello.routing.yml

              
              hello.requestHi:
  path: '/hello/request'
  defaults:
    _form: '\Drupal\hello\Form\HelloRequestForm'
  requirements:
    _permission: 'access content'
              
            

Lets make a Block!

Without hook_block_info and hook_block_view!

/modules/custom/hello/src/Plugin/Block/HelloBlock.php

              
namespace Drupal\hello\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'Hello' block.
 *
 * @Block(
 *   id = "hello_block",
 *   admin_label = @Translation("Hello block"),
 * )
 */
class HelloBlock extends BlockBase {
  public function build() {
    return array(
      '#markup' => $this->t("This is a an awesome block!"),
    );
  }
}

              
            

How about themes?

Similar strucuture to modules.

Let's download some, and explore

Ok, we are experts. Lets build!

Let's build a site together, your client is a large educational institution and they require a small departmental site that will enable the following set of functionality

Manage users in two different roles:

  • Staff
  • Student

Ability to create and share events on an event page.

Events can be any of the various different types:

  • Student Events
  • Faculty Events
  • Community Events

Events are accessible by anyone.

Today we covered:

  • Provided an overview of our active local community
  • Learned about the history of Drupal
  • What makes Drupal a unique and powerful CMS.
  • Reviewed the core concepts of a Drupal site
  • Took a tour of the Drupal 8 interface
  • Dove deeper into the internals of Drupal 8
  • Built a basic site using some of the topics covered

Support Drupal & community events like this

Drupal Association Member Benefits

  • Listed in public directories
  • Receive discounts from DA partners like O'Reilly, Drupal Watchdog, and BuildAModule
  • Membership Badge on your Drupal user profile
  • Receive the latest news on Drupal Association projects.

Thank you!

Please share your feedback! https://www.surveymonkey.com/r/XWGNNPP