You are here

public function CalendarValidator::validateArgument in Calendar 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/argument_validator/CalendarValidator.php \Drupal\calendar\Plugin\views\argument_validator\CalendarValidator::validateArgument()

Performs validation for a given argument.

Overrides ArgumentValidatorPluginBase::validateArgument

File

src/Plugin/views/argument_validator/CalendarValidator.php, line 57

Class

CalendarValidator
Defines a argument validator plugin for Date arguments used in Calendar.

Namespace

Drupal\calendar\Plugin\views\argument_validator

Code

public function validateArgument($arg) {
  if (isset($this->argumentWrapper) && $this->argumentWrapper
    ->validateValue($arg)) {
    $date = $this->argumentWrapper
      ->createDateTime();

    // Adds 'January' to year to get correct header on Year calendars
    // to avoid problem defined on third note at
    // http://www.php.net/manual/en/datetime.formats.date.php
    $january = '';
    if ($this->options['replacement_format'] === 'Y') {
      $january = 'January';
    }
    $time = strtotime($january . $date
      ->format($this->options['replacement_format']));

    // Override title for substitutions.
    // @see \Drupal\views\Plugin\views\argument\ArgumentPluginBase::getTitle
    $this->argument->validated_title = $this->dateFormatter
      ->format($time, 'custom', $this->options['replacement_format']);
    return TRUE;
  }
  return FALSE;
}