You are here

public static function Contexts::enable in Hook Update Deploy Tools 7

Enables an array of contexts and checks to make sure they were enabled.

Parameters

mixed $contexts: array: of context machine names to enable. string: single context machine name to enable.

Return value

string Messsage indicating the contexts are enabled.

Throws

\HudtException Calls the update a failure, preventing it from registering the update_N.

File

src/Contexts.php, line 125

Class

Contexts
Public method for managing Contexts that verifies the changes.

Namespace

HookUpdateDeployTools

Code

public static function enable($contexts = array()) {
  try {
    $contexts = (array) $contexts;
    $t = get_t();
    $enabled = $t('enabled');
    $failed = $t('failed');
    $report = array();
    self::canSwitch();
    self::checkContextsExist($contexts, TRUE);
    foreach ($contexts as $context) {
      $context_object = context_load($context);
      ctools_export_crud_enable('context', $context_object);
    }
    $success = self::checkEnabled($contexts);
    return $success;
  } catch (\Exception $e) {
    $vars['!error'] = method_exists($e, 'logMessage') ? $e
      ->logMessage() : $e
      ->getMessage();
    if (!method_exists($e, 'logMessage')) {

      // Not logged yet, so log it.
      $message = 'contexts::enable failed because: !error';
      Message::make($message, $vars, WATCHDOG_ERROR);
    }
    throw new HudtException('Update aborted!  !error', $vars, WATCHDOG_ERROR, FALSE);
  }
}