Skip to content

Instantly share code, notes, and snippets.

@vishwac09
Created September 22, 2022 17:59
Show Gist options
  • Save vishwac09/efee8587537e83507396465ccfc8ec4b to your computer and use it in GitHub Desktop.
Save vishwac09/efee8587537e83507396465ccfc8ec4b to your computer and use it in GitHub Desktop.
Using the Entity Convert Library
<?php
use Drupal\node\Entity\Node;
// Include the library.
use DrupalUtils\EntityConvert\EntityConvert;
// Load instance of node
$node = Node::load(1);
// Creating a new Instance.
$entityConvert = new EntityConvert();
// Pass on the Node object to get the parsed value as an array.
$parsedNode = $entityConvert->toArray($node, false);
// Pass on the Node object to get the parsed value as an object.
$parsedNode = $entityConvert->toObject($node, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment