function MigrateMessageController::buildFilterQuery

Same name in other branches
  1. 10 core/modules/migrate/src/Controller/MigrateMessageController.php \Drupal\migrate\Controller\MigrateMessageController::buildFilterQuery()

Builds a query for migrate message administration.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

array|null An associative array with keys 'where' and 'args' or NULL if there were no filters set.

1 call to MigrateMessageController::buildFilterQuery()
MigrateMessageController::details in core/modules/migrate/src/Controller/MigrateMessageController.php
Displays a listing of migration messages for the given migration ID.

File

core/modules/migrate/src/Controller/MigrateMessageController.php, line 250

Class

MigrateMessageController
Provides controller methods for the Message form.

Namespace

Drupal\migrate\Controller

Code

protected function buildFilterQuery(Request $request) : ?array {
    $session_filters = $request->getSession()
        ->get('migration_messages_overview_filter', []);
    if (empty($session_filters)) {
        return NULL;
    }
    // Build query.
    $where = $args = [];
    foreach ($session_filters as $filter) {
        $filter_where = [];
        switch ($filter['type']) {
            case 'array':
                foreach ($filter['value'] as $value) {
                    $filter_where[] = $filter['where'];
                    $args[] = $value;
                }
                break;
            case 'string':
                $filter_where[] = $filter['where'];
                $args[] = '%' . $filter['value'] . '%';
                break;
            default:
                $filter_where[] = $filter['where'];
                $args[] = $filter['value'];
        }
        if (!empty($filter_where)) {
            $where[] = '(' . implode(' OR ', $filter_where) . ')';
        }
    }
    $where = !empty($where) ? implode(' AND ', $where) : '';
    return [
        'where' => $where,
        'args' => $args,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.