Skip to content
Snippets Groups Projects

Issue #2827055: Add option to show only start or end date in the DateTime Range custom formatter

Issue #2827055: Add option to show only start or end date in the DateTime Range custom formatter

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Lauri Timmanee
  • Srishti Bankar added 3 commits

    added 3 commits

    Compare with previous version

  • added 1 commit

    • 91dc7e2c - Move the constants to DateRangeItem class

    Compare with previous version

  • Srishti Bankar added 42 commits

    added 42 commits

    Compare with previous version

  • Srishti Bankar added 48 commits

    added 48 commits

    Compare with previous version

  • Lauri Timmanee added 109 commits

    added 109 commits

    Compare with previous version

  • Lauri Timmanee
  • Srishti Bankar added 33 commits

    added 33 commits

    Compare with previous version

  • 14 17 'datetime_range_post_update_views_string_plugin_id' => '9.0.0',
    15 18 ];
    16 19 }
    20
    21 /**
    22 * Updates date range field formatter configuration by adding a "from_to" setting to flagged entity view displays.
    23 *
    24 * @see \datetime_range_entity_view_display_presave
    25 */
    26 function datetime_range_post_update_from_to_configuration(array &$sandbox = NULL): void {
    27 $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
    28
    29 $callback = function (EntityViewDisplayInterface $entity_view_display) {
    30 return $entity_view_display->get('datetime_range_updated') === TRUE;
  • Yash Rode added 133 commits

    added 133 commits

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    • 92ed9f60 - saved form_to config in post_update

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • 72 '#description' => $this->t('The string to separate the start and end dates'),
    73 '#default_value' => $this->getSetting('separator'),
    74 '#states' => [
    75 'visible' => [
    76 'select[name="fields[' . $field_name . '][settings_edit_form][settings][from_to]"]' => ['value' => DateTimeRangeConstants::BOTH],
    77 ],
    78 ],
    79 ];
    80
    81 return $form;
    82 }
    83
    84 /**
    85 * {@inheritdoc}
    86 */
    87 public function dateTimeRangeSettingsSummary() {
  • 108 */
    109 protected function getFromToOptions() {
    110 return [
    111 DateTimeRangeConstants::BOTH => $this->t('Display both start and end dates'),
    112 DateTimeRangeConstants::START_DATE => $this->t('Display start date only'),
    113 DateTimeRangeConstants::END_DATE => $this->t('Display end date only'),
    114 ];
    115 }
    116
    117 /**
    118 * Returns whether or not the start date should be displayed.
    119 *
    120 * @return bool
    121 * True if the start date should be displayed. False otherwise.
    122 */
    123 public function startDateIsDisplayed() {
  • 124 switch ($this->getSetting('from_to')) {
    125 case DateTimeRangeConstants::BOTH:
    126 case DateTimeRangeConstants::START_DATE:
    127 return TRUE;
    128 }
    129
    130 return FALSE;
    131 }
    132
    133 /**
    134 * Returns whether or not the end date should be displayed.
    135 *
    136 * @return bool
    137 * True if the end date should be displayed. False otherwise.
    138 */
    139 public function endDateIsDisplayed() {
  • Lauri Timmanee
  • 2 2
    3 3 namespace Drupal\datetime_range;
    4 4
    5 use Drupal\Core\Datetime\DrupalDateTime;
    5 6 use Drupal\Core\Field\FieldItemListInterface;
    7 use Drupal\Core\Form\FormStateInterface;
    6 8
    7 9 /**
    8 10 * Provides friendly methods for datetime range.
    9 11 */
    10 12 trait DateTimeRangeTrait {
    11 13
    14 /**
    15 * {@inheritdoc}
    16 */
    17 public static function dateTimeRangeDefaultSettings() {
  • 64 ];
    65
    66 if (!in_array($plugin_definition['class'], $daterange_formatter_classes, FALSE)) {
    67 continue;
    68 }
    69
    70 if (!isset($component['settings']['from_to'])) {
    71 // Existing daterange formatters don't have 'from_to'.
    72 $component['settings']['from_to'] = DateTimeRangeConstants::BOTH;
    73 $entity_view_display->setComponent($name, $component);
    74 $update = TRUE;
    75 }
    76 }
    77
    78 if ($update) {
    79 $entity_view_display->set('datetime_range_updated', TRUE);
  • 1 <?php
    2
    3 namespace Drupal\datetime_range;
    4
    5 /**
    6 * Declares constants used in the datetime range module.
    7 */
    8 class DateTimeRangeConstants {
  • 103 /**
    104 * Returns a list of possible values for the 'from_to' setting.
    105 *
    106 * @return array
    107 * A list of 'from_to' options.
    108 */
    109 protected function getFromToOptions() {
    110 return [
    111 DateTimeRangeConstants::BOTH => $this->t('Display both start and end dates'),
    112 DateTimeRangeConstants::START_DATE => $this->t('Display start date only'),
    113 DateTimeRangeConstants::END_DATE => $this->t('Display end date only'),
    114 ];
    115 }
    116
    117 /**
    118 * Returns whether or not the start date should be displayed.
  • Yash Rode added 42 commits

    added 42 commits

    Compare with previous version

  • Yash Rode added 41 commits

    added 41 commits

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • 1 <?php
    2
    3 namespace Drupal\datetime_range;
    4
    5 /**
    6 * Declares constants used in the datetime range module.
    7 */
    8 enum DateTimeRangeConstants: string {
  • Yash Rode added 29 commits

    added 29 commits

    Compare with previous version

  • quietone
  • This needs to have return types added to all new methods.

  • Yash Rode added 146 commits

    added 146 commits

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    • f54e0f91 - added return type, shortened summary line

    Compare with previous version

  • Yash Rode added 1 commit

    added 1 commit

    • 7df4b258 - removed paramter from func calls

    Compare with previous version

  • catch @catch started a thread on the diff
  • 27 32 return $output;
    28 33 }
    29 34 }
    35
    36 /**
    37 * Implements hook_ENTITY_TYPE_presave() for entity_view_display entities.
    38 */
    39 function datetime_range_entity_view_display_presave(EntityViewDisplayInterface $entity_view_display): void {
    • This should either have a @todo, or maybe be moved to a helper function, so that it's easy to identify and remove when we remove the post update. Views has its own ConfigUpdater class for this, but tbh I think _datetime_range_post_update_from_to_configuration() or something would be fine here?

    • Please register or sign in to reply
  • omkar podey added 407 commits

    added 407 commits

    Compare with previous version

  • omkar podey added 1 commit
  • omkar podey added 1 commit
  • added 1 commit

    • b94e605d - Convert the enum back to interface so it's 8.1 compatible

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading