Skip to content
Snippets Groups Projects
Verified Commit da2be507 authored by Frank Mably's avatar Frank Mably
Browse files

Initial commit

parents
Branches
Tags
No related merge requests found
# Drupal editor configuration normalization
# @see http://editorconfig.org/
# This is the top-most .editorconfig file; do not search in parent directories.
root = true
# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[composer.{json, lock}]
indent_size = 4
.idea
This diff is collapsed.
name: BEF HTML5 Date plugin
type: module
description: Plugin BEF permettant d'utiliser des champs date HTML5 dans les filtres de vue.
package: BM
core_version_requirement: ^8.8 || ^9 || ^10
dependencies:
- better_exposed_filters:better_exposed_filters
{
"name": "drupal/bef_html5_date",
"description": "BEF HTML5 Date plugin",
"type": "drupal-module",
"license": "AGPL-3.0+",
"authors": [
{
"name": "Frank Mably (mably)",
"homepage": "https://www.drupal.org/u/mably",
"role": "Maintainer"
}
],
"homepage": "https://drupal.org/project/bef_html5_date",
"support": {
"issues": "https://drupal.org/project/issues/bef_html5_date",
"source": "https://git.drupalcode.org/project/bef_html5_date"
},
"require": {
"drupal/core": "^9.3 || ^10"
}
}
<?php
namespace Drupal\bef_html5_date\Plugin\better_exposed_filters\filter;
use Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase;
use Drupal\Core\Form\FormStateInterface;
/**
* HTML5 date widget implementation.
*
* @BetterExposedFiltersFilterWidget(
* id = "bef_html5_date",
* label = @Translation("HTML5 Date"),
* )
*/
class Html5Date extends FilterWidgetBase {
/**
* {@inheritdoc}
*/
public static function isApplicable($filter = NULL, array $filter_options = []) {
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
$is_applicable = FALSE;
if ((is_a($filter, 'Drupal\views\Plugin\views\filter\Date') || !empty($filter->date_handler)) && !$filter->isAGroup()) {
$is_applicable = TRUE;
}
return $is_applicable;
}
/**
* {@inheritdoc}
*/
public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
$field_id = $this->getExposedFilterFieldId();
// Handle wrapper element added to exposed filters
// in https://www.drupal.org/project/drupal/issues/2625136.
$wrapper_id = $field_id . '_wrapper';
if (!isset($form[$field_id]) && isset($form[$wrapper_id])) {
$element = &$form[$wrapper_id][$field_id];
}
else {
$element = &$form[$field_id];
}
parent::exposedFormAlter($form, $form_state);
/*
* Standard Drupal date field. Depending on the settings, the field
* can be at $element (single field) or
* $element[subfield] for two-value date fields or filters
* with exposed operators.
*/
$fields = ['min', 'max', 'value'];
if (count(array_intersect($fields, array_keys($element)))) {
foreach ($fields as $field) {
if (isset($element[$field])) {
$element[$field]['#type'] = 'date';
$element[$field]['#attributes']['type'] = 'date';
$element[$field]['#attributes']['class'][] = 'bef-html5-date';
}
}
}
else {
$element['#type'] = 'date';
$element['#attributes']['type'] = 'date';
$element['#attributes']['class'][] = 'bef-html5-date';
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment