26
#DrupalMeetupIslamabad August 19 th 2015 Organized By IKONAMI www.ikonami.net

Drupal 8-Overview.pptx

Embed Size (px)

DESCRIPTION

www.ikonami.netIkonami organized a #drupalMeetup in #IslamabadDate: August 19, 2015Presentation Topic: Drupal 8 OverviewPresenter: Asghar KhanAgenda:What is Drupal 8? in a lineDrupal 8 new core modules.Modules removed from core.Drupal 8 directory Structure.Drupal 8 module development.Drupal 8 module routing systemDrupal 8 form APIDrupal 8 Plugin systemOpen Discussion:One-on-One sessions with programmers, who are facing any issue in Drupal 7 customization OR stuck in coding of modules.

Citation preview

Page 1: Drupal 8-Overview.pptx

#DrupalMeetupIslamabadAugust 19th 2015

Organized By IKONAMIwww.ikonami.net

Page 2: Drupal 8-Overview.pptx

Muhammad Asghar KhanDrupal Consultant - Ikonami

• Drupal Developer • 7 years experience in IT• Zend Certified PHP Eng.• Drupal Module contributor

Speaker

August 19, 2015 www.ikonami.net

Page 3: Drupal 8-Overview.pptx

www.ikonami.net

Agenda

• What is Drupal 8 in a line?• Drupal 8 new core modules.• Modules removed from core.• Drupal 8 directory Structure.• Drupal 8 module development.• Drupal 8 module routing system• Drupal 8 form API• Drupal 8 Plugin systemAugust 19, 2015

Page 4: Drupal 8-Overview.pptx

www.ikonami.net

What is Drupal 8 in a line?

D8 = D7 + D7 contrib modules

D8 build fairly sophisticated sites without having to install 30+ contributed modules as we did in Drupal 7.

August 19, 2015

Page 5: Drupal 8-Overview.pptx

Drupal 8 - New Core Modules

• Actions• Ban• Basic Authentication• Block Content• Breakpoint• CKEditor• Config• Config Translation • Content Translation• Datetime• Editor• Entity Reference• HAL• History• Language

• Link• Menu Link Content• Menu UI• Migrate• Migrate Drupal• Options• Quickedit• Responsive Image• Rest• Serialization• Telephone• Text• Tour• Views• Views UI

August 19, 2015 www.ikonami.net

Page 6: Drupal 8-Overview.pptx

Modules Removed from Core

• Blog• Dashboard• Menu• Open ID• Overlay

• PHP• Poll• Profile• Translation• Trigger

August 19, 2015 www.ikonami.net

Page 7: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Directory Structure

August 19, 2015

Screenshot

Page 8: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Directory Structure

1. /core - Drupal core files like script, misc, themes etc.2. /libraries - 3rd party libraries, i.e. “wysiwyg editor”3. /modules – To place contributed and custom modules4. /profile - contributed and custom profiles5. /themes - contributed and custom (sub)themes6. sites/[domain OR default]/{modules, themes} - Site

specific modules and themes can be moved into these directories to avoid them showing up on every site

7. sites/[domain OR default]/files - Files directory

August 19, 2015

Page 9: Drupal 8-Overview.pptx

www.ikonami.net

Basic Module Files

Only “.info.yml” file is required for Drupal 8.

× In Drupal 8, we don’t need “.module file”

August 19, 2015

Page 10: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - .info.yml file

Drupal 8 introduced new info file for component i.e. “.info.yml”. So all .info files are moved to .info.yml files. The new file extension is .info.yml.

This applies to Modules Themes ProfilesAugust 19, 2015

Page 11: Drupal 8-Overview.pptx

www.ikonami.net

.info.yml syntax

In .info file we used equal(=) for assigning and square brackets([]) for array. In .info.yml we will use colon(:) for assigning and start space and dash for array.For the most part, change all = to :.

For arrays (e.g. dependencies[] = node), use the following format in Drupal 8:dependencies: - node

In Drupal 7 we use ; for Comments BUT in Drupal 8 we will use # for Comments.August 19, 2015

Page 12: Drupal 8-Overview.pptx

www.ikonami.net

Modified entries in .info.yml File • New Required Element type–A new type key is now required with values that indicate the type of extension. Use module, theme or profile. For example:–type: module

• Remove files[] entries–Remove any files[] entries. Classes are now autoloaded.

• Convert configure links to route names–In Drupal 8, specify the administrative configuration link using the route name instead of the system path.

• Drupal 7–configure = admin/config/system/actions

• Drupal 8–configure: action.admin

August 19, 2015

Page 13: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 7 - Theme info

August 19, 2015

Screenshot

Page 14: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - .info.yml

August 19, 2015

Screenshot

Page 15: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Module .inf.yml

August 19, 2015

name: My test Moduletype: moduledescription: My first demo module to test my development approach.package: Web servicesversion: VERSIONcore:8.xdependencies: -rest -serialization

Page 16: Drupal 8-Overview.pptx

www.ikonami.net

Create your “First module”

Create your info file in your module directory

/modules/hello_d8/hello_d8.yml.

name: Hello D8description: Demonstrate Drupal 8 module development.type: modulecore: 8.x

August 19, 2015

Page 17: Drupal 8-Overview.pptx

www.ikonami.net

Create Menu• In drupal 8 “hook_menu” has been removed and introduced Routing-

Approach.

• Create routing file like [your_module].routing.yml

/modules/hello_d8/hello_d8.routing.yml

hello_d8.page:path: /hello-d8/pagedefaults: _controller: 'Drupal\hello_d8\Controller\HelloD8Controller::pageCallback’ _title: 'Hello Drupal 8’

Requirements: _permission: 'access content'

August 19, 2015

Page 18: Drupal 8-Overview.pptx

www.ikonami.net

Create your module controller

As Drupal 8 follows PSR-4 folder structure so you need to create your controller file under /modules/hello_d8/src/Controller/HelloD8Controller.php

<?php

namespace Drupal\hello_d8\Controller;

use Drupal\Core\Controller\ControllerBase;class HelloD8Controller extends ControllerBase { public function pageCallback () { return [ '#markup' => $this->t('Welcome Drupal 8 uesers') ]; }}

August 19, 2015

Page 19: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 Page

August 19, 2015

Screenshot

Page 20: Drupal 8-Overview.pptx

www.ikonami.net

Create your form in Drupal 8

Add your page path in hello_d8.routing.yml file./modules/hello_d8/hello_d8.routing.yml

hello_d8.config: path: /admin/config/system/hello-d8-config defaults: _form: 'Drupal\hello_d8\Form\ConfigForm' _title: 'Drupal 8 Configuration' requirements: _permission: 'configure_hello_d8'

August 19, 2015

Page 21: Drupal 8-Overview.pptx

www.ikonami.net

Create your form in Drupal 8Create your form class to build your form.<?phpnamespace Drupal\hello_d8\Form;use Drupal\Core\Form\ConfigFormBase;use Drupal\Core\Form\FormStateInterface;

class ConfigForm extends ConfigFormBase { protected function getEditableConfigNames() { return ['hello_d8.settings']; } public function getFormId() { return 'hello_d8_config'; } function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('hello_d8.settings'); $form['default_count'] = [ '#type' => 'number', '#title' => $this->t('Default count'), '#default_value' => $config->get('default_count'), ]; return parent::buildForm($form, $form_state); } public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $config = $this->config('hello_d8.settings'); $config->set('default_count', $form_state->getValue('default_count')); $config->save(); }}

August 19, 2015

Page 22: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Form Page

August 19, 2015

Screenshot

Page 23: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Plugin API

Plugins are small pieces of functionality that are swappable. Plugins that perform similar functionality are of the same plugin type.

August 19, 2015

Page 24: Drupal 8-Overview.pptx

www.ikonami.net

Drupal 8 - Block CodeCreate your plugin class /modules/hello_d8/src/Plugin/Block/HelloD8Block.php

<?phpnamespace Drupal\hello_d8\Plugin\Block;use Drupal\Core\Block\BlockBase;/** * Create hello_d8 block. * @Block( * id = "hello_d8_block", * admin_label = @Translation("Hello Drupal 8"), * category = @Translation("System") * ) * */class HelloD8Block extends BlockBase { public function build() { return [ '#markup' => $this->t('Hello Drupal 8 block.') ]; }}

August 19, 2015

Page 25: Drupal 8-Overview.pptx

www.ikonami.net

Your Block

August 19, 2015

Page 26: Drupal 8-Overview.pptx

Thank You

[email protected]