22 September
22 September
21 September
You can get config value in any custom code using following method
Example 1
$phone = \Drupal::config('socialmedia.settings')->get('phone');
In above example "socialmedia.settings" is const which has been defined in configuration form and "phone" is variable where stored value
Will get value which have beed set through configuration form.
Example 2
$slogan = \Drupal::config('system.site…
26 August
There are several ways to get the user's name programmatically.
$uid = 1; // For example I have get detail of user ID 1 $account = \Drupal\user\Entity\User::load($uid); // pass your uid
Method 1
drupal_set_message($account->name->value);
Method 2
drupal_set_message($account->get("name")->value);
Method 3
drupal_set_message($account->getUsername());
Method 4
drupal_set_message…
13 August
$vid = 'Vocabulary machine name'; // Vocabulary machine name for example city, state etc. $terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid); foreach ($terms as $term) { $termlist[$term->tid] = $term->name; }
19 January
Sometime we face FTP connection issue with AIrtel Broadband so follow this step to resolved this issue.
Open the IP Address 192.168.1.1 in browser Login with password given by Airtel Go to Services Tab
Click on Left Menu of Firewall then Firewal menu will drop down. Click on ALG Menu under Firewall
There will be appear screen of ALG Type now you can enable FTP from the list
Now Click on Apply Change
28 December
$query = \Drupal::database()->select('node', 'n'); $query->fields('n', ['nid','type']); $query->condition('type', array('basic'), 'IN'); // Basic is content type $query->leftJoin('node__field_user_ref', 'UID', "n.nid = UID.entity_id"); // field_user_ref is entity field for user reference $query->condition('UID.field_user_ref_target_id', NULL, 'IS NOT NULL'); $pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(50); $results = $pager->…
16 December
Following code can be used to get user picture or image by loading user data in Drupal 8
$user = \Drupal\user\Entity\User::load($uid); $imgpath = $user->get('user_picture')->entity->uri->value; if(!empty($imgpath)){ $user_pic = file_create_url($picurl); }
6 December
Add this line in head
use Drupal\comment\Entity\Comment;
These are following code format which can use to add comment through custom code in Drupal 8 or 9
$values = [ 'entity_type' => 'node', // required. 'entity_id' => $nid, // required. 'field_name' => 'comment', // required. 'uid' => $uid, // required. 'comment_type' => 'comment', // required. '…
22 November
you have to use following class
Drupal\Core\Url
You can use folowing code to get URL Alias
$options = ['absolute' => TRUE]; $url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $nid], $options); $nodeurl = $url->toString();
12 November
When you create or edit a node there is some default option or attribute in Node Form so we can disable or hide through custom code by using following code in our custom module.
In my example trying to to through folrm_alter hook. Following code using hide URL Aliasing for the content type of Article.
function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == 'node_article_edit_form' || $form_id == '…
© 2023.ZedAngle. All Rights Reserved.