Commit 697134f7 authored by tim.plunkett's avatar tim.plunkett Committed by Spleshka

Add ability to traverse field_collection

parent 7d1ac0af
......@@ -148,6 +148,20 @@ function expire_admin_settings_form() {
'#description' => t('Expire urls of entities which are referenced from the expiring node.'),
'#default_value' => variable_get('expire_node_reference_pages', EXPIRE_NODE_REFERENCE_PAGES),
);
if (module_exists('field_collection')) {
$form['tabs']['node']['expire']['expire_node_reference_field_collection_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Traverse references attached to field collections'),
'#description' => t('Expire urls of entities which are referenced from field collections attached to the expiring node.'),
'#default_value' => variable_get('expire_node_reference_field_collection_pages', EXPIRE_NODE_REFERENCE_FC_PAGES),
'#states' => array(
'visible' => array(
':input[name="expire_node_reference_pages"]' => array('checked' => TRUE),
),
),
);
}
}
$form['tabs']['node']['expire']['expire_node_custom'] = array(
......@@ -260,6 +274,20 @@ function expire_admin_settings_form() {
'#description' => t('Expire urls of entities which are referenced from node, to which expiring comment is related.'),
'#default_value' => variable_get('expire_comment_node_reference_pages', EXPIRE_COMMENT_NODE_REFERENCE_PAGES),
);
if (module_exists('field_collection')) {
$form['tabs']['comment']['expire']['expire_comment_node_reference_field_collection_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Traverse references attached to field collections'),
'#description' => t('Expire urls of entities which are referenced from field collections attached to the expiring comment\'s node.'),
'#default_value' => variable_get('expire_comment_node_reference_field_collection_pages', EXPIRE_COMMENT_NODE_REFERENCE_FC_PAGES),
'#states' => array(
'visible' => array(
':input[name="expire_comment_node_reference_pages"]' => array('checked' => TRUE),
),
),
);
}
}
$form['tabs']['comment']['expire']['expire_comment_custom'] = array(
......@@ -345,6 +373,20 @@ function expire_admin_settings_form() {
'#description' => t('Expire urls of entities which are referenced from the expiring user profile.'),
'#default_value' => variable_get('expire_user_reference_pages', EXPIRE_USER_REFERENCE_PAGES),
);
if (module_exists('field_collection')) {
$form['tabs']['user']['expire']['expire_user_reference_field_collection_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Traverse references attached to field collections'),
'#description' => t('Expire urls of entities which are referenced from field collections attached to the expiring user.'),
'#default_value' => variable_get('expire_user_reference_field_collection_pages', EXPIRE_USER_REFERENCE_FC_PAGES),
'#states' => array(
'visible' => array(
':input[name="expire_user_reference_pages"]' => array('checked' => TRUE),
),
),
);
}
}
$form['tabs']['user']['expire']['expire_user_custom'] = array(
......@@ -657,6 +699,11 @@ function expire_node_settings_form(&$form) {
if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
$form['expire']['node_expires']['expire_node_reference_pages']['#default_value'] =
variable_get('expire_node_reference_pages_' . $node_type, EXPIRE_NODE_REFERENCE_PAGES);
if (module_exists('field_collection')) {
$form['expire']['node_expires']['expire_node_reference_field_collection_pages']['#default_value'] =
variable_get('expire_node_reference_field_collection_pages_' . $node_type, EXPIRE_NODE_REFERENCE_FC_PAGES);
}
}
$form['expire']['node_expires']['expire_node_custom']['#default_value'] =
......@@ -693,6 +740,11 @@ function expire_node_settings_form(&$form) {
if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
$form['expire']['comment_expires']['expire_comment_node_reference_pages']['#default_value'] =
variable_get('expire_comment_node_reference_pages_' . $node_type, EXPIRE_COMMENT_NODE_REFERENCE_PAGES);
if (module_exists('field_collection')) {
$form['expire']['comment_expires']['expire_comment_node_reference_field_collection_pages']['#default_value'] =
variable_get('expire_comment_node_reference_field_collection_pages_' . $node_type, EXPIRE_COMMENT_NODE_REFERENCE_FC_PAGES);
}
}
$form['expire']['comment_expires']['expire_comment_custom']['#default_value'] =
......
......@@ -55,32 +55,35 @@ define('EXPIRE_MENU_LINK_DELETE', 3);
// Debug levels.
define('EXPIRE_DEBUG_DISABLED', 0);
define('EXPIRE_DEBUG_WATCHDOG', 1);
define('EXPIRE_DEBUG_FULL', 2);
define('EXPIRE_DEBUG_FULL', 2);
// Default values for cache expiration.
define('EXPIRE_NODE_FRONT_PAGE' , FALSE);
define('EXPIRE_NODE_NODE_PAGE' , TRUE);
define('EXPIRE_NODE_TERM_PAGES' , FALSE);
define('EXPIRE_NODE_REFERENCE_PAGES' , FALSE);
define('EXPIRE_NODE_CUSTOM' , FALSE);
define('EXPIRE_COMMENT_FRONT_PAGE' , FALSE);
define('EXPIRE_COMMENT_COMMENT_PAGE' , TRUE);
define('EXPIRE_COMMENT_REFERENCE_PAGES' , FALSE);
define('EXPIRE_COMMENT_NODE_PAGE' , TRUE);
define('EXPIRE_COMMENT_NODE_TERM_PAGES' , FALSE);
define('EXPIRE_COMMENT_NODE_REFERENCE_PAGES', FALSE);
define('EXPIRE_COMMENT_CUSTOM' , FALSE);
define('EXPIRE_USER_FRONT_PAGE' , FALSE);
define('EXPIRE_USER_USER_PAGE' , TRUE);
define('EXPIRE_USER_TERM_PAGES' , FALSE);
define('EXPIRE_USER_REFERENCE_PAGES' , FALSE);
define('EXPIRE_USER_CUSTOM' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY_PAGE' , FALSE);
define('EXPIRE_VOTINGAPI_CUSTOM' , FALSE);
define('EXPIRE_FILE_FILE' , FALSE);
define('EXPIRE_FILE_FRONT_PAGE' , FALSE);
define('EXPIRE_FILE_CUSTOM' , FALSE);
define('EXPIRE_NODE_FRONT_PAGE' , FALSE);
define('EXPIRE_NODE_NODE_PAGE' , TRUE);
define('EXPIRE_NODE_TERM_PAGES' , FALSE);
define('EXPIRE_NODE_REFERENCE_PAGES' , FALSE);
define('EXPIRE_NODE_REFERENCE_FC_PAGES' , FALSE);
define('EXPIRE_NODE_CUSTOM' , FALSE);
define('EXPIRE_COMMENT_FRONT_PAGE' , FALSE);
define('EXPIRE_COMMENT_COMMENT_PAGE' , TRUE);
define('EXPIRE_COMMENT_REFERENCE_PAGES' , FALSE);
define('EXPIRE_COMMENT_NODE_PAGE' , TRUE);
define('EXPIRE_COMMENT_NODE_TERM_PAGES' , FALSE);
define('EXPIRE_COMMENT_NODE_REFERENCE_PAGES' , FALSE);
define('EXPIRE_COMMENT_NODE_REFERENCE_FC_PAGES' , FALSE);
define('EXPIRE_COMMENT_CUSTOM' , FALSE);
define('EXPIRE_USER_FRONT_PAGE' , FALSE);
define('EXPIRE_USER_USER_PAGE' , TRUE);
define('EXPIRE_USER_TERM_PAGES' , FALSE);
define('EXPIRE_USER_REFERENCE_PAGES' , FALSE);
define('EXPIRE_USER_REFERENCE_FC_PAGES' , FALSE);
define('EXPIRE_USER_CUSTOM' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY_PAGE' , FALSE);
define('EXPIRE_VOTINGAPI_CUSTOM' , FALSE);
define('EXPIRE_FILE_FILE' , FALSE);
define('EXPIRE_FILE_FRONT_PAGE' , FALSE);
define('EXPIRE_FILE_CUSTOM' , FALSE);
/**
* Implementation of hook_menu().
......
......@@ -178,16 +178,18 @@ class ExpireAPI {
/**
* Find all entity references in fields and build urls for them.
*
* @param $entity
* @param object $entity
* Entity object.
*
* @param $entity_type
* @param string $entity_type
* Type of entity.
* @param bool $traverse_field_collection
* (optional) Whether or not to traverse references from field collections
* attached to this entity. Defaults to FALSE.
*
* @return array
* Entity references' urls that should be flushed.
*/
public static function expireReferences($entity, $entity_type) {
public static function expireReferences($entity, $entity_type, $traverse_field_collection = FALSE) {
$field_references = array();
......@@ -196,11 +198,23 @@ class ExpireAPI {
// Get all fields from current entity type.
$field_instances = field_info_instances($entity_type, $bundle_name);
// Gather references across field_collections.
$field_collection_items = array();
foreach ($field_instances as $field_name => $field_instance) {
// Load information about field.
$field_info = field_info_field($field_name);
// Collect field collection items.
if ($traverse_field_collection && $field_info['type'] == 'field_collection') {
$items = field_get_items($entity_type, $entity, $field_name);
if (!empty($items) && is_array($items)) {
foreach ($items as $item) {
$field_collection_items[] = $item['value'];
}
}
}
if (in_array($field_info['type'], array('node_reference', 'user_reference', 'entityreference'))) {
if (in_array($field_info['type'], array('node_reference', 'user_reference'))) {
......@@ -256,6 +270,14 @@ class ExpireAPI {
$urls['reference-' . $field_reference['entity_type'] . '-' . $field_reference['entity_id']] = $field_entity_uri['path'];
}
// Traverse gathered field collections.
if ($field_collection_items) {
foreach (field_collection_item_load_multiple($field_collection_items) as $field_collection_item) {
$field_collection_urls = ExpireAPI::expireReferences($field_collection_item, 'field_collection_item');
$urls = array_merge($urls, $field_collection_urls);
}
}
return $urls;
}
......
......@@ -93,7 +93,8 @@ class ExpireComment implements ExpireInterface {
// Expire comment's node references.
$expire_node_references = variable_get('expire_comment_node_reference_pages' . $variable_suffix, EXPIRE_COMMENT_NODE_REFERENCE_PAGES);
if ((module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) && $expire_node_references) {
$urls = ExpireAPI::expireReferences($node, 'node');
$traverse_field_collection = module_exists('field_collection') && variable_get('expire_comment_node_reference_field_collection_pages' . $variable_suffix, EXPIRE_COMMENT_NODE_REFERENCE_FC_PAGES);
$urls = ExpireAPI::expireReferences($node, 'node', $traverse_field_collection);
$expire_urls = array_merge($expire_urls, $urls);
}
......
......@@ -67,7 +67,8 @@ class ExpireNode implements ExpireInterface {
// Expire node reference's pages.
$expire_node_references = variable_get('expire_node_reference_pages' . $variable_suffix, EXPIRE_NODE_REFERENCE_PAGES);
if ((module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) && $expire_node_references) {
$urls = ExpireAPI::expireReferences($node, 'node');
$traverse_field_collection = module_exists('field_collection') && variable_get('expire_node_reference_field_collection_pages' . $variable_suffix, EXPIRE_NODE_REFERENCE_FC_PAGES);
$urls = ExpireAPI::expireReferences($node, 'node', $traverse_field_collection);
$expire_urls = array_merge($expire_urls, $urls);
}
......
......@@ -57,7 +57,8 @@ class ExpireUser implements ExpireInterface {
// Expire user reference's pages.
$expire_references = variable_get('expire_user_reference_pages', EXPIRE_USER_REFERENCE_PAGES);
if ((module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) && $expire_references) {
$urls = ExpireAPI::expireReferences($account, 'user');
$traverse_field_collection = module_exists('field_collection') && variable_get('expire_user_reference_field_collection_pages', EXPIRE_USER_REFERENCE_FC_PAGES);
$urls = ExpireAPI::expireReferences($account, 'user', $traverse_field_collection);
$expire_urls = array_merge($expire_urls, $urls);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment