DatexDate.php in Datex 8
File
src/Element/DatexDate.php
View source
<?php
namespace Drupal\datex\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Date;
class DatexDate extends Date {
public function getInfo() {
return [
'#date_date_element' => 'text',
] + parent::getInfo();
}
public static function preRenderDate($element) {
$element = parent::preRenderDate($element);
if ($element['#attributes']['type'] === 'date') {
$element['#attributes']['type'] = 'text';
}
return $element;
}
public static function processDate(&$element, FormStateInterface $form_state, &$complete_form) {
$element = parent::processDate($element, $form_state, $complete_form);
$type = $element['#attributes']['type'];
if (($type === 'date' || $type === 'text') && !empty($element['#date_date_format'])) {
if (!empty($element['#value'])) {
$parents = $element['#parents'];
array_pop($parents);
$fs = $form_state
->getValue($parents);
$element['#value'] = $fs['date'];
}
$lib = [];
foreach ($element['#attached']['library'] as $item) {
if ($item !== 'core/drupal.date' && $item !== 'datex/picker') {
$lib[] = $item;
}
}
$lib[] = 'datex/picker';
$element['#attached']['library'] = $lib;
$element['#attributes']['type'] = 'text';
}
return $element;
}
}
Classes
Name |
Description |
DatexDate |
Plugin annotation
@FormElement("date"); |