function node_gallery_api_get_relationship_type in Node Gallery 7
Fetches a gallery-to-image relationship from the database.
If one of either $gallery_type or $item_type are supplied, this function returns a single relationship. If neither are specified, it returns all relationships, keyed by the gallery content type. If both are supplied, $item_type will be ignored.
Parameters
string $gallery_type: (optional) The content type of the gallery in the relationship. If this is an int, we'll use that as the rid. Defaults to NULL.
string $item_type: (optional) The content type of the image in the relationship. Defaults to NULL.
Return value
array An associative array containing:
- rid: An integer representing the rid column in the database.
- gallery_type: A string that is the content type of the gallery.
- item_type: A string that is the content type of the image.
- filefield_name: The name of the imagefield for the image.
- settings: An associative array of settings for the relationship.
24 calls to node_gallery_api_get_relationship_type()
- NodeGalleryBehaviorHandler::NodeGalleryRelationshipCrud in plugins/
entityreference/ behavior/ NodeGalleryBehaviorHandler.class.php - Create, update or delete Node Gallery relationships based on field values.
- NodeGallerySelectionHandler::buildEntityFieldQuery in plugins/
entityreference/ selection/ NodeGallerySelectionHandler.class.php - Build an EntityFieldQuery to get referencable entities.
- NodeGallerySelectionHandler::settingsForm in plugins/
entityreference/ selection/ NodeGallerySelectionHandler.class.php - Override settings form().
- node_gallery_api_create_item_from_file in ./
node_gallery_api.pages.inc - Create item from file. Form Plupload.
- node_gallery_api_create_new_gallery_submit in ./
node_gallery_api.module - If the user selected the option to create a new gallery, create a stub gallery, assign the images to that gallery, and redirect them to the gallery edit form.
File
- ./
node_gallery_api.inc, line 80 - Node Gallery API function
Code
function node_gallery_api_get_relationship_type($gallery_type = NULL, $item_type = NULL, $id = NULL, $reset = FALSE) {
$relationship_types =& drupal_static(__FUNCTION__);
if (!isset($relationship_types) || $reset) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node_gallery_relationship_type');
$entities = $query
->execute();
if (!empty($entities['node_gallery_relationship_type'])) {
$relationship_types = entity_load('node_gallery_relationship_type', array_keys($entities['node_gallery_relationship_type']));
}
}
if (empty($relationship_types)) {
return NULL;
}
elseif (empty($gallery_type) && empty($item_type) && empty($id)) {
return $relationship_types;
}
$filtered_types = $relationship_types;
foreach ($filtered_types as $i => $type) {
if (!empty($id) && $i != $id) {
unset($filtered_types[$i]);
}
if (!empty($gallery_type) && !in_array($gallery_type, $type->settings['relationship_type']['gallery_types'])) {
unset($filtered_types[$i]);
}
if (!empty($item_type) && !in_array($item_type, $type->settings['relationship_type']['item_types'])) {
unset($filtered_types[$i]);
}
}
if (empty($filtered_types)) {
return NULL;
}
else {
return array_shift($filtered_types);
}
}