class PersianDateTime in Persian Date for Drupal 8 8
Same name and namespace in other branches
- 8.4 src/Element/PersianDateTime.php \Drupal\persian_date\Element\PersianDateTime
Class PersianDateTime @package Drupal\persian_date\Element
Plugin annotation
@FormElement("persian_datetime");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Datetime\Element\DateElementBase
- class \Drupal\Core\Datetime\Element\Datetime
- class \Drupal\persian_date\Element\PersianDateTime
- class \Drupal\Core\Datetime\Element\Datetime
- class \Drupal\Core\Datetime\Element\DateElementBase
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PersianDateTime
1 file declares its use of PersianDateTime
- PersianTimestampDateTimeDefaultWidget.php in src/
Plugin/ Field/ FieldWidget/ PersianTimestampDateTimeDefaultWidget.php
File
- src/
Element/ PersianDateTime.php, line 23
Namespace
Drupal\persian_date\ElementView source
class PersianDateTime extends Datetime {
public function getInfo() {
$info = parent::getInfo();
$info['#date_date_element'] = 'text';
return $info;
}
public static function formatExample($format) {
if (!static::$dateExample) {
static::$dateExample = new PersianDrupalDateTime();
}
return static::$dateExample
->format($format);
}
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
if ($input !== FALSE) {
$date_input = $element['#date_date_element'] != 'none' && !empty($input['date']) ? $input['date'] : '';
$time_input = $element['#date_time_element'] != 'none' && !empty($input['time']) ? $input['time'] : '';
$date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
$time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
$timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL;
// Seconds will be omitted in a post in case there's no entry.
if (!empty($time_input) && strlen($time_input) == 5) {
$time_input .= ':00';
}
try {
$date_time_format = trim($date_format . ' ' . $time_format);
$date_time_input = trim($date_input . ' ' . $time_input);
$date = PersianDrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone);
$date = DrupalDateTime::createFromDateTime($date
->getDateTime());
} catch (\Exception $e) {
$date = NULL;
}
$input = [
'date' => $date_input,
'time' => $time_input,
'object' => $date,
];
}
else {
$date = $element['#default_value'];
if ($date instanceof DrupalDateTime && !$date
->hasErrors()) {
$input = [
'date' => $date
->format($element['#date_date_format']),
'time' => $date
->format($element['#date_time_format']),
'object' => $date,
];
}
else {
$input = [
'date' => '',
'time' => '',
'object' => NULL,
];
}
}
return $input;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateElementBase:: |
protected static | function | Specifies the start and end year to use as a date range. | |
DateElementBase:: |
protected static | function | Returns the most relevant title of a datetime element. | |
Datetime:: |
protected static | property | ||
Datetime:: |
protected static | function | Retrieves the right format for a HTML5 date element. | |
Datetime:: |
protected static | function | Retrieves the right format for a HTML5 time element. | |
Datetime:: |
public static | function |
Form element processing handler for the #ajax form property. Overrides RenderElement:: |
|
Datetime:: |
public static | function | Expands a datetime element type into date and/or time elements. | |
Datetime:: |
public static | function | Validation callback for a datetime element. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PersianDateTime:: |
public static | function |
Creates an example for a date format. Overrides Datetime:: |
|
PersianDateTime:: |
public | function |
Returns the element properties for this element. Overrides Datetime:: |
|
PersianDateTime:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides Datetime:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |