Skip to main content

Working with Drupal nodes

In Drupal most content is stored in nodes, nodes are an inbuilt entity type used to store content. As a developer it is usually the case that you start by defining a number of content types which are specific to the site you're working on, these will be made up of a number of fields and settings specific to the content type you're defining. A content type is essentially just another name for a node type with each new content type your define being a new type of node that users can use to store their content. Find out more about nodes by reading some of our blog posts below...

Read some of our articles about Drupal nodes

Get the entity for a route

29th Aug 2017

In Drupal 7, we had menu_get_object() to get the object in code for whichever node, term, or whatever entity makes up the current page. But in Drupal 8, that has been replaced, and entities can usually be operated on in a generic way. If you know the type of entity you want, it's pretty simple. But I keep running into different suggestions of how to get the entity object when you don't know its type. Given that D8 allows us to deal with entities in a unified way, I thought there must be a good way! The code of core itself is usually the best place to look for examples of how to do common things.

Read more

Language lessons: What are you translating?

19th Aug 2014

Content (node-level) translation or entity (field-level) translation?

It seems an obvious question to ask, but what are you translating?

The tools exist to translate just about anything in Drupal 7*, but in many different ways, so you need to know exactly what you're translating. Language is 'a first-class citizen', in the sense that any piece of text is inherently written by someone on some language, which Drupal 7 is built to recognise. Sometimes you want to translate each & every individual piece of text (e.g. at the sentence or paragraph level). Other times you want to translate a whole page or section that is made up of multiple pieces of text.

Read more

Bulk deleting Drupal nodes of a particular content type

12th Apr 2008

The Drupal admin interface allows you to delete up to 50 nodes at one time, which is great - but there are times when you it's just not enough and you need to bulk delete many thousands of nodes.

In this example we will delete all nodes of a particular type (page), a quick way to execute the code is to create a new node, set the input format to PHP, paste the code into the node body - add a title and click submit - don't forget to delete the node when your done!

  $node_type = 'page';
  //fetch the...
Read more