How to regenerate images when you do a style change, and images don't reflect them
Introduction There might be a situation when you are doing some changes in the…
March 18, 2018
Being a drupal user from last around 5 years, I used to know small codes for drupal. These codes helps in many ways, in templating, or in writing custom automation etc.
$query = db_select( 'node', 'n' ); $query ->condition( 'n.type', '' ) ->fields('n', array('nid')); $result = $query ->execute() ->fetchAll(); foreach( $result as $row ) { print_r($row); }
$query = db_select( 'node', 'n' ); $query ->condition( 'n.type', '' ) ->fields('n', array('nid', 'title')); $result = $query ->execute() ->fetchAll(); foreach( $result as $row ) { print_r($row); }
Note: You can get all the attributes from a node by loading a node, by using php code: node_load(nid). But, it is very heavy operation. In many cases, you do not want to load complete node.
function getTitle($nid) { $query = db_select( 'node', 'n' ); $query ->condition( 'n.nid', $nid) ->fields('n', array('title')); $result = $query->execute(); return $result->fetchObject()->title; }
$contentType = 'article'; $rangeFrom = 0; $number = 4; $query = db_select('node', 'n'); $query->condition('n.status', NODE_PUBLISHED); $query->condition('n.type', $contentType); $info = $query ->fields('n', array('nid', 'title')) ->orderBy('n.changed', 'DESC') ->range($rangeFrom, $number) ->execute() ->fetchAll(); print_r($info);
Example: If my content type has a field: videoId. Find out if this content type has any node with this particular videoIdas value.
$query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'my_content_type') ->propertyCondition('status', NODE_PUBLISHED) ->fieldCondition('my_field_name', 'value', 'my_required_field_value', '='); $result = $query->execute(); print_r($result);
Introduction There might be a situation when you are doing some changes in the…
For programmers, who want to write about their codes. Its often the first…
Visual Studio Code is one of the awesome developer tools by Microsoft. Let’s…
This will take backup of your passed database name, to the passed folder. It…
See the code below: The output will be 4 columns separated by comma. You can…
Introduction You have a running kubernetes setup, and have a webservice (exposed…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…