View source
<?php
define('CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED', '7.x-3.x');
function context_menu_block_enable() {
$t = get_t();
$info = drupal_parse_info_file(drupal_get_path('module', 'context') . '/context.info');
if (!isset($info['version'])) {
variable_set('context_menu_block_validate', TRUE);
drupal_set_message($t('Context does not have a version defined in its .info file. This could be because you are using a checkout of its git repository. For Context: Menu Block support, make sure you are using the @branch branch of Context.', array(
'@branch' => CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED,
)), 'warning');
}
elseif (!_context_menu_block_validate_context($info['version'])) {
drupal_set_message($t('Context: Menu Block requires Context @branch. Update Context to continue using Context: Menu Block.', array(
'@branch' => CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED,
)), 'error');
}
}
function context_menu_block_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$info = drupal_parse_info_file(drupal_get_path('module', 'context') . '/context.info');
if (!isset($info['version'])) {
variable_set('context_menu_block_validate', TRUE);
$requirements['context_menu_block'] = array(
'title' => $t('Context'),
'value' => $t('Version tag not found'),
'severity' => REQUIREMENT_WARNING,
'description' => $t('Context does not have a version defined in its .info file. This could be because you are using a checkout of its git repository. For Context: Menu Block support, make sure you are using the @branch branch of Context.', array(
'@branch' => CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED,
)),
);
return $requirements;
}
$requirements['context_menu_block'] = array(
'title' => $t('Context'),
'value' => $info['version'],
);
if (_context_menu_block_validate_context($info['version'])) {
$requirements['context_menu_block']['severity'] = REQUIREMENT_OK;
$requirements['context_menu_block']['description'] = $t('The correct version of Context is enabled for use with Context: Menu Block.');
}
else {
$requirements['context_menu_block']['severity'] = REQUIREMENT_ERROR;
$requirements['context_menu_block']['description'] = $t('The version of Context enabled is not supported with Context: Menu Block. Download and enable the @branch branch of Context.', array(
'@branch' => CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED,
));
}
}
return $requirements;
}
function context_menu_block_uninstall() {
variable_del('context_menu_block_validate');
}
function _context_menu_block_validate_context($version) {
$module_version = _context_menu_block_parse_version($version);
$supported_version = _context_menu_block_parse_version(CONTEXT_MENU_BLOCK_CONTEXT_SUPPORTED);
if ($module_version['module']['major'] == $supported_version['module']['major']) {
variable_set('context_menu_block_validate', TRUE);
return TRUE;
}
else {
variable_set('context_menu_block_validate', FALSE);
return FALSE;
}
}
function _context_menu_block_parse_version($version) {
preg_match('#(\\d+[^.]*)\\.(\\S+?)-(\\d+[^.]*)\\.(\\S+)#', $version, $matches);
$version = array(
'core' => array(
'major' => $matches[1],
'minor' => $matches[2],
),
'module' => array(
'major' => $matches[3],
'minor' => $matches[4],
),
);
return $version;
}