Saturday, August 19, 2017

To create new user from Drush command

To create new user using Drush use below command from Drush

drush user-create admin --mail="person@example.com"  --password="admin"
Where
Admin is the username
mail is the email address
and Password

Remove all contents from Drupal 8

To remove all contents, taxonomies, users and other content element. I would recommend to use delete_all module. Available in Drupal 7 and Drupal 8

Tuesday, August 8, 2017

Get all terms from the vocabulary

To get all terms from the specific vocabulary use below snippets

$vid = 'name_of_vocabulary';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
 $term_data[] = array(
  "id" => $term->tid,
  "name" => $term->name
 );
}