繰り返し日付フィールド
Provides a recurring/repeating dates field type that supports RFC 5545 RRULE format for defining complex recurring date patterns.
date_recur
インストール
composer require 'drupal/date_recur:^3.8'
概要
Recurring Dates Fieldモジュールは、Drupalで繰り返し日付を処理するための包括的なソリューションを提供します。コアのdatetime_rangeフィールドタイプを拡張し、RFC 5545 iCalendar繰り返しルール(RRULE)をサポートすることで、日次、週次、月次、年次など、さまざまな制約を持つ複雑な繰り返し日付パターンを定義できます。
このモジュールはrlanvin/php-rruleライブラリを使用して、RRULE文字列から発生日を解析・生成します。効率的なViews統合とクエリのため、発生日は専用のデータベーステーブルに保存されます。プラグイン可能なインタープリターシステムにより、管理者は繰り返しルールを表示用に人間が読めるテキストに変換する方法を設定できます。
主な機能には、タイムゾーン対応の日付処理、無限および有限の繰り返しパターンのサポート、設定可能な事前作成間隔での発生日キャッシュ、繰り返し日付コンテンツのフィルタリングと表示のための包括的なViews統合が含まれます。
Features
- 繰り返し日付パターンを定義するためのRRULEサポートを備えたdatetime_rangeを拡張するdate_recurフィールドタイプを提供
- FREQ、INTERVAL、COUNT、UNTIL、BYDAY、BYMONTH、BYMONTHDAY、BYYEARDAY、BYWEEKNO、BYHOUR、BYMINUTE、BYSECOND、BYSETPOS、WKST、EXDATEを含むRFC 5545 iCalendar繰り返しルールの完全サポート
- 効率的なクエリとViews統合のための専用データベーステーブルへの自動発生日キャッシュ
- 無限繰り返し日付の設定可能な事前作成間隔(1〜5年先まで)
- RRULE文字列を複数言語(de、en、es、fi、fr、it、nl)で人間が読めるテキストに変換するプラグイン可能なインタープリターシステム
- 開始/終了日ピッカー、タイムゾーンセレクター、RRULEテキストエリア入力を備えた基本ウィジェット
- 日付、人間が読める解釈、設定可能な数の今後の発生日を表示する基本フォーマッター
- ユーザーが使用できるRRULE機能を管理者が制限できる細かな頻度とパート設定
- 発生日フィルター、発生日テーブルへのリレーションシップ、日付フィールドプラグインを備えたViews統合
- カスタム処理のためのフィールド値保存、エンティティ削除、リビジョン削除時にイベントをディスパッチするイベントシステム
- 適切なUTC変換によるタイムゾーン対応のストレージと表示
- 日付のみとdatetime両方のフィールド設定をサポート
Use Cases
Event Calendar with Recurring Events
Create a content type for events with a date_recur field. Configure the field to allow weekly and monthly frequencies with BYDAY and BYMONTHDAY parts. Use Views with the occurrence filter to display events occurring within a date range, and the occurrence relationship to list all upcoming instances. Configure an interpreter to show 'Every Monday and Wednesday' instead of raw RRULE strings.
Appointment Scheduling System
Use date_recur fields on appointment content types to define recurring availability slots. Set the precreate interval to 2 years to generate occurrence data for scheduling. Create Views with the occurrence filter to find available slots within a selected time period. The occurrence cache table enables efficient querying without runtime RRULE calculation.
Class or Course Scheduling
Define courses that meet on specific patterns (e.g., every Tuesday and Thursday from 2-4pm). Configure field settings to restrict frequencies to WEEKLY and parts to BYDAY, UNTIL, and COUNT to prevent overly complex rules. The formatter shows the class schedule in plain English while storing the precise RRULE for occurrence generation.
Maintenance Schedule Management
Track equipment maintenance schedules with date_recur fields. Use MONTHLY frequency with BYMONTHDAY to schedule maintenance on specific days each month, or YEARLY with BYMONTH for annual inspections. Subscribe to the FIELD_VALUE_SAVE event to trigger notifications or create work orders when schedules are updated.
Custom Occurrence Processing
Implement an event subscriber for date_recur_field_value_save to sync occurrences with external calendar systems (Google Calendar, Outlook) or to create individual nodes/entities for each occurrence. The event provides access to the field item list and entity context for custom processing logic.
Tips
- Use the precreate setting wisely - longer intervals generate more occurrence rows but enable querying further into the future
- When using Views with date_recur fields, add the occurrence relationship first, then add fields/filters from the occurrence table for proper occurrence-based queries
- Configure interpreter settings to match your site's language and date format preferences for consistent user experience
- Restrict allowed frequencies and parts in field settings if you don't need the full complexity of RRULE - this simplifies the user experience
- For infinite recurring rules, the occurrence cache only contains precreated dates - plan your precreate interval based on how far ahead users need to query
- Subscribe to date_recur events for custom processing rather than using entity hooks, as the events provide the specific field context
- The RRULE textarea in the basic widget accepts standard iCalendar format - users can paste RRULEs from other calendar applications
- When creating custom formatters or widgets, use the DateRecurHelper::create() factory method to get occurrence data from field values
Technical Details
Admin Pages 3
/admin/config/regional/recurring-date-interpreters
Manage recurring date interpreters that convert RRULE strings into human-readable text. Interpreters are reusable configurations that can be selected in field formatter settings to control how recurring rules are displayed to users.
/admin/config/regional/recurring-date-interpreters/add
Create a new recurring date interpreter configuration. First select the plugin type, then configure plugin-specific settings.
/admin/config/regional/recurring-date-interpreters/manage/{date_recur_interpreter}
Modify settings for an existing recurring date interpreter.
権限 1
Hooks 5
hook_theme
Defines three theme hooks for rendering recurring date components: date_recur_basic_widget, date_recur_settings_frequency_table, and date_recur_basic_formatter.
hook_field_info_alter
Marks date_recur field type and any subclasses with a special flag (is_date_recur) used for occurrence table management and Views integration.
hook_field_views_data
Provides Views integration for date_recur attached fields, including occurrence table relationship and field handlers.
hook_views_data
Provides Views integration for date_recur base fields and occurrence filter plugin registration.
hook_views_data_alter
Removes default Views handlers from date_recur base fields that would conflict with the module's custom handlers.
Troubleshooting 6
Run 'composer require rlanvin/php-rrule' in your Drupal root directory to install the required library, then clear caches.
Ensure you've added the occurrence relationship to your View before adding occurrence-based fields or filters. Check that the occurrence cache table exists (date_recur__[entity_type]__[field_name]) and contains data.
Create an interpreter at /admin/config/regional/recurring-date-interpreters and select it in the field formatter settings. Verify the interpreter plugin is properly configured.
The module validates timezones on update. Run the provided update hook which will identify invalid timezone values that need manual correction in the database.
Check field settings to ensure at least one frequency with at least one part is enabled. If 'Allow all frequency and parts' is unchecked and no frequencies are enabled, the RRULE input will be hidden.
Each date_recur field creates its own occurrence cache table. For infinite rules, occurrence data is precreated based on the precreate interval. Consider reducing the precreate interval or using COUNT/UNTIL limits on rules to reduce database size.
Security Notes 4
- The module has 'covered' security advisory coverage from Drupal's security team
- Timezone values are validated against PHP's timezone_identifiers_list() to prevent injection of invalid values
- RRULE strings are validated using the php-rrule library's parser to ensure only valid rules are stored
- The rrule_max_length storage setting provides protection against extremely long RRULE strings that could impact performance