Blog

blog-img

22 April

How to create user programatically in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$user = \Drupal\user\Entity\User::create();

// Mandatory.
$user->setPassword('password');
$user->enforceIsNew();
$user->setEmail('email');
$user->setUsername('user_name');

// Optional.
$user->set('init', 'email');
$user->set('langcode', $language);
$user->set('preferred_langcode', $language);
$user->set('preferred_admin_langcode', $language);
$user->set('setting_name', 'setting_value');
$user->addRole('rid');
$user->…
                        Read More...
                      
blog-img

21 April

Custom code to add meta tag in Drupal 7
By: admin | Published On: Tue, 04/21/2020 - 23:45

In your theme's template.php file, you could add something like **/

/** * Implements hook_preprocess_html */ 
function THEME_NAME_preprocess_html(&$vars) { 
	if (current_path() == 'my/custom/path') { 
		$description = array( 
		'#type' => 'html_tag', 
		'#tag' => 'meta', 
		'#attributes' => array( 'name' => 'description', 'content' => 'here all description goes', )
		 ); 
		 
		 drupal_add_html_head($description, 'description'); 
	} 
 }
 
Read More...
blog-img

21 April

Redirect Method in DRUPAL8
By: admin | Published On: Tue, 04/21/2020 - 23:44

Method to redirect on node id url

$url = Url::fromRoute('entity.node.canonical', ['node' => $nid]); $form_state->setRedirectUrl($url);

Method to redirect on custom url

$url = Url::fromRoute('olsys.mycustom_dashboard'); $form_state->setRedirectUrl($url);

Redirect on user view page of loggedin user

use Drupal\Core\Controller\ControllerBase; // Use this on top return $this->redirect('user.page'); // use this as your code
Read More...