{% import '@lib/di.twig' as di %}
<?php

declare(strict_types=1);

namespace Drupal\{{ machine_name }}\Plugin\views\argument_default;

{% apply sort_namespaces %}
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
  {% if configurable %}
use Drupal\Core\Form\FormStateInterface;
  {% endif %}
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
  {% if services %}
{{ di.use(services) }}
use Symfony\Component\DependencyInjection\ContainerInterface;
  {% endif %}
{% endapply %}

/**
 * @todo Add plugin description here.
 */
#[ViewsArgumentDefault(
  id: '{{ plugin_id }}',
  title: new TranslatableMarkup('{{ plugin_label }}'),
)]
final class {{ class }} extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {

{% if services %}
  /**
   * Constructs a new {{ class }} instance.
   */
  public function __construct(
    array $configuration,
    $plugin_id,
    $plugin_definition,
{{ di.signature(services) }}
  ) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
    return new self(
      $configuration,
      $plugin_id,
      $plugin_definition,
{{ di.container(services) }}
    );
  }

{% endif %}
{% if configurable %}
  /**
   * {@inheritdoc}
   */
  protected function defineOptions(): array {
    $options = parent::defineOptions();
    $options['example'] = ['default' => ''];
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state): void {
    $form['example'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Example'),
      '#default_value' => $this->options['example'],
    ];
  }

{% endif %}
  /**
   * {@inheritdoc}
   *
   * @todo Make sure the return type-hint matches the argument type.
   */
  public function getArgument(): int {

    // @DCG
    // Here is the place where you should create a default argument for the
    // contextual filter. The source of this argument depends on your needs.
    // For example, the argument can be extracted from the URL or fetched from
    // some fields of the currently viewed entity.
    $argument = 123;

    return $argument;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge(): int {
    return Cache::PERMANENT;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts(): array {
    // @todo Use 'url.path' or 'url.query_args:%key' contexts if the argument
    // comes from URL.
    return [];
  }

}
