SmartDateInlineWidget.php in Smart Date 3.2.x
File
src/Plugin/Field/FieldWidget/SmartDateInlineWidget.php
View source
<?php
namespace Drupal\smart_date\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateDefaultWidget;
class SmartDateInlineWidget extends SmartDateDefaultWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$time_wrapper = [
'#type' => 'container',
'#attributes' => [
'class' => [
'smartdate--time-inline',
],
],
'#tree' => TRUE,
];
$element = array_merge([
'time_wrapper' => $time_wrapper,
], $element);
$element['time_wrapper']['value'] = $element['value'];
unset($element['value']);
$element['time_wrapper']['separator']['#markup'] = '<span class="smartdate--separator">' . $this
->t('to') . '</span>';
$element['time_wrapper']['end_value'] = $element['end_value'];
unset($element['end_value']);
if (!isset($element['value']) || isset($element['#access']) && $element['#access'] === FALSE) {
return $element;
}
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'];
}
}
$values = parent::massageFormValues($values, $form, $form_state);
return $values;
}
}