LoginSignup
3
5

More than 5 years have passed since last update.

Drupal 8 入門の入門 (環境設定他)

Last updated at Posted at 2016-05-05

WordPress他のメジャーなCMSを利用した経験のない人間が、Drupalでどうにかしなければならなくなった(ている)時のメモです。(遺言として書き残します。)

参考になりそうなサイト

開発(テーマの?)をする環境に関するいろいろ

インストール

テンプレートでのデバッグを有効にする

Drupal Console

  • Drupal Consoleを使用すると、コマンド一発で開発/本番のモード切替ができて楽
  • その他にもいろいろできるっぽい。
  • 何らかの原因でDrupal Consoleのインストールがうまくいかなくても、twigでのデバッグはservice.ymlの書き換え、その他については管理機能から設定できる(と思う)
    # Run this in your terminal to get the latest Console version:
    curl https://drupalconsole.com/installer -L -o drupal.phar

    # Accessing from anywhere on your system:
    mv drupal.phar /usr/local/bin/drupal

    # Apply executable permissions on the downloaded file:
    chmod +x /usr/local/bin/drupal

    # Copy configuration files to user home directory:
    drupal init --override

    --------------------ここまででOK---

    # Check and validate system requirements
    drupal check

    # Lists all available commands:
    drupal list

    # Update DrupalConsole to the latest version:
    drupal self-update

サイトのモード(開発/本番)切替

Developmentモードに変更した場合

[maryco@centos6 drupal]$ drupal site:mode dev
 Configuration name: system.performance
 ------------------------- ---------------- ----------------
  Configuration key         Original Value   Override Value
 ------------------------- ---------------- ----------------
  cache.page.use_internal   true             false
  css.preprocess            true             false
  css.gzip                  true             false
  js.preprocess             true             false
  js.gzip                   true             false
  response.gzip             true             false
 ------------------------- ---------------- ----------------

 Configuration name: views.settings
 -------------------------------- ---------------- ----------------
  Configuration key                Original Value   Override Value
 -------------------------------- ---------------- ----------------
  ui.show.sql_query.enabled        false            true
  ui.show.performance_statistics   false            true
 -------------------------------- ---------------- ----------------

 Configuration name: system.logging
 ------------------- ---------------- ----------------
  Configuration key   Original Value   Override Value
 ------------------- ---------------- ----------------
  error_level         none             all
 ------------------- ---------------- ----------------


 Services files /var/www/apps/drupal/drupal/sites/default/services.yml was overwritten


 New services settings
 ------------- ------------- -------
  Service       Parameter     Value
 ------------- ------------- -------
  twig.config   auto_reload   true
  twig.config   cache         true
  twig.config   debug         true
 ------------- ------------- -------

 // cache:rebuild

 Rebuilding cache(s), wait a moment please.


 [OK] Done clearing cache(s).

Productionモードに変更した場合

[maryco@centos6 drupal]$ drupal site:mode prod
 Configuration name: system.performance
 ------------------------- ---------------- ----------------
  Configuration key         Original Value   Override Value
 ------------------------- ---------------- ----------------
  cache.page.use_internal   false            true
  css.preprocess            true             true
  css.gzip                  false            true
  js.preprocess             true             true
  js.gzip                   false            true
  response.gzip             false            true
 ------------------------- ---------------- ----------------

 Configuration name: views.settings
 -------------------------------- ---------------- ----------------
  Configuration key                Original Value   Override Value
 -------------------------------- ---------------- ----------------
  ui.show.sql_query.enabled        true             false
  ui.show.performance_statistics   true             false
 -------------------------------- ---------------- ----------------

 Configuration name: system.logging
 ------------------- ---------------- ----------------
  Configuration key   Original Value   Override Value
 ------------------- ---------------- ----------------
  error_level         all              none
 ------------------- ---------------- ----------------


 Services files /var/www/apps/drupal/drupal/sites/default/services.yml was overwritten


 New services settings
 ------------- ------------- -------
  Service       Parameter     Value
 ------------- ------------- -------
  twig.config   auto_reload   false
  twig.config   cache         true
  twig.config   debug         false
 ------------- ------------- -------

 // cache:rebuild

 Rebuilding cache(s), wait a moment please.


 [OK] Done clearing cache(s).

ルートの情報を確認する

引数なしだとルート名とパスの一覧が出力される

$ drupal router:debug

  • view.author_contents_page.page_1」については、管理機能で作成したView(ページ)。
  • Viewの名称「Author Contents Page」がルート名として登録されている。
  • URLは「/articles/author/%author_id」としている。(=パラメータに名前を付けられる)
Route name                                            Path
・
view.frontpage.page_1                                 /node
entity.node.canonical                                 /node/{node}
entity.taxonomy_term.canonical                        /taxonomy/term/{taxonomy_term}
view.author_contents_page.page_1                      /articles/author/{author_id}
・

個々のルートについての詳細情報を見る(先ほどのViewの場合)

$ drupal router:debug view.author_contents_page.page_1

 Route                           view.author_contents_page.page_1
 Path                            /articles/author/{author_id}
 Defaults
  _controller                    Drupal\views\Routing\ViewPageController::handle
  _title                         同じ記者の記事一覧
  view_id                        author_contents_page
  display_id                     page_1
  _view_display_show_admin_links 1
 Options
  compiler_class                 \Drupal\Core\Routing\RouteCompiler
  _view_argument_map             arg_0: author_id

  _view_display_plugin_id        page
  _view_display_plugin_class     Drupal\views\Plugin\views\display\Page
  _view_display_show_admin_links 1
  returns_response
  _route_filters                 content_type_header_matcher

  _route_enhancers               route_enhancer.param_conversion

  _access_checks                 access_check.permission

個々のルートについての詳細情報を見る(ノードの場合)

$ drupal router:debug entity.node.canonical

 Route             entity.node.canonical
 Path              /node/{node}
 Defaults
  _controller      \Drupal\node\Controller\NodeViewController::view
  _title_callback  \Drupal\node\Controller\NodeViewController::title
 Options
  compiler_class   \Drupal\Core\Routing\RouteCompiler
  parameters       node:
                     type: 'entity:node'
                     converter: paramconverter.entity

  _route_filters   content_type_header_matcher

  _route_enhancers route_enhancer.param_conversion

  _access_checks   access_check.entity

サイトをメンテナンスモードに切り替える

$ drupal site:maintenance on -v

 Operating in maintenance mode on
 // cache:rebuild

 Rebuilding cache(s), wait a moment please.


 [OK] Done clearing cache(s).

【注意】メンテナンスモードに切り替わりますが、テンプレートの準備は忘れずに!
screenshot.1462425046.png

PhpStormの設定

ちゃんと設計されたPHPではVimはさすがにキツいのでIDEに迷わず乗り換え。

  • 元Eclipse利用者で.vimrcを晒せるほどvimマスターではないのでキーマップのIdeaVIMは無効化
  • 下記のプラグインを追加

Drupal Symfony2 Bridge
EditorConfig

参照:Drupal Development using PhpStorm

その他設定に関する調査メモ

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5