You are here

function alpha_pagination_process_views_handler in Views Alpha Pagination 7.2

Processes a view handler in all view instances.

Parameters

string|string[] $type: The handler type(s) to process.

callable $callback: A callback function to process the handler.

1 call to alpha_pagination_process_views_handler()
alpha_pagination_migrate_option in ./alpha_pagination.module
Migrates an option for a view handler.

File

./alpha_pagination.module, line 133
Module hooks and alters for the Views Alpha Pagination module.

Code

function alpha_pagination_process_views_handler($type, callable $callback) {
  $types = (array) $type;
  static $view_object_types;
  if (!isset($view_object_types)) {
    module_load_include('inc', 'views', 'includes/view');
    $view_object_types = views_object_types();
  }

  /** @var \view $view */
  $views = [];
  foreach (views_get_all_views() as $view) {

    // Initialize displays.
    $view
      ->init_display();

    /** @var \views_display $display */
    foreach ($view->display as $display_id => $display) {

      // Set the "current" display being iterated on.
      $view
        ->set_display($display_id);

      // Skip if there's no handler (for whatever reason).
      if (!isset($display->handler)) {
        continue;
      }

      // Get all the handlers that match $type.
      foreach (array_keys($display->display_options) as $type) {
        if (!in_array($type, array_keys($view_object_types))) {
          continue;
        }

        /** @var \views_handler[] $handlers */
        $handlers = [];

        /** @var \views_handler $handler */
        foreach ($display->handler
          ->get_handlers($type) as $id => $handler) {
          if (in_array($handler->field, $types)) {
            $handlers[$id] = $handler;
          }
        }
        foreach ($handlers as $id => $handler) {
          $save = call_user_func_array($callback, [
            $handler,
          ]);
          if ($save === TRUE) {
            $views[$view->name] = $view;
          }
        }
      }
    }
  }

  // Save any views.
  alpha_pagination_save_views($views);
}