Revision 582db59d
Added by Assos Assos almost 9 years ago
drupal7/includes/module.inc | ||
---|---|---|
676 | 676 |
/** |
677 | 677 |
* Determines which modules are implementing a hook. |
678 | 678 |
* |
679 |
* @param $hook |
|
679 |
* Lazy-loaded include files specified with "group" via hook_hook_info() or |
|
680 |
* hook_module_implements_alter() will be automatically included by this |
|
681 |
* function when necessary. |
|
682 |
* |
|
683 |
* @param string $hook |
|
680 | 684 |
* The name of the hook (e.g. "help" or "menu"). |
681 |
* @param $sort |
|
685 |
* @param bool $sort
|
|
682 | 686 |
* By default, modules are ordered by weight and filename, settings this option |
683 | 687 |
* to TRUE, module list will be ordered by module name. |
684 |
* @param $reset |
|
688 |
* @param bool $reset
|
|
685 | 689 |
* For internal use only: Whether to force the stored list of hook |
686 | 690 |
* implementations to be regenerated (such as after enabling a new module, |
687 | 691 |
* before processing hook_enable). |
... | ... | |
696 | 700 |
static $drupal_static_fast; |
697 | 701 |
if (!isset($drupal_static_fast)) { |
698 | 702 |
$drupal_static_fast['implementations'] = &drupal_static(__FUNCTION__); |
703 |
$drupal_static_fast['verified'] = &drupal_static(__FUNCTION__ . ':verified'); |
|
699 | 704 |
} |
700 | 705 |
$implementations = &$drupal_static_fast['implementations']; |
706 |
$verified = &$drupal_static_fast['verified']; |
|
701 | 707 |
|
702 | 708 |
// We maintain a persistent cache of hook implementations in addition to the |
703 | 709 |
// static cache to avoid looping through every module and every hook on each |
... | ... | |
711 | 717 |
// per request. |
712 | 718 |
if ($reset) { |
713 | 719 |
$implementations = array(); |
720 |
$verified = array(); |
|
714 | 721 |
cache_set('module_implements', array(), 'cache_bootstrap'); |
715 | 722 |
drupal_static_reset('module_hook_info'); |
716 | 723 |
drupal_static_reset('drupal_alter'); |
... | ... | |
719 | 726 |
} |
720 | 727 |
|
721 | 728 |
// Fetch implementations from cache. |
729 |
// This happens on the first call to module_implements(*, *, FALSE) during a |
|
730 |
// request, but also when $implementations have been reset, e.g. after |
|
731 |
// module_enable(). |
|
722 | 732 |
if (empty($implementations)) { |
723 | 733 |
$implementations = cache_get('module_implements', 'cache_bootstrap'); |
724 | 734 |
if ($implementations === FALSE) { |
... | ... | |
727 | 737 |
else { |
728 | 738 |
$implementations = $implementations->data; |
729 | 739 |
} |
740 |
// Forget all previously "verified" hooks, in case that $implementations |
|
741 |
// were cleared via drupal_static_reset('module_implements') instead of |
|
742 |
// module_implements(*, *, TRUE). |
|
743 |
$verified = array(); |
|
730 | 744 |
} |
731 | 745 |
|
732 | 746 |
if (!isset($implementations[$hook])) { |
733 | 747 |
// The hook is not cached, so ensure that whether or not it has |
734 | 748 |
// implementations, that the cache is updated at the end of the request. |
735 | 749 |
$implementations['#write_cache'] = TRUE; |
750 |
// Discover implementations for this hook. |
|
736 | 751 |
$hook_info = module_hook_info(); |
737 | 752 |
$implementations[$hook] = array(); |
738 | 753 |
$list = module_list(FALSE, FALSE, $sort); |
... | ... | |
744 | 759 |
$implementations[$hook][$module] = $include_file ? $hook_info[$hook]['group'] : FALSE; |
745 | 760 |
} |
746 | 761 |
} |
747 |
// Allow modules to change the weight of specific implementations but avoid |
|
762 |
// Allow modules to change the weight of specific implementations, but avoid
|
|
748 | 763 |
// an infinite loop. |
749 | 764 |
if ($hook != 'module_implements_alter') { |
765 |
// Remember the implementations before hook_module_implements_alter(). |
|
766 |
$implementations_before = $implementations[$hook]; |
|
750 | 767 |
drupal_alter('module_implements', $implementations[$hook], $hook); |
768 |
// Verify implementations that were added or modified. |
|
769 |
foreach (array_diff_assoc($implementations[$hook], $implementations_before) as $module => $group) { |
|
770 |
// If drupal_alter('module_implements') changed or added a $group, the |
|
771 |
// respective file needs to be included. |
|
772 |
if ($group) { |
|
773 |
module_load_include('inc', $module, "$module.$group"); |
|
774 |
} |
|
775 |
// If a new implementation was added, verify that the function exists. |
|
776 |
if (!function_exists($module . '_' . $hook)) { |
|
777 |
unset($implementations[$hook][$module]); |
|
778 |
} |
|
779 |
} |
|
751 | 780 |
} |
781 |
// Implementations for this hook are now "verified". |
|
782 |
$verified[$hook] = TRUE; |
|
752 | 783 |
} |
753 |
else { |
|
784 |
elseif (!isset($verified[$hook])) { |
|
785 |
// Implementations for this hook were in the cache, but they are not |
|
786 |
// "verified" yet. |
|
754 | 787 |
foreach ($implementations[$hook] as $module => $group) { |
755 | 788 |
// If this hook implementation is stored in a lazy-loaded file, so include |
756 | 789 |
// that file first. |
... | ... | |
769 | 802 |
$implementations['#write_cache'] = TRUE; |
770 | 803 |
} |
771 | 804 |
} |
805 |
$verified[$hook] = TRUE; |
|
772 | 806 |
} |
773 | 807 |
|
774 | 808 |
return array_keys($implementations[$hook]); |
... | ... | |
833 | 867 |
* @see module_implements() |
834 | 868 |
*/ |
835 | 869 |
function module_implements_write_cache() { |
870 |
// The list of implementations includes vital modules only before full |
|
871 |
// bootstrap, so do not write cache if we are not fully bootstrapped yet. |
|
872 |
if (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL) { |
|
873 |
return; |
|
874 |
} |
|
836 | 875 |
$implementations = &drupal_static('module_implements'); |
837 | 876 |
if (isset($implementations['#write_cache'])) { |
838 | 877 |
unset($implementations['#write_cache']); |
Also available in: Unified diff
Update Drupal core to version 7.40