clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace Drupal\date_popup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\Date;
/**
* The date popup views filter plugin.
*/
class DatePopup extends Date {
use DatePopupTrait;
/**
* {@inheritdoc}
*/
public function buildExposedForm(&$form, FormStateInterface $form_state) {
parent::buildExposedForm($form, $form_state);
$this->applyDatePopupToForm($form);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Drupal\date_popup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api\Plugin\views\filter\SearchApiDate;
/**
* Defines a class for search api date filter with popup.
*/
class DatePopupSearchApi extends SearchApiDate {
use DatePopupTrait;
/**
* {@inheritdoc}
*/
public function buildExposedForm(&$form, FormStateInterface $form_state) {
parent::buildExposedForm($form, $form_state);
$this->applyDatePopupToForm($form);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Drupal\date_popup;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
/**
* Provides shared code between the Date and Datetime plugins.
*/
trait DatePopupTrait {
/**
* Applies the date storage format to default value.
*
* @param string $default_value
* The date value to be formatted.
*
* @return string
* The formatted value.
*/
protected function setDefaultValue(string $default_value): string {
if (!empty($default_value)) {
$date = new DrupalDateTime($default_value);
if (!$date->hasErrors()) {
return $date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
}
}
return $default_value;
}
/**
* Applies the HTML5 date popup to the views filter form.
*
* @param array &$form
* The form to apply it to.
*/
protected function applyDatePopupToForm(array &$form): void {
if (!empty($this->options['expose']['identifier'])) {
$identifier = $this->options['expose']['identifier'];
// Identify wrapper.
$wrapper_key = $identifier . '_wrapper';
if (isset($form[$wrapper_key])) {
$element = &$form[$wrapper_key][$identifier];
}
else {
$element = &$form[$identifier];
}
// Detect filters that are using min/max.
if (isset($element['min'])) {
$element['min']['#type'] = 'date';
$element['max']['#type'] = 'date';
if ($this->options['value']['type'] == 'offset') {
$element['min']['#default_value'] = $this->setDefaultValue($element['min']['#default_value']);
$element['max']['#default_value'] = $this->setDefaultValue($element['max']['#default_value']);
}
if (isset($element['value'])) {
$element['value']['#type'] = 'date';
}
}
else {
$element['#type'] = 'date';
$element['#default_value'] = $this->setDefaultValue($element['#default_value']);
}
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Drupal\date_popup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime\Plugin\views\filter\Date;
/**
* The datetime popup views filter plugin.
*/
class DatetimePopup extends Date {
use DatePopupTrait;
/**
* {@inheritdoc}
*/
public function buildExposedForm(&$form, FormStateInterface $form_state) {
parent::buildExposedForm($form, $form_state);
$this->applyDatePopupToForm($form);
}
}