<?php
namespace Drupal\rufi_structure\Plugin\views\field;

use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

/**
 * @ingroup views_field_handlers
 */
#[ViewsField("query_param_node_type_field")]
class QueryParamNodeTypeField extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    // No query needed, we fetch the value from the request.
  }

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $request = \Drupal::request();
    $node_type = $request->query->get('node_type');
    return $node_type ? $this->t('@type', ['@type' => $node_type]) : '';
  }
}
