use Drupal\views\Plugin\views\filter\InOperator;
/**
* Implements hook_views_data_alter().
*/
function custom_filter_views_data_alter(array &$data) {
$data['node_field_data']['custom_file_filter'] = [
'title' => t('Custom File Filter'),
'filter' => [
'id' => 'custom_filter_handler',
],
];
}
/**
* Custom filter handler for filtering by file name.
*/
class CustomFilterHandler extends InOperator {
public function query() {
$user_input = $this->getExposedInput()['custom_filter'];
if (!empty($user_input)) {
$this->ensureMyTable();
$this->query->addWhere(0, "node__field_attachments.field_attachments_target_id IS NOT NULL");
$this->query->addWhere(0, "file_managed.filename LIKE :file_name", [':file_name' => '%' . db_like($user_input) . '%']);
}
}
}