diff --git a/README.txt b/README.txt index ed048e4..b1be808 100644 --- a/README.txt +++ b/README.txt @@ -11,6 +11,11 @@ entity CRUD controller, which helps simplifying the creation of new entity types This is an API module. You only need to enable it if a module depends on it or you are interested in using it for development. +If you've the features (https://drupal.org/project/features) module enabled you +can optimize the performance by setting the variable features_rebuild_on_flush +to FALSE. This avoids that flushing the cache triggers the entity rebuild +process. Instead this process will be triggered whenever features are rebuilt. + This README is for interested developers. If you are not interested in developing, you may stop reading now. diff --git a/entity.features.inc b/entity.features.inc index e266aaf..73626c4 100644 --- a/entity.features.inc +++ b/entity.features.inc @@ -7,6 +7,12 @@ /** * Returns the configured entity features controller. + * + * @param string $type + * The entity type to get the controller for. + * + * @return EntityDefaultFeaturesController + * The configured entity features controller. */ function entity_features_get_controller($type) { $static = &drupal_static(__FUNCTION__); @@ -130,6 +136,18 @@ class EntityDefaultFeaturesController { } } } + + /** + * Generates the result for hook_features_rebuild(). + * + * @see entity_features_rebuild() + * @see entity_features_post_restore() + */ + function rebuild($module = NULL) { + // We don't do the rebuild here since a whole rebuild is triggered in + // entity_features_post_restore(). + // entity_defaults_rebuild(array($this->type)); + } } /** @@ -146,6 +164,8 @@ function entity_features_api() { } /** + * Implements hook_features_export_options(). + * * Features component callback. */ function entity_features_export_options($a1, $a2 = NULL) { @@ -157,6 +177,8 @@ function entity_features_export_options($a1, $a2 = NULL) { } /** + * Implements hook_features_export(). + * * Features component callback. */ function entity_features_export($data, &$export, $module_name = '', $entity_type) { @@ -164,6 +186,8 @@ function entity_features_export($data, &$export, $module_name = '', $entity_type } /** + * Implements hook_features_export_render(). + * * Features component callback. */ function entity_features_export_render($module, $data, $export = NULL, $entity_type) { @@ -171,8 +195,32 @@ function entity_features_export_render($module, $data, $export = NULL, $entity_t } /** + * Implements hook_features_revert(). + * * Features component callback. */ function entity_features_revert($module = NULL, $entity_type) { return entity_features_get_controller($entity_type)->revert($module); } + +/** + * Implements hook_features_rebuild(). + * + * Features component callback. + */ +function entity_features_rebuild($module = NULL, $entity_type) { + return entity_features_get_controller($entity_type)->rebuild($module); +} + +/** + * Implements hook_features_post_restore(). + * + * Revert all defaults when a features rebuild is triggered - even the ones not + * handled by features itself. + */ +function entity_features_post_restore($op, $items = array()) { + if ($op == 'rebuild') { + // Use features rebuild to rebuild the features independent exports too. + entity_defaults_rebuild(); + } +} diff --git a/entity.module b/entity.module index d4a882c..e507e02 100644 --- a/entity.module +++ b/entity.module @@ -1076,7 +1076,10 @@ function entity_flush_caches() { // case of enabling or disabling modules we already rebuild defaults in // entity_modules_enabled() and entity_modules_disabled(), so we do not need // to do it again. - if (current_path() != 'admin/modules/list/confirm') { + // Also check if features has explicitly disabled rebuilding on cache flush. + // If the variable is set features is installed and will take care of the re- + // build whenever the features page is visited anyway. + if (current_path() != 'admin/modules/list/confirm' && variable_get('features_rebuild_on_flush', TRUE)) { entity_defaults_rebuild(); }