function pmpapi_push_entity_ok_to_push in Public Media Platform API Integration 7
Determines if an entity should be pushed to the PMP API.
Parameters
$entity object: The drupal entity to be evaluated for push-worthiness
$type string: The type of entity being evaluated
Return value
boolean TRUE if entity can be pushed to the PMP API, FALSE if not.
4 calls to pmpapi_push_entity_ok_to_push()
- pmpapi_permissions_form_node_form_alter in pmpapi_permissions/
pmpapi_permissions.module - Implements hook_form_BASE_FORM_ID_alter().
- pmpapi_push_entity_insert in pmpapi_push/
pmpapi_push.module - Implements hook_entity_insert().
- pmpapi_push_entity_presave in pmpapi_push/
pmpapi_push.module - Implements hook_entity_presave().
- pmpapi_push_entity_update in pmpapi_push/
pmpapi_push.module - Implements hook_entity_update().
File
- pmpapi_push/
pmpapi_push.module, line 49 - Maps drupal entities to MPM profiles, and pushes them to the PMP API.
Code
function pmpapi_push_entity_ok_to_push($entity, $type) {
$uname = pmpapi_push_get_uname($entity, $type);
// Is global push flag set active?
$kill_switch = variable_get('pmpapi_push_push_active');
// Is bundle mapped to a PMP profile?
$mapped_profile = variable_get('pmpapi_push_' . $uname . '_profile');
// If an entity is "unpublished" (status = 0), then do not push
// NB: status property for file entities does not mean publish/unpublish, so we
// skip $status_on check for these.
$status_on = !isset($entity->status) || $entity->status || $type == 'file';
// Absence of a push flag, or a truthy push flag, means "push the entity"
$push_flag = TRUE;
$push_flag_field = variable_get('pmpapi_push_' . $uname . '_push_flag');
if ($push_flag_field) {
$language = isset($entity->language) ? $entity->language : LANGUAGE_NONE;
$field_items = field_get_items($type, $entity, $push_flag_field, $language);
if (!empty($field_items)) {
foreach ($field_items as $field_item) {
if (!$field_item['value']) {
// 1+ falsey value in the field means "don't push"
$push_flag = FALSE;
break;
}
}
}
else {
$push_flag = FALSE;
}
}
// Modules can implement their own tests on an entity
$hooks_ok = module_invoke_all('pmpapi_push_entity_ok_to_push', $entity, $type);
return $kill_switch && $mapped_profile && $status_on && $push_flag && !in_array(FALSE, $hooks_ok, TRUE);
}