<commit_before><?php

namespace Drupal\effective_activism\Form;

use DateTimeZone;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\effective_activism\Entity\Group;
use Drupal\effective_activism\Entity\Organization;
use Drupal\effective_activism\Helper\PathHelper;
use ReflectionClass;

/**
 * Form controller for event template edit forms.
 *
 * @ingroup effective_activism
 */
class EventTemplateForm extends ContentEntityForm {

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, Organization $organization = NULL, Group $group = NULL) {
    /* @var $entity \Drupal\effective_activism\Entity\EventTemplate */
    $form = parent::buildForm($form, $form_state);
    $form['#theme'] = (new ReflectionClass($this))->getShortName();
    if (!$this->entity->isNew()) {
      $form['new_revision'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Create new revision'),
        '#default_value' => FALSE,
        '#weight' => 10,
      ];
    }
    $entity = $this->entity;
    // Set values from path.
    $form['organization']['widget'][0]['target_id']['#default_value'] = $organization;
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
    // Event start date must be older or equal to end date.
    $start_date = new DrupalDateTime($form_state->getValue('event_start_date')[0]['value'], new DateTimezone(DATETIME_STORAGE_TIMEZONE));
    $end_date = new DrupalDateTime($form_state->getValue('event_end_date')[0]['value'], new DateTimezone(DATETIME_STORAGE_TIMEZONE));
    if (
      !$start_date->hasErrors() &&
      !$end_date->hasErrors() &&
      $start_date->format('U') > $end_date->format('U')
    ) {
      $form_state->setErrorByName('event_end_date', $this->t('End date must be later than start date.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {<commit_msg>AFA-244 Allow for one or both values to be empty<commit_after><?php

namespace Drupal\effective_activism\Form;

use DateTimeZone;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\effective_activism\Entity\Group;
use Drupal\effective_activism\Entity\Organization;
use Drupal\effective_activism\Helper\PathHelper;
use ReflectionClass;

/**
 * Form controller for event template edit forms.
 *
 * @ingroup effective_activism
 */
class EventTemplateForm extends ContentEntityForm {

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, Organization $organization = NULL, Group $group = NULL) {
    /* @var $entity \Drupal\effective_activism\Entity\EventTemplate */
    $form = parent::buildForm($form, $form_state);
    $form['#theme'] = (new ReflectionClass($this))->getShortName();
    if (!$this->entity->isNew()) {
      $form['new_revision'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Create new revision'),
        '#default_value' => FALSE,
        '#weight' => 10,
      ];
    }
    $entity = $this->entity;
    // Set values from path.
    $form['organization']['widget'][0]['target_id']['#default_value'] = $organization;
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
    // Event start date must be older or equal to end date.
    if (
      !empty($form_state->getValue('event_start_date')[0]['value']) &&
      !empty($form_state->getValue('event_end_date')[0]['value'])
    ) {
      $start_date = new DrupalDateTime($form_state->getValue('event_start_date')[0]['value'], new DateTimezone(DATETIME_STORAGE_TIMEZONE));
      $end_date = new DrupalDateTime($form_state->getValue('event_end_date')[0]['value'], new DateTimezone(DATETIME_STORAGE_TIMEZONE));
      if (
        !$start_date->hasErrors() &&
        !$end_date->hasErrors() &&
        $start_date->format('U') > $end_date->format('U')
      ) {
        $form_state->setErrorByName('event_end_date', $this->t('End date must be later than start date.'));
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
{'fraction_non_alphanumeric': 0.15638321741081446, 'fraction_numerical': 0.003365492483733453, 'mean_word_length': 4.094857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3197593', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1398, 'n_words': 268}