function _onlyone_exists_nodes_content_type in Allow a content type only once (Only One) 7
Return if exists nodes of a content type in the actual language.
Parameters
string $content_type: Content type machine name.
string $language_to_check: The language to check. If the variable is not provided and the site is multilingual the actual language will be taken.
Return value
int If exists nodes return the first node nid otherwise return 0.
3 calls to _onlyone_exists_nodes_content_type()
- onlyone_form_node_form_alter in ./
onlyone.module - Implements hook_form_BASE_FORM_ID_alter().
- onlyone_node_validate in ./
onlyone.module - Implements hook_node_validate().
- onlyone_preprocess_node_add_list in ./
onlyone.module - Implements hook_preprocess_HOOK() for block content add list templates.
File
- ./
onlyone.helpers.inc, line 225 - Helper functions.
Code
function _onlyone_exists_nodes_content_type($content_type, $language_to_check = NULL) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', $content_type);
// The site is multilingual?
if (drupal_multilingual()) {
if (empty($language_to_check)) {
global $language;
$language_to_check = $language->language;
}
$query
->propertyCondition('language', $language_to_check);
}
// Executing the query.
$result = $query
->execute();
// Getting the nid.
$nid = isset($result['node']) ? key($result['node']) : 0;
return $nid;
}