Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Open Y Socrates

140 sites No security coverage
View on drupal.org

This module implements a strategy pattern to manage pluggable data wrapper services with varying priorities. It allows you to define which service should be used to retrieve data based on the highest priority defined for a specific project. This can also be extended to manage cron services with specified periodicities.

πŸ‡ΊπŸ‡¦

This module is maintained by Ukrainian developers.
Please consider supporting Ukraine in a fight for their freedom and safety of Europe.

Socrates is an OOP representation of https://en.wikipedia.org/wiki/Strategy_pattern for Open Y to cover needs of pluggable distributed Data Wrapper services by priority.

Basically, if you have a membership calculator which should be used for display same thing but for different Data Services, Socrates gives you a convenient opportunity to define which service should be used for obtaining data on specific project. The highest priority service will be chosen for retrieving data.

For connecting your service to Socrates you need to

  • implement OpenyDataServiceInterface for the service's class
  • extend your_module.services.yml with tags
  <span class="hljs-attribute">example_socrates_data_service</span>:
    <span class="hljs-attribute">class</span>: Drupal\openy_socrates\ExampleSocratesDataService
    <span class="hljs-attribute">tags</span>:
      - { <span class="hljs-attribute">name</span>: openy_data_service, <span class="hljs-attribute">priority</span>: <span class="hljs-number">1000</span> }
  • replace the Data service with Socrates everywhere you need to have an ability to prioritize Data retrieving.

For connecting your service to Socrates Cron you need to:

  • implement OpenyCronServiceInterface for the service's class
  • extend your_module.services.yml with a tags
<span class="hljs-attr">  example_socrates_cron_service:</span>
<span class="hljs-attr">    class:</span> Drupal\openy_socrates\ExampleSocratesCronService
<span class="hljs-attr">    tags:</span>
<span class="hljs-bullet">      -</span>
<span class="hljs-attr">        name:</span> openy_cron_service
        <span class="hljs-comment"># In seconds from the last run.</span>
<span class="hljs-attr">        periodicity:</span> <span class="hljs-number">60</span>

Add the command to your crontab:

<span class="hljs-bullet">* </span><span class="hljs-bullet">* *</span> <span class="hljs-bullet">* *</span>   drush ev '\Drupal::service("socrates")-&gt;cron();'

Your data class usage with Socrates is fairly simple:

  <span class="hljs-comment">/* <span class="hljs-doctag">@var</span> \Drupal\my_module_data_service\dataService $dataService */</span>
  $myDataService = \Drupal::service(<span class="hljs-string">'socrates'</span>);
  $myDataService-&gt;myMethod();

Activity

Total releases
2
First release
May 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Release date
1.1.0 Stable Jun 30, 2025
1.0.4 Stable May 2, 2025