StackStarter.io/spin
Spin Code: #trainingday
Hi! I'm Nick.
I'm a Managing Partner @
Hi! I'm Rich.
I'm a Web Platform Strategist & Architect @
Hi! I'm Mai. I'm a senior developer @
Join the local community!
Our podcast series: Talking Drupal Podcast
StackStarter.io/spin
Spin Code: #trainingday
Our many stages of evolution
A revolution is happening!
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 is a global corporation that works to keep governments, infrastructure, and environments sustainable. It uses Drupal 8 to present and prove its capabilities.
Lets talk about the C in CMS
We can do alot with just core. Let's see how we can extend.
/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!
Without hook_menu!
/**
* 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'
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'
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!"),
);
}
}
Similar strucuture to modules.
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:
Ability to create and share events on an event page.
Events can be any of the various different types:
Events are accessible by anyone.
Please share your feedback! https://www.surveymonkey.com/r/XWGNNPP