root / date / lib / Drupal / date / Plugin / field / widget / DateSelectWidget.php @ 77885877
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* @file
|
4 |
* Definition of Drupal\date\Plugin\field\widget\DateSelectWidget.
|
5 |
*/
|
6 |
|
7 |
namespace Drupal\date\Plugin\field\widget; |
8 |
|
9 |
use Drupal\Core\Annotation\Plugin; |
10 |
use Drupal\Core\Annotation\Translation; |
11 |
use Drupal\field\Plugin\Type\Widget\WidgetBase; |
12 |
use Drupal\date\Plugin\field\widget\DateTextWidget; |
13 |
|
14 |
/**
|
15 |
* Plugin implementation of the 'date' widget.
|
16 |
*
|
17 |
* @Plugin(
|
18 |
* id = "date_select",
|
19 |
* module = "date",
|
20 |
* label = @Translation("Select list"),
|
21 |
* field_types = {
|
22 |
* "date"
|
23 |
* },
|
24 |
* settings = {
|
25 |
* "date_date_format" = "Y-m-d",
|
26 |
* "date_date_element" = "date",
|
27 |
* "input_format_custom" = "",
|
28 |
* "increment" = 15,
|
29 |
* "text_parts" = {""},
|
30 |
* "year_range" = "-3:+3",
|
31 |
* }
|
32 |
* )
|
33 |
*/
|
34 |
class DateSelectWidget extends DateWidgetBase { |
35 |
|
36 |
function settingsForm(array $form, array &$form_state) { |
37 |
$element = parent::settingsForm(array $form, array &$form_state); |
38 |
|
39 |
$element['date_date_format'] = array( |
40 |
'#type' => 'select', |
41 |
'#title' => t('Date entry format'), |
42 |
'#default_value' => $settings['date_date_format'], |
43 |
'#options' => $this->formatOptions(), |
44 |
'#description' => t('Control the order and format of the options users see.'), |
45 |
'#weight' => 3, |
46 |
'#fieldset' => 'date_format', |
47 |
); |
48 |
|
49 |
$element['advanced'] = array( |
50 |
'#type' => 'fieldset', |
51 |
'#title' => t('Advanced settings'), |
52 |
'#collapsible' => TRUE, |
53 |
'#collapsed' => TRUE, |
54 |
'#fieldset' => 'date_format', |
55 |
'#weight' => 9, |
56 |
); |
57 |
$element['advanced']['text_parts'][$key] = array( |
58 |
'#type' => 'value', |
59 |
'#value' => (int) in_array($key, (array) $settings['text_parts']), |
60 |
); |
61 |
|
62 |
$element['advanced']['text_parts'] = array('#theme' => 'date_text_parts'); |
63 |
$text_parts = (array) $settings['text_parts']; |
64 |
foreach (DateGranularity::granularityNames() as $key => $value) { |
65 |
$element['advanced']['text_parts'][$key] = array( |
66 |
'#type' => 'radios', |
67 |
'#default_value' => in_array($key, $text_parts) ? 1 : 0, |
68 |
'#options' => array(0 => '', 1 => ''), |
69 |
); |
70 |
} |
71 |
|
72 |
return $element; |
73 |
} |
74 |
} |