Skip to content

Instantly share code, notes, and snippets.

Drupal 8 - download and install instructions - Lando version
References:
* https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies
Navigate to the new site’s grandparent directory, ex:
$ cd ~/Sites/drupal
Download the site files to the new site dir with Composer:
@DavMorr
DavMorr / Generate number from an alphanumeric string.php
Last active July 10, 2018 14:15
Generate a number from an alphanumeric string. Has limited utility and no suggestion of identity uniqueness.
<?php
function getNumKey($str) {
$alpha = range('A', 'Z');
$chars = str_split(strtoupper($str));
foreach ($chars as $char) {
$x = (is_numeric($char)) ? $char : (array_search($char, $alpha) + 1);
$numz += $x;
// echo $x.' ';
}
return $numz;

Install Drupal 8 with Composer

There are several ways to install a Dupal 8 site instance with Composer, but the following includes the automated options that I prefer most.

$ composer create-project drupal-composer/drupal-project:8.x-dev [[[ /path/to/site/root/parent ]]] --stability dev --no-interaction

[[[ /path/to/site/root/parent ]]] = the path to the parent directory above the web/docroot of the site.

| feature | drupal-composer/drupal-project |

@DavMorr
DavMorr / Entity API implements Typed Data API - Using the API.md
Last active April 10, 2018 01:21
Entity API implements Typed Data API : Using the API - Examples

Entity API implements Typed Data API

from Entity API implements Typed Data API (drupal.org)

Using the API

Entity API defines some magic methods, like __get(), to allow for fast and easy access to field values. So using the API is very straightforward and the syntax reminds a lot of the pre Drupal 8 era.

Fetching the actual value of the image’s alternative text will be done as below:

@DavMorr
DavMorr / Drupal 8 : serialize typed data into JSON.md
Last active June 4, 2024 22:10
Drupal 8 : serialize typed data into JSON - Among other rad things that you can do via the type data api in drupal 8. the following example shows how to interact with typed data with the core Serialize service for serializing and deserializing lists of URI data types items.

Drupal 8 : serialize typed data into JSON

from: Typed Data API overview (drupal.org)

  // Serialize Typed Data into JSON.
  $listDefinition = \Drupal::typedDataManager()->createListDataDefinition('uri');
  $list = \Drupal::typedDataManager()->create($listDefinition, ['http://example.com', 'http://drupal.org']);
  $serializer = \Drupal::service('serializer');
 echo $serializer-&gt;serialize($list, 'json');
@DavMorr
DavMorr / Drupal-8-Update-8.4.x-to-8.5.1.md
Last active April 3, 2018 23:25
High level update procs for update a Drupal 8 site from v. 8.4.x to 8.5.x

This is a high level update procs for update a Drupal 8 site from Drupal v. 8.4.x to 8.5.x to pick up the critical security updates.
This does not include debugging tips if things go sideways resultant of the updates.

Create new clone or update dev site to current and backup. Be ready to restore is things go sideways. Put site in maintenace mode.

Run:

$ composer update drupal/core webflo/drupal-core-require-dev symfony/* --with-dependencies
$ drush updatedb
@DavMorr
DavMorr / XdebugOnMac-w-PHP7-n-AcquiaDevDesktop-support.md
Last active March 14, 2018 21:08
Install xdebug on Mac and add Acquia DevDesktop support

Download and extract the xdebug source code (I used xdebug-2.5.5).

$ cd xdebug-2.5.5
$ /Applications/DevDesktop/php7_0/bin/phpize

and now the step that was the one that caused most grief figuring out...

$ ./configure --with-php-config=/Applications/DevDesktop/php7_0/bin/php-config CC="gcc -arch i386" CXX="g++ -arch i386"
$ make
$ cp modules/xdebug.so /Applications/DevDesktop/php7_0/ext/
@DavMorr
DavMorr / behat_3.0_oob_commanands list
Created March 7, 2018 18:59
behat ~3.0 out of the box commands list
# $ vendor/bin/behat -dl
default | Given I am an anonymous user
default | Given I am not logged in
default | Given I am logged in as a user with the :role role(s)
default | Given I am logged in as a/an :role
default | Given I am logged in as a user with the :role role(s) and I have the following fields:
default | Given I am logged in as :name
default | Given I am logged in as a user with the :permissions permission(s)
default | Then I should see (the text ):text in the :rowText row
@DavMorr
DavMorr / behat.yml
Created March 7, 2018 18:58
Composer does not create the top level behat.yml file when installing behat on OS X. This is out of the box for behat ~3.0 for drupal 8.
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
@DavMorr
DavMorr / sed-to-strip-uuid-from-yaml-config-files--osx.md
Last active March 5, 2024 13:23
Drupal 8 - use sed to strip uuid line from exported config files

[Drupal 8] use sed (on OSX) to strip the uuid line from exported config files being used for module default configuration; i.e. [module_name]/config/optional|install

NOTE: this can also by bypassed in the export by using Drupal Cnnsole and including the --remove-uuid flag. Also using the --remove-config-hash flag can help prevent additional headaches.

Ex: drupal config:export --directory=”[full-path-to-location]” --tar --remove-uuid --remove-config-hash

The UUID should never be included when using when using these exported config yaml files as the default configuration pagaged with a custom module. This is suppoedly not to be a thing in the exported yaml files at some point, but until then stripping the uuid line out is a manual process which can be a pain as there can be a lot of files.

To automate this, run the following sed command in the directory containing the yaml files: