Skip to content

PHP function for extracting fields from Drupal Nodes into a simple and clean array

Notifications You must be signed in to change notification settings

AlexanderBech/ExtractNodePro.php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

ExtractNodePro.php

PHP function for extracting fields from Drupal Nodes into a simple and clean array

Usage

Insert extractNodePro function in template.php in your Drupal theme, and call the function in your node-template.

Let's say you have these fields on a content type:

  • title
  • body
  • field_custom_thing

Then you can call the function like this: (Notice you can leave out "field_" on custom fields if you want)

$data = extractNodePro($node, array('title', 'body', 'custom_thing'));

OUTPUT: (if field_custom_thing is a text field)

$data = array(
	'title' => 'Title of the content type',
	'body' => 'Body of the content type',
	'custom_thing' => 'value of custom thing'
);

If field_custom_thing is something else, let's say an image, you would get:

$data = array(
	'title' => 'Title of the content type',
	'body' => 'Body of the content type',
	'custom_thing' => array(
		'uri' => 'public://image.jpg',
		'width' => 500,
		'height' => 500
	)
);

Default values are: value, rgb, uri, alt, width, height

What values gets extracted, can be modified like so:

$data = extractNodePro($node, array('title', 'body', 'custom_thing'), array('alt', 'value'));

About

PHP function for extracting fields from Drupal Nodes into a simple and clean array

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages