Tuesday, July 25, 2017

Drupal 8 note

Drupal 8 note

Modules

Devel
https://www.drupal.org/project/devel

Examples for Developers
https://www.drupal.org/project/examples

Drush
https://www.drupal.org/project/drush

Drupal Console
https://drupalconsole.com/
===
# svn propedit svn:ignore /www/drupal8_public/sites

sites.php
*.com
*.ca
*.cn
*.local
===
# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer

# composer self-update
# composer update
===
Install Drupal 8

# DRUPAL_VERSION=8.2.4; export DRUPAL_VERSION
# DRUPAL_MD5=288aa9978b5027e26f20df93b6295f6c; export DRUPAL_MD5
# curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz \
&& echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c - \
&& tar -xz --strip-components=1 -f drupal.tar.gz \
&& rm drupal.tar.gz \
&& chown -R www-data:www-data sites modules themes

# unset DRUPAL_VERSION
# unset DRUPAL_MD5
# env
===
Drush

# wget http://files.drush.org/drush.phar
# php drush.phar core-status
# chmod +x drush.phar
# mv drush.phar /usr/local/bin/drush
# chown root:wheel /usr/local/bin/drush

# drush help

# drush pm-download drupal-8 --select --destination=/www/drupal8 --drupal-project-rename=drupal8
# cd example
# mkdir modules/contrib
# mkdir modules/custom

# drush site-install minimal --account-mail=admin@example.com --account-name=admin --account-pass=admin --site-mail=admin@example.com --site-name=MySiteName --sites-subdir=mytest.local --db-url='mysql://[db_user]:[db_pass]@localhost/[db_name]'

# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local core-status
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-releases
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-projectinfo
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-info

# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-refresh
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-updatestatus
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-updatecode
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local updatedb-status
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local updatedb

# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-download devel --destination=modules/contrib
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-projectinfo devel
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-info devel
# drush --root=/www/test_dru8/example --uri=simplestore.cent-exp.local pm-enable devel

# drush --root=/www/drupal-8.0.5 --uri=simplestore.cent-exp.local cache-rebuild

# drush --root=/www/drupal-8.0.5 --uri=simplestore.cent-exp.local php-script test.php
# drush --root=/www/drupal-8.0.5 --uri=simplestore.cent-exp.local --debug --verbose php-script test.php
===
# drupal init --override
# drupal check

# drupal list
# drupal self-update

# drupal generate:module
===
Disable Drupal 8 caching during development

# cp sites/example.settings.local.php sites/simplestore.cent-exp.local/settings.local.php

Uncomment these lines:

# vim sites/simplestore.cent-exp.local/settings.php

if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}

Uncomment these lines in settings.local.php to Disable the render cache and Disable Dynamic Page Cache:

# vim sites/simplestore.cent-exp.local/settings.local.php

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

Open development.services.yml in the sites folder and add the following block (to disable twig cache):

# vim sites/development.services.yml

parameters:
twig.config:
debug : true
auto_reload: true
cache: false

Afterwards you have to rebuild the Drupal cache. Otherwise your website will encounter an unexpected error on page reload. This can be done by visiting the following URL from your Drupal 8 website:
http://yoursite/core/rebuild.php

https://www.drupal.org/node/2598914

===
Drupal Console - a CLI tool to generate boilerplate code, interact and debug Drupal 8.
https://drupalconsole.com/

Evaluate Drupal projects online
http://simplytest.me/project/examples/8.x-1.x

===
Generates a token based on $value, the user session, and the private key:
\Drupal::csrfToken()->get()
\Drupal::csrfToken()->validate()

===
1. find the proper way to deal with database query error during form_submit try .. catch (rollback)

2. db_transaction

https://api.drupal.org/api/drupal/core%21includes%21database.inc/function/db_transaction/8
http://dcycleproject.org/blog/27/dont-perform-logic-your-hookformsubmit-use-api

===
vim *.yml src/*/*.php templates/*.twig css/*.css js/*.js
===
$outArr = [];
$sql = "SELECT name FROM {variable} WHERE name LIKE :name";
$arg = [
':name' => db_like('csm_node_temp_') . '%',
];

foreach (db_query($sql, $arg) as $obj) {
$outArr[] = $obj->name;
}
===
Goodbye Drush Make, Hello Composer!
https://www.lullabot.com/articles/goodbye-drush-make-hello-composer
===
files/config_*/sync

This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync. For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config
===
Working With Twig Templates

https://www.drupal.org/node/2186401
https://www.drupal.org/node/2354645

No comments: