Example #1
0
function materialize_ajax_settings_save($form, $form_state)
{
    $config = config('materialize.settings');
    $theme = $form_state['build_info']['args'][0];
    $theme_settings = config_get('theme_' . $theme . '_settings', array());
    $trigger = $form_state['triggering_element']['#name'];
    $theme_settings[$trigger] = $form_state['input'][$trigger];
    if (empty($theme_settings[$trigger])) {
        $theme_settings[$trigger] = 0;
    }
    config_set('theme_' . $theme . '_settings', $theme_settings);
    backdrop_set_message("configuration saved.");
}
/**
 * Perform necessary actions after modules are enabled.
 *
 * This function differs from hook_enable() in that it gives all other modules a
 * chance to perform actions when modules are enabled, whereas hook_enable() is
 * only called on the module actually being enabled. See module_enable() for a
 * detailed description of the order in which install and enable hooks are
 * invoked.
 *
 * @param $modules
 *   An array of the modules that were enabled.
 *
 * @see hook_enable()
 * @see hook_modules_installed()
 * @see module_enable()
 */
function hook_modules_enabled($modules)
{
    if (in_array('lousy_module', $modules)) {
        backdrop_set_message(t('mymodule is not compatible with lousy_module'), 'error');
        mymodule_disable_functionality();
    }
}
Example #3
0
/**
 * The user just logged in.
 *
 * @param $edit
 *   The array of form values submitted by the user.
 * @param $account
 *   The user object on which the operation was just performed.
 */
function hook_user_login(&$edit, $account)
{
    $config = config('system.date');
    // If the user has a NULL time zone, notify them to set a time zone.
    if (!$account->timezone && $config->get('user_configurable_timezones') && $config->get('user_empty_timezone_message')) {
        backdrop_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/{$account->uid}/edit", array('query' => backdrop_get_destination(), 'fragment' => 'edit-timezone')))));
    }
}
 if (isset($_SESSION['authorize_operation']['page_title'])) {
     backdrop_set_title($_SESSION['authorize_operation']['page_title']);
 } else {
     backdrop_set_title(t('Authorize file system changes'));
 }
 // See if we've run the operation and need to display a report.
 if (isset($_SESSION['authorize_results']) && ($results = $_SESSION['authorize_results'])) {
     // Clear the session out.
     unset($_SESSION['authorize_results']);
     unset($_SESSION['authorize_operation']);
     unset($_SESSION['authorize_filetransfer_info']);
     if (!empty($results['page_title'])) {
         backdrop_set_title($results['page_title']);
     }
     if (!empty($results['page_message'])) {
         backdrop_set_message($results['page_message']['message'], $results['page_message']['type']);
     }
     $output = theme('authorize_report', array('messages' => $results['messages']));
     $links = array();
     if (is_array($results['tasks'])) {
         $links += $results['tasks'];
     } else {
         $links = array_merge($links, array(l(t('Administration pages'), 'admin'), l(t('Front page'), '<front>')));
     }
     $output .= theme('item_list', array('items' => $links, 'title' => t('Next steps')));
 } elseif (isset($_GET['batch'])) {
     $output = _batch_page();
 } else {
     if (empty($_SESSION['authorize_operation']) || empty($_SESSION['authorize_filetransfer_info'])) {
         $output = t('It appears you have reached this page in error.');
     } elseif (!($batch = batch_get())) {
Example #5
0
/**
 * Respond to node type creation.
 *
 * This hook is invoked from node_type_save() after the node type is added to
 * the database.
 *
 * @param $info
 *   The node type object that is being created.
 */
function hook_node_type_insert($info)
{
    backdrop_set_message(t('You have just created a content type with a machine name %type.', array('%type' => $info->type)));
}
Example #6
0
/**
 * Form constructor for the list of available database module updates.
 */
function update_script_selection_form($form, &$form_state)
{
    $count = 0;
    $incompatible_count = 0;
    $form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE);
    // Ensure system.module's updates appear first.
    $form['start']['system'] = array();
    $updates = update_get_update_list();
    $starting_updates = array();
    $incompatible_updates_exist = FALSE;
    foreach ($updates as $module => $update) {
        if (!isset($update['start'])) {
            $form['start'][$module] = array('#type' => 'item', '#title' => $module . ' module', '#markup' => $update['warning'], '#prefix' => '<div class="messages warning">', '#suffix' => '</div>');
            $incompatible_updates_exist = TRUE;
            continue;
        }
        if (!empty($update['pending'])) {
            $starting_updates[$module] = $update['start'];
            $form['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']);
            $form['start'][$module . '_updates'] = array('#theme' => 'item_list', '#items' => $update['pending'], '#title' => $module . ' module');
        }
        if (isset($update['pending'])) {
            $count = $count + count($update['pending']);
        }
    }
    // Find and label any incompatible updates.
    foreach (update_resolve_dependencies($starting_updates) as $function => $data) {
        if (!$data['allowed']) {
            $incompatible_updates_exist = TRUE;
            $incompatible_count++;
            $module_update_key = $data['module'] . '_updates';
            if (isset($form['start'][$module_update_key]['#items'][$data['number']])) {
                $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: <em>' . implode(', ', $data['missing_dependencies']) . '</em>' : "This update will be skipped due to an error in the module's code.";
                $form['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
            }
            // Move the module containing this update to the top of the list.
            $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start'];
        }
    }
    // Warn the user if any updates were incompatible.
    if ($incompatible_updates_exist) {
        backdrop_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning');
    }
    if (empty($count)) {
        backdrop_set_message(t('No pending updates.'));
        unset($form);
        $form['links'] = array('#theme' => 'links', '#links' => update_helpful_links());
        // No updates to run, so caches won't get flushed later.  Clear them now.
        backdrop_flush_all_caches();
    } else {
        $form['help'] = array('#markup' => '<p>Updates have been found that need to be applied. You may review the updates below before executing them.</p>', '#weight' => -5);
        if ($incompatible_count) {
            $form['start']['#title'] = format_plural($count, '1 pending update (@number_applied to be applied, @number_incompatible skipped)', '@count pending updates (@number_applied to be applied, @number_incompatible skipped)', array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count));
        } else {
            $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates');
        }
        $form['actions'] = array('#type' => 'actions');
        $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates');
    }
    return $form;
}
/**
 * This hook is called right after the execute process. The query has
 * been executed, but the pre_render() phase has not yet happened for
 * handlers.
 *
 * Adding output to the view can be accomplished by placing text on
 * $view->attachment_before and $view->attachment_after. Altering the
 * content can be achieved by editing the items of $view->result.
 * @param $view
 *   The view object about to be processed.
 */
function hook_views_post_execute(&$view)
{
    // If there are more than 100 results, show a message that encourages the user
    // to change the filter settings.
    // (This action could be performed later in the execution process, but not
    // earlier.)
    if ($view->total_rows > 100) {
        backdrop_set_message(t('You have more than 100 hits. Use the filter settings to narrow down your list.'));
    }
}
/**
 * Respond to comment deletion.
 *
 * This hook is invoked from comment_delete_multiple() after
 * field_attach_delete() has called and after the comment has been removed from
 * the database.
 *
 * @param $comment
 *   The comment object for the comment that has been deleted.
 *
 * @see hook_comment_predelete()
 * @see comment_delete_multiple()
 * @see entity_delete_multiple()
 */
function hook_comment_delete($comment)
{
    backdrop_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject)));
}
Example #9
0
/**
 * Complete a batch process.
 *
 * Callback for batch_set().
 *
 * This callback may be specified in a batch to perform clean-up operations, or
 * to analyze the results of the batch operations.
 *
 * @param $success
 *   A boolean indicating whether the batch has completed successfully.
 * @param $results
 *   The value set in $context['results'] by callback_batch_operation().
 * @param $operations
 *   If $success is FALSE, contains the operations that remained unprocessed.
 */
function callback_batch_finished($success, $results, $operations)
{
    if ($success) {
        // Here we do something meaningful with the results.
        $message = t("!count items were processed.", array('!count' => count($results)));
        $message .= theme('item_list', array('items' => $results));
        backdrop_set_message($message);
    } else {
        // An error occurred.
        // $operations contains the operations that remained unprocessed.
        $error_operation = reset($operations);
        $message = t('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)));
        backdrop_set_message($message, 'error');
    }
}