Last active
March 3, 2017 02:53
-
-
Save brooke-heaton/c0a837b116c5f249b480cd529201ee61 to your computer and use it in GitHub Desktop.
Check if a node exists by node title using Entity Field Query (EFQ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? php | |
/** | |
* This Drupal 7 helper function can look up if a node exists and is useful | |
* if adding nodes in a postImport() method on a migration or | |
* if needing to avoid duplicates or relate nodes. | |
*/ | |
public function checkNodeExistsByTitle($title) { | |
$query = new EntityFieldQuery(); | |
$entities = $query->entityCondition('entity_type', 'node') | |
->propertyCondition('type', 'topic') | |
->propertyCondition('title', $title) | |
->range(0, 1) | |
->execute(); | |
return $entities; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment