PHP

Create a node in Drupal 8

Create a node in Drupal 8

Creating a node programmatically in Drupal 8? There is much more to it that this, but this is the start...

use \Drupal\node\Entity\Node;

$node = Node::create(['type' => 'CONTENT_TYPE']);
$node->set('title', 'YOUR TITLE');
// Simple textfield
$node->set('field_TEXT_FIELD', 'Your Text Here');
        
$node->save();

 

Add a class to l() function

Add a class to l() function

In Drupal 7, you might want to output a simple class when using the l() function to create a link

l('Link Text', 'path', array('attributes' => array('class' => 'custom-class')));