You are here

protected function DateRecurModularUtilityTrait::buildRruleString in Recurring Date Field Modular Widgets 3.x

Same name and namespace in other branches
  1. 8 src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::buildRruleString()
  2. 2.x src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::buildRruleString()

Builds RRULE string from an array of parts, stripping disallowed parts.

Parameters

array $parts: An array of parts, including 'FREQ'.

\Drupal\date_recur\DateRecurPartGrid $grid: A part grid. Any disallowed frequencies or parts are stripped silently.

Return value

string An RRULE string ready for storage.

2 calls to DateRecurModularUtilityTrait::buildRruleString()
DateRecurModularAlphaWidget::massageFormValues in src/Plugin/Field/FieldWidget/DateRecurModularAlphaWidget.php
Massages the form values into the format expected for field values.
DateRecurModularOscarWidget::massageFormValues in src/Plugin/Field/FieldWidget/DateRecurModularOscarWidget.php
Massages the form values into the format expected for field values.

File

src/DateRecurModularUtilityTrait.php, line 159

Class

DateRecurModularUtilityTrait
Trait containing convenience methods for dealing with date recur widgets.

Namespace

Drupal\date_recur_modular

Code

protected function buildRruleString(array $parts, DateRecurPartGrid $grid) : string {
  $frequency = $parts['FREQ'];
  foreach (array_keys($parts) as $part) {
    if ($part === 'FREQ') {
      continue;
    }
    if (!$grid
      ->isPartAllowed($frequency, $part)) {
      unset($parts[$part]);
    }
  }
  $ruleKv = [];
  foreach ($parts as $k => $v) {
    $ruleKv[] = "{$k}={$v}";
  }
  return implode(';', $ruleKv);
}