1. 8.5.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  2. 8.5.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  3. 8.0.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  4. 8.0.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  5. 8.1.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  6. 8.1.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  7. 8.2.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  8. 8.2.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  9. 8.3.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  10. 8.3.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  11. 8.4.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat
  12. 8.4.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  13. 8.6.x core/lib/Drupal/Core/Datetime/Entity/DateFormat.php DateFormat
  14. 8.6.x core/modules/config_translation/src/FormElement/DateFormat.php DateFormat

Defines the date format element for the configuration translation interface.

Hierarchy

Expanded class hierarchy of DateFormat

File

core/modules/config_translation/src/FormElement/DateFormat.php, line 10

Namespace

Drupal\config_translation\FormElement
View source
class DateFormat extends FormElementBase {

  /**
   * {@inheritdoc}
   */
  public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {

    /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
    $date_formatter = \Drupal::service('date.formatter');
    $description = $this
      ->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.');
    $format = $this
      ->t('Displayed as %date_format', [
      '%date_format' => $date_formatter
        ->format(REQUEST_TIME, 'custom', $translation_config),
    ]);
    return [
      '#type' => 'textfield',
      '#description' => $description,
      '#field_suffix' => ' <small data-drupal-date-formatter="preview">' . $format . '</small>',
      '#attributes' => [
        'data-drupal-date-formatter' => 'source',
      ],
      '#attached' => [
        'drupalSettings' => [
          'dateFormats' => $date_formatter
            ->getSampleDateFormats($translation_language
            ->getId()),
        ],
        'library' => [
          'system/drupal.system.date',
        ],
      ],
    ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
DateFormat::getTranslationElement public function Returns the translation form element for a given configuration definition. Overrides FormElementBase::getTranslationElement
FormElementBase::$definition protected property The data definition of the element this form element is for.
FormElementBase::$element protected property The schema element this form is for.
FormElementBase::create public static function Creates a form element instance from a schema definition. Overrides ElementInterface::create
FormElementBase::getSourceElement protected function Returns the source element for a given configuration definition.
FormElementBase::getTranslationBuild public function Builds a render array containg the source and translation form elements. Overrides ElementInterface::getTranslationBuild
FormElementBase::setConfig public function Sets configuration based on a nested form value array. Overrides ElementInterface::setConfig
FormElementBase::__construct public function Constructs a FormElementBase.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.