public function DateRecurDefaultRRule::humanReadable in Recurring Dates Field 8
Return a human readable and translated representation of the repeat rule.
This is the start for a Drupal-translated and improved converter. So far only handles a few cases. For unhandled cases, this calls back to RRule\RRule::humanReadable.
@todo: Cover more (all) cases.
Parameters
array $opt:
Return value
\Drupal\Core\StringTranslation\TranslatableMarkup|string
File
- src/
DateRecurDefaultRRule.php, line 44
Class
Namespace
Drupal\date_recurCode
public function humanReadable(array $opt = []) {
$build = [];
$daynames = DateHelper::weekDays(TRUE);
array_push($daynames, $daynames[0]);
unset($daynames[0]);
$monthnames = DateHelper::monthNames(TRUE);
$parts = [];
if (!empty($this->byweekday)) {
$dayparts = [];
foreach ($this->byweekday as $day) {
$dayparts[] = $daynames[$day];
}
$parts['day'] = $this
->_hrFormatList($dayparts);
}
elseif (!empty($this->byweekday_nth)) {
$dayparts = $days = [];
foreach ($this->byweekday_nth as $info) {
$days[$info[0]][] = $info[1];
}
foreach ($days as $day => $pos) {
$dayparts[] = $this
->t('pos_day', [
'@pos' => $this
->_hrFormatPosList($pos),
'@day' => $daynames[$day],
]);
}
$parts['day'] = $this
->_hrFormatList($dayparts);
}
switch ($this->freq) {
case self::WEEKLY:
$build['rule'] = $this
->t('weekly', [
'@day' => $parts['day'],
]);
break;
case self::MONTHLY:
$build['rule'] = $this
->t('monthly', [
'@posday' => $parts['day'],
]);
break;
}
if (!empty($this->dtstart)) {
$build['time'] = $this
->formatDateForDisplay($this->dtstart, 'H:i');
}
if (!empty($build['rule'])) {
return $this
->t('complete', [
'@rule' => $build['rule'],
'@time' => $build['time'],
]);
}
else {
$string = parent::humanReadable($opt);
return $string;
}
}