You are here

function _views_bulk_operations_get_operations in Views Bulk Operations (VBO) 5

Description Fetch available operations.

Parameters

(string) $filter: 'refresh' - build operations data from scratch 'all' - return stored data for all available operations 'enabled' - return stored data for operations that are enabled only 'disabled' - return stored data for operations that are disabled only

(string) $vid: The ID of the view whose operations we are selecting

Return value

(array) Array whose keys contain the name of the callback and values contain additional information about that callback. Format of array is as follows:

array( 'callback' => array( label, // human readable name of operation callback arguments, // node operations callbacks enabled, // whether we show this operation in our views configurable, // actions operations only type // action or node operation ) )

5 calls to _views_bulk_operations_get_operations()
views_bulk_operations_form in ./views_bulk_operations.module
views_bulk_operations_form_submit in ./views_bulk_operations.module
views_bulk_operations_form_validate in ./views_bulk_operations.module
views_bulk_operations_view_settings in ./views_bulk_operations.module
Bulk operations config page for a given view.
views_bulk_operations_view_settings_submit in ./views_bulk_operations.module

File

./views_bulk_operations.module, line 858
Allow bulk node operations directly within views.

Code

function _views_bulk_operations_get_operations($filter, $vid) {
  if (module_exists('actions')) {
    views_bulk_operations_action_info();

    // make sure our actions are loaded
  }
  $stored_operations = _views_bulk_operations_get($vid, array());
  switch ($filter) {
    case 'all':
      if (empty($store_operations)) {
        return _views_bulk_operations_get_operations('refresh', $vid);
      }
      return $stored_operations;
    case 'refresh':
      $new_operations = array();

      // Core 'node operations'
      $node_operations = module_invoke_all('node_operations');
      foreach ($node_operations as $operation) {

        // some node operations do not provide a valid callback
        // (such as the 'delete' operation)
        if (empty($operation['callback'])) {
          continue;
        }
        $key = md5($operation['callback'] . $operation['label']);
        $enabled = isset($stored_operations[$key]['enabled']) ? $stored_operations[$key]['enabled'] : VIEWS_BULK_OPS_DEFAULT_OPERATION_ENABLE;
        $new_operations[$key] = array(
          'label' => $operation['label'],
          'callback' => $operation['callback'],
          'callback arguments' => $operation['callback arguments'],
          'enabled' => $enabled,
          'configurable' => false,
          'type' => 'node',
        );
      }

      // Actions Operations (if module available)
      if (module_exists('actions')) {
        $action_operations = actions_list() + _views_bulk_operations_get_custom_actions();
        foreach ($action_operations as $callback => $values) {

          // we do not want to include ALL actions as some are not 'node
          // operations'-like. TODO: Depending on how actions work, we may want
          // to allow admin to turn on/off action types. Don't know enough about
          // actions to determine that right now, so limiting to types I know we
          // want.
          foreach (array(
            'node',
            'workflow',
            'email',
          ) as $type) {
            if (0 != strcasecmp($type, $values['type'])) {
              continue;
            }
            $key = md5($callback . $values['description']);
            $enabled = isset($stored_operations[$key]['enabled']) ? $stored_operations[$key]['enabled'] : VIEWS_BULK_OPS_DEFAULT_OPERATION_ENABLE;
            $new_operations[$key] = array(
              'label' => $values['description'],
              'callback' => $callback,
              'callback arguments' => $values['parameters'],
              'enabled' => $enabled,
              'configurable' => $values['configurable'],
              'type' => 'action',
            );
            break;

            // out of inner, type-searching loop
          }
        }
      }
      _views_bulk_operations_set($vid, $new_operations);
      return $new_operations;
    case 'enabled':
    case 'disabled':
      $filtered_operations = array();
      $state = $filter == 'enabled' ? 1 : 0;
      foreach ($stored_operations as $operation => $values) {
        if ($values['enabled'] == $state) {
          $filtered_operations[$operation] = $values;
        }
      }
      return $filtered_operations;
  }
}