Latest Articles
Our latest news updates and insightful blog posts, designed to empower you with the knowledge and strategies you need to succeed.
Get URL by Node id Drupal 8
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();
Get or Set config value programmatically Drupal 8
Get value of variable from configuration form
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')->ge…
Get node id of current node page Drupal 10
$node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { // You can get nid and anything else you need from the node object. $nid = $node->id(); }
Get installed a POS system to improve the business and manage accurately
A small store to a large retail store is advisable to use Point of Service systems to easily customize their routine operations. It increases productivity, business, revenue, relationship with customers, and also saves time efficiently. Free POS applications can be used in simple business procedures using existing tools where advanced system is not affordable. POS is connected with multiple computers, printers, scanners at the administrator, sales counter, and many more locations. If addition…
Get field value of reference node on node twig template Drupal 8 and 9
In following example field_course_ref is a field which reference with other node, field_course_type is a field of the reference content type which is a term so we get term name
{{ node.field_course_ref.entity.field_course_type.entity.name.value }}
Get error undefined method File::url() in Drupal 9
I was trying to create a custom banner based on user uploaded image in node then I got following error in Drupal 9 but it was workiing in Drupal 8
Following code I was using
$img_url = $file->url();
Getting this error
Error: Call to undefined method Drupal\file\Entity\File::url() in theme_preprocess_page()
I found the solution its working fine in simply use createFileUrl(); instead of url();
Functions file_create_url() not working in Drupal 10
Functions file_create_url() was using to create url of images and files drupal 9 but now its not working in Drupal 10 so its deprecated now you can use code as follow to create url in Drupal 10
\Drupal::service('file_url_generator')->generateAbsoluteString($uri);
Used in Drupal 9 and before | Using Drupal 10 |
---|---|
file_create_url($uri) | \Drupal::service('file_url_generator…
|