Blog

blog-img

22 April

How to add condition in views with custom field in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

If you want to add if condition in my "global custom text" field in views Drupal 8

Example 1: Check node status and put conditional link according to publish status

{% if  status  %}
   put your HTML as condition
{% endif %}

Example 2: In this example we are checking a field value is empty or not. according to value in we are showing link or status

{% if  field_final_layout_date is empty %}

put your HTML as condition

{% else…
                        Read More...
                      
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

22 April

Query according to field condition in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Code to query for getting node according to field condition in DRUPAL 8

$query = \Drupal::entityQuery('node')
  ->condition('status', NODE_PUBLISHED)
  ->condition('type', 'custom_type');
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 2);
$query->condition($and);
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 8);
$query->condition($and);
$result = $query->execute();
Read More...
blog-img

22 April

Redirect Method in DRUPAL8
By: admin | Published On: Wed, 04/22/2020 - 22:13

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 

$url = \Drupal\…
                        Read More...
                      
blog-img

22 April

Set current date in custom form element in DRUPAL8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Set current date in custom form element in DRUPAL8

Add this line at top

 use Drupal\Core\Datetime\DrupalDateTime; 

Add the following code to your form

function HOOK_form_alter(…
                        Read More...
                      
blog-img

22 April

How to add Captcha in Webform in Drupal 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

If you have already created a webform then you can follow thi step
1. Open this url /admin/structure/webform (Structure -> Webform)
2. Click on "Build" in OPERATIONS column

3. Click on "+Add element" button, there will be seen a list form element

4. You can select Captcha from available list.

Read More...
blog-img

22 April

Programatically add content to webform DRUPAL
By: admin | Published On: Wed, 04/22/2020 - 22:13
global $user;
$nid = 4; //nid is the node id of your webform.

$node = node_load($nid); 

The values to save. Take case about array indexes! (see below)

$data = array(
    '1' => array('0' => $type),
    '2' => array('0' => $method),
    '5' => array('0' => $volume),
    '6' => array('0' => $comment),
    '7' => array('0' => $phone),
    '8' => array('0' => $length)
);

$submission = (object) array(
    'nid' => $nid,
    'uid…
                        Read More...
                      
blog-img

22 April

User related methods in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Get user role of current loggedin user

$user_roles = \Drupal::currentUser()->getRoles();

Get user detail of curent loggedin user

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
user_delete(uid);

$user_roles = \Drupal::currentUser()->getRoles();
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$uid = $user->get('uid')->value;	
Read More...
blog-img

22 April

Custom code to add meta tag in Drupal 7
By: admin | Published On: Wed, 04/22/2020 - 22:13

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

22 April

Online Reputation Management
By: admin | Published On: Wed, 04/22/2020 - 22:13

Online popularity control known as Online Reputation Management Company too is a key to success in online company. Why so? It is because it removes possibility for your company to earn bad name on the world wide web and increases your good picture through advertising good material relevant to your company. Under online popularity control assistance, everything published on the world wide web about you is considerably supervised. Content which contain harmful pieces of details are hidden on… Read More...