{{ php_prefix|raw }}

namespace Drupal\{{ machine_name }}\Plugin\ECA\Condition;

use Drupal\Core\Form\FormStateInterface;
{% if context %}
use Drupal\Core\Plugin\Context\ContextDefinition;
{% endif %}
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\eca\Attribute\EcaCondition;
use Drupal\eca\Plugin\ECA\Condition\ConditionBase;

/**
 * Plugin implementation of the ECA condition "{{ purpose }}".
 */
#[EcaCondition(
  id: '{{ machine_name }}_{{ id }}',
  label: new TranslatableMarkup('{{ purpose }}'),
  description: new TranslatableMarkup('{{ description }}'),
{% if context %}
  context_definitions: [
{% for i,item in context %}
    '{{ item|trim }}' => new ContextDefinition(
      data_type: '{{ item|trim }}',
      label: new TranslatableMarkup('{{ item|trim|camelize }}'),
    ),
{% endfor %}
  ],
{% endif %}
  version_introduced: '{{ module_version }}',
)]
class {{ class }} extends ConditionBase {

  /**
   * {@inheritdoc}
   */
  public function evaluate(): bool {
{% if context %}
    ${{ context[0] }} = $this->getValueFromContext('{{ context[0] }}');
{% endif %}
    $result = TRUE;
    return $this->negationCheck($result);
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration(): array {
    return [
      'field1' => '',
    ] + parent::defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
    $form['field1'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label of field 1'),
      '#default_value' => $this->configuration['field1'],
    ];
    return parent::buildConfigurationForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    $this->configuration['field1'] = $form_state->getValue('field1');
    parent::submitConfigurationForm($form, $form_state);
  }

}
