Drupal 8

User login

Example of using this with a date field from a node in order to get it to format the date in the correct timezone

use Drupal\Core\Datetime\DrupalDateTime;

$date = new DrupalDateTime($mynode->field_my_date_field->value, 'UTC');
$formatted_date = \Drupal::service('date.formatter')->format($date->getTimestamp(), 'custom', 'F j, Y h:ia');

blog:

Create a new administrator account in drupal with drush

In otder to create a new user in your website using drush, you'll need to run the following commands:

$ drush user-create YourUsername --mail="your@mail.com" --password="YourPassword"

This will create a new user in the website.

In order to assign the role administrator to the user run:

$ drush user-add-role "administrator" YourUsername

Drupal 8: How to include the node id and a class in body based on the , depending on the current path

While working on a custom bootstrap subtheme in Drupal, I needed to include specific classes in the body tag.

There are two different cases that I needed to take into consideration, one for nodes and one for custom paths generated by e.g. from Views or Taxonomy.

In the first case, I needed the node id to be included as a class, and on the second I needed a class name that was based on the path.

To achieve this, I needed to edit two different files under my subtheme category. You will need to replace themename with the actual name of your theme.

blog:

Subscribe to Drupal 8