Joaquín Bravo (@jackbravo)
# https://getcomposer.org/download/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# https://getcomposer.org/doc/00-intro.md#globally
sudo mv composer.phar /usr/local/bin/composer
composer --version
# edit your local command line php.ini
# to memory_limit = -1
composer create-project drupal-composer/drupal-project:8.x-dev demo-drupal
# demo-drupal is the name of the folder
# if your internet is slow
wget -c https://ftp.drupal.org/files/projects/drupal-8.8.5.tar.gz
mv drupal-8.8.5 demo-drupal
# Finally
cd demo-drupal
git init
git add .
# drupal already provides a sensible .gitignore file
# by default it ignores all contrib modules and drupal core
git commit -m "Initial commit"
If you need to patch drupal core or a contrib modules
you can use
https://github.com/cweagans/composer-patches
this modifications live on the composer.json file
# in our composer.json file
"require": {
...
"drupal/console": "^1.0.2",
"drupal/core": "^8.8.0",
"drush/drush": "^9.7.1 | ^10.0.0",
"vlucas/phpdotenv": "^4.0",
...
},
./vendor/bin/drush site:install --db-url=sqlite://sites/example.com/files/.ht.sqlite
./vendor/bin/drush runserver
./vendor/bin/drush config:export
git status
git add config
git commit -m "Add site configuration"
chmod u+w web/sites/default
composer require drupal/restui
# From web UI or console...
./vendor/bin/drush pm:enable restui basic_auth
./vendor/bin/drush config:export
git status
git diff
git add composer.* config
git commit -m "Enable restuid and basic_auth module"
./vendor/bin/drush config:export
git add config
git commit -m "Enable REST GET for content"
From http://127.0.0.1:8888/admin/config/services/rest
Enable GET for "Content" with:
./vendor/bin/drupal create:nodes
# https://github.com/jakubroztocil/httpie
sudo apt-get install httpie
brew install httpie
http "http://127.0.0.1:8888/node/1?_format=json"
http 127.0.0.1:8888/node/1 _format==json
Drupal Console is another drupal CLI tool
It is mostly used for development tasks
Drush is used for more general tasks
http 127.0.0.1:8888/rest/views/articles _format==json
http -a admin:admin 127.0.0.1:8888/rest/views/articles _format==json
drupal config:export
git status
git add config
git diff --cached
git commit -m "Create /rest/views/articles view"
1. Go to Text Formats and editors
2. Enable Embed media on Basic HTML
3. Once enabled, configure it just below
4. Drag its button to the active toolbar and SAVE
5. Try it
./vendor/bin/drupal generate:module
Enter the new module name:
> Demo REST
./vendor/bin/drupal generate:plugin:rest:resource
Enter the module name [restui]:
> demo_rest
Enter the plugin rest resource name [DefaultRestResource]:
> ArticlesRestResource
Enter the plugin rest resource url:
> rest/articles
./vendor/bin/drush pm:enable demo_rest
./vendor/bin/drupal rest:enable
Rest ID [entity:action]:
> articles_rest_resource
./vendor/bin/drush cache:clear
http -a admin:admin 127.0.0.1:8888/rest/articles _format==json