Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/Datetime/Element/DateElementBase.php
- 9 core/lib/Drupal/Core/Datetime/Element/DateElementBase.php
Namespace
Drupal\Core\Datetime\Element
File
core/lib/Drupal/Core/Datetime/Element/DateElementBase.php
View source
<?php
namespace Drupal\Core\Datetime\Element;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Render\Element\FormElementBase;
abstract class DateElementBase extends FormElementBase {
protected static function datetimeRangeYears($string, $date = NULL) {
$datetime = new DrupalDateTime();
$this_year = $datetime
->format('Y');
[
$min_year,
$max_year,
] = explode(':', $string);
$plus_pattern = '@[\\+|\\-][0-9]{1,4}@';
$year_pattern = '@^[0-9]{4}@';
if (!preg_match($year_pattern, $min_year, $matches)) {
if (preg_match($plus_pattern, $min_year, $matches)) {
$min_year = $this_year + $matches[0];
}
else {
$min_year = $this_year;
}
}
if (!preg_match($year_pattern, $max_year, $matches)) {
if (preg_match($plus_pattern, $max_year, $matches)) {
$max_year = $this_year + $matches[0];
}
else {
$max_year = $this_year;
}
}
if ($min_year > $max_year) {
$temp = $max_year;
$max_year = $min_year;
$min_year = $temp;
}
$value_year = $date instanceof DrupalDateTime ? $date
->format('Y') : '';
if (!empty($value_year)) {
$min_year = min($value_year, $min_year);
$max_year = max($value_year, $max_year);
}
return [
$min_year,
$max_year,
];
}
protected static function getElementTitle($element, $complete_form) {
$title = '';
if (!empty($element['#title'])) {
$title = $element['#title'];
}
else {
$parents = $element['#array_parents'];
array_pop($parents);
$parent_element = NestedArray::getValue($complete_form, $parents);
if (!empty($parent_element['#title'])) {
$title = $parent_element['#title'];
}
}
return $title;
}
}
Classes