View
213
Download
1
Category
Preview:
Citation preview
Introduction to Symfony components and helper components in Drupal 8
Ankit Babbar Drupal Developer at ValueboundVolunteer at SPIC MACAYtwitter: ankitbabbar
History of PHP
Functional vs OOPs ProgrammingFrameworks
3rd Party LibrariesNamespace
PHP-FIGYAML
Composer
https://cipix.nl/understanding-drupal-8-part-1-general-structure-framework
HTTP request looks like:
GET /foo.html HTTP/1.1Host: example.comAccept: text/htmlUser-Agent: Mozialla/5.0 (Macintosh)
GET Retrieve the resource from the server
POSTCreate a resource on the server
PUT Update the resource on the server
DELETE Delete the resource from the server
Request
HTTP response looks like:HTTP/1.1 200 OKDate: Sat, 25 Jul 2015 10:30:00 ISTServer: apache2/2.xxContent-Type: text/html
<html>
Response
YAML: YAML Ain’t Markup LanguageSample Router
hello_world.content: path: ‘/hello-world' defaults: _controller: '\Drupal\hello\Controller\HelloController::content' _title: 'Hello World' requirements: _permission: 'access content'
Sample Hello World Controllerclass HelloController extends ControllerBase { public function content() { return array( '#type' => 'markup', '#markup' => t('Hello, World!'), ); }}
class Notifier { private $mailer; public function __construct() { $this->mailer = new Mailer(); } public function notify() { … $this->mailer->send($from, $to, $msg); … }}
class Notifier { private $mailer; public function __construct(MailInterface $m) { $this->mailer = $m; } public function notify() { …. $this->mailer->send($from, $to, $msg); … }}
$mailer = new SpecialMailer();$notifier = new Notifier($mailer);
Composer
Sample composer.json for hello_world module{ "name": “drupal/hello_world", "require": { "mailchimp/mailchimp": "2.0.6" }}
Full Controller File Look like:<?php/** * @file * Contains \Drupal\hello\Controller\HelloController. */
namespace Drupal\hello\Controller;
use Drupal\Core\Controller\ControllerBase;class HelloController extends ControllerBase { public function content() { return array( '#type' => 'markup', '#markup' => t('Hello, World!'), ); }}?>
1. Symfony Documentation2. DrupalCon Denver 2012: DRUPAL 8 MEETS SYMFONY2
https://www.youtube.com/watch?v=Gr71z_WoejM3. UNDERSTANDING DRUPAL 8: https://cipix.nl/understanding-drupal-8-part-1-
general-structure-framework4. DrupalCon Portland 2013: DEPENDENCY INJECTION IN DRUPAL 8
https://www.youtube.com/watch?v=kocJ6pn9kEc5. DrupalCon Denver 2012: DRUPAL 8 MEETS SYMFONY2
https://www.youtube.com/watch?v=Gr71z_WoejM6. Symfony en Drupal 8
http://symfony.com/doc/current/components/event_dispatcher/introduction.html#introduction
7. Unravelling the Drupal 8 Plugin System https://drupalize.me/blog/201409/unravelling-drupal-8-plugin-system
8. Drupal 8 Plugin System https://www.youtube.com/watch?v=2o5uY-iOoMo9. PSR-4 http://www.php-fig.org/psr/psr-4/10. Namespaces http://php.net/manual/en/language.namespaces.php
References and Resources
Recommended