SmartDateOnlyWidget.php in Smart Date 3.4.x
File
src/Plugin/Field/FieldWidget/SmartDateOnlyWidget.php
View source
<?php
namespace Drupal\smart_date\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class SmartDateOnlyWidget extends SmartDateInlineWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element['time_wrapper']['value']['#date_time_format'] = '';
$element['time_wrapper']['value']['#date_time_element'] = 'none';
$element['time_wrapper']['end_value']['#date_time_format'] = '';
$element['time_wrapper']['end_value']['#date_time_element'] = 'none';
$element['duration']['#access'] = FALSE;
$form['#attached']['library'] = [
'smart_date/date_only',
];
return $element;
}
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
foreach ($values as &$item) {
if (isset($item['time_wrapper']['value'])) {
$item['value'] = $item['time_wrapper']['value'];
}
if (isset($item['time_wrapper']['end_value'])) {
$item['end_value'] = $item['time_wrapper']['end_value'];
}
$item['value']
->setTime(0, 0, 0);
$item['end_value']
->setTime(23, 59, 0);
}
$values = parent::massageFormValues($values, $form, $form_state);
return $values;
}
}