drupal console

16
DRUPAL CONSOLE WWW.DRUPALCONSOLE.COM Martin Hasoň 12. 11. 2015 8. setkání přátel Symfony a Drupal v Brně

Upload: martin-hason

Post on 11-Apr-2017

485 views

Category:

Software


0 download

TRANSCRIPT

DRUPAL CONSOLEWWW.DRUPALCONSOLE.COM

Martin Hasoň12. 11. 2015

8. setkání přátel Symfony a Drupal v Brně

CO JE DRUPAL CONSOLEKolekce příkazů pro generování kódu a práci s Drupal 8.Narozdíl od Drush je použita Symfony Console.Nástroj umožňující ovládat a nastavit Drupal8 bezwebového rozhraní.

Instalace$ php ­r "readfile('http://drupalconsole.com/installer');" | php$ mv console.phar /usr/local/bin/drupal$ drupal init

STAŽENÍ DRUPAL8$ drupal site:new demo

[+] Getting releases for DrupalPlease select your favorite release [8.0.0­rc3 ] 8.0.0­rc3 [8.0.0­rc2 ] 8.0.0­rc2 [8.0.0­rc1 ] 8.0.0­rc1 [8.0.0­beta16 ] 8.0.0­beta16 [8.0.0­beta15 ] 8.0.0­beta15 [8.0.0­beta14 ] 8.0.0­beta14 [8.0.0­beta13 ] 8.0.0­beta13 [8.0.0­beta12 ] 8.0.0­beta12 [8.0.0­beta11 ] 8.0.0­beta11 [8.0.0­beta10 ] 8.0.0­beta10 [8.0.0­beta9 ] 8.0.0­beta9 [8.0.0­beta7 ] 8.0.0­beta7 [8.0.0­beta6 ] 8.0.0­beta6 [8.0.0­beta4 ] 8.0.0­beta4 [8.0.0­beta3 ] 8.0.0­beta3 [8.0.0­beta2 ] 8.0.0­beta2 [8.0.0­beta1 ] 8.0.0­beta1 [8.0.0­alpha15] 8.0.0­alpha15 [8.0.0­alpha14] 8.0.0­alpha14 [8.0.x­dev ] 8.0.x­dev > 8.0.0­rc3[+] Downloading Drupal 8.0.0­rc3[+] Extracting files for Drupal 8.0.0­rc3[+] Drupal 8.0.0­rc3 was downloaded in directory demo

INSTALACE DRUPAL8$ cd demo$ drupal site:install

Select Drupal profile to be installed [Minimal ] Minimal [Standard] Standard > StandardSelect language for your Drupal installation [English]: Czechcommands.migrate.setup.migrations.questions.db­type [SQLite ] SQLite [MySQL, MariaDB, Percona Server, or equivalent] MySQL, MariaDB, Percona Server, or equivalent > MySQL, MariaDB, Percona Server, or equivalentDatabase Host [127.0.0.1]: Database Name: drupal8_demo Database User: rootDatabase Pass: Database Prefix: Database Port [3306]: Provide your Drupal site name [Drupal 8 Site Install]: Drupal8 DemoProvide your Drupal site mail [[email protected]]: Provide your Drupal administrator account name [admin]: Provide your Drupal administrator account mail [[email protected]]: Provide your Drupal administrator account password: [­] Starting Drupal 8 install process[­] Your Drupal 8 installation was completed sucessfully

PŘÍKAZY PRO DEBUGOVÁNÍ$ drupal config:debug # Výpis konfigurace$ drupal container:debug # Seznam služeb$ drupal cron:debug # Seznam modulů s úlohami pro cron$ drupal database:log:debug$ drupal migrate:debug # Seznam dostupných migrací$ drupal module:debug # Seznam dostupných modulů$ drupal multisite:debug $ drupal rest:debug # Seznam REST zdrojů$ drupal router:debug # Seznam rout$ drupal site:debug # Seznam lokálních i remote webů$ drupal update:debug$ drupal views:debug

PŘIDÁNÍ WEBROFILERU A LIŠTY$ drupal module:download webprofiler

[+] Getting releases for module webprofilerPlease select your favorite release [8.x­2.0­rc3 ] 8.x­2.0­rc3 [8.x­2.0­rc2 ] 8.x­2.0­rc2 [8.x­2.0­rc1 ] 8.x­2.0­rc1 [8.x­2.0­beta16 ] 8.x­2.0­beta16 [8.x­2.0­beta15 ] 8.x­2.0­beta15 [8.x­1.1­beta15 ] 8.x­1.1­beta15 [8.x­1.1­beta13 ] 8.x­1.1­beta13 ... > 8.x­2.0­rc3[­] Downloading module webprofiler release 8.x­2.0­rc3[­] Module webprofiler version 8.x­2.0­rc3 was downloaded successfully

$ drupal module:install webprofiler

KONFIGURACE WEBPROFILERU$ drupal config:edit webprofiler.config

purge_on_cache_clear: truestorage: profiler.database_storageexclude: "/contextual/*\r\n/toolbar/*\r\n/edit/*\r\n*.js\r\n*.css"ide_link: 'subl://open?url=file://@file&line=@line'active_toolbar_items: assets: assets blocks: blocks cache: cache config: config database: database events: events drupal_extension: drupal_extension forms: '0' http: '0' php_config: php_config performance_timing: performance_timing request: request routing: routing services: services state: state theme: theme time: time translations: translations user: user views: views mail: '0'query_sort: sourcequery_highlight: 5langcode: cs

KONFIGURACE WEBPROFILERU

DRUPAL8 TIMELINE

SYMFONY TIMELINE

UŽITEČNÉ PŘÍKAZYZměna módu aplikace

$ drupal site:mode prod$ drupal site:mode dev

Stránka údržby$ drupal site:maintenance on$ drupal site:maintenance off

Export a import nastavení$ drupal config:export$ drupal config:import

VLASTNÍ MODUL$ drupal generate:module

Welcome to the Drupal module generator

Enter the new module name: demoEnter the module machine name [demo]: Enter the module Path [/modules/custom]: Enter module description [My Awesome Module]: My Demo moduleEnter package name [Other]: Enter Drupal Core version [8.x]: Define module as feature [no]? Do you want to add a composer.json file to your module [no]? yesWould you like to add module dependencies [no]? Do you confirm generation [yes]?

Generated or updated files

Site path: /home/hason/Projekty/drupal­test/demo1 ­ modules/custom/demo/demo.info.yml2 ­ modules/custom/demo/demo.module3 ­ modules/custom/demo/composer.json

$ drupal module:install demo

VLASTNÍ CONTROLLER$ drupal generate:controller

Welcome to the Drupal Controller generator

Enter the module name: demoEnter the Controller class name [DefaultController]: HelloControllerController title: HelloEnter the action method name [index]: helloEnter the route path [demo/hello/param_1/param_2]: demo/hello/name Controller title (empty to start with code generation): Do you want to generate a unit test class [yes]? noDo you want to load services from the container [no]? yes

Type the service name or use keyup or keydown.This is optional, press enter to continue

Enter your service: twigEnter your service: Do you confirm generation [yes]?

Generated or updated files

Site path: /home/hason/Projekty/drupal­test/demo1 ­ modules/custom/demo/src/Controller/HelloController.php2 ­ modules/custom/demo/demo.routing.yml

[+] Rebuilding routes, wait a moment please[+] Done rebuilding route(s).

VLASTNÍ CONTROLLER<?php// modules/custom/demo/src/Controller/HelloController.php

namespace Drupal\demo\Controller;

use Drupal\Component\Utility\Html;use Drupal\Core\Controller\ControllerBase;use Drupal\Core\Template\TwigEnvironment;use Symfony\Component\DependencyInjection\ContainerInterface;

class HelloController extends ControllerBase

protected $twig;

public function __construct(TwigEnvironment $twig) $this­>twig = $twig;

public static function create(ContainerInterface $container) return new static( $container­>get('twig') );

public function hello($name) return [ '#type' => 'markup', '#markup' => sprintf('Hello %s!', Html::escape($name)), ];

VLASTNÍ CONTROLLER A ŠABLONA// modules/custom/demo/src/Controller/HelloController.php//...

use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;

class HelloController extends ControllerBase // ...

public function hello(Request $request, $name) return new Response( $this­>twig­>render('@demo/hello.html.twig', ['name' => $name]) ); // ...

# modules/custom/demo/templates/hello.html.twig #

Hello name !

A TO UŽ JSME V SYMFONY!

https://github.com/hasonhttps://twitter.com/@hasonmhttps://www.webuni.cz