class HelperService

Service with some helpful methods that we use in different locations.

Properties

protected DateFormatterInterface $dateFormatter

Drupal\Core\Datetime\DateFormatterInterface definition.

protected ModuleHandlerInterface $moduleHandler

The module handler.

Methods

__construct(DateFormatterInterface $date_formatter, ModuleHandlerInterface $moduleHandler)

Constructs a new HelperService object.

string
createIsoDate(int $timestamp)

Create a ISO8601 timestamp that Microsoft Graph API can use.

string
formatDate(string $date, string $timezone = 'UTC', string $format = 'd-m-Y H:i')

Format a ISO8601 date into something more readable.

false|array
getApiConfig(string|null $config_id = 'default')

Retrieve the API settings from the config.

string|array
getAuthScopes(O365ConnectorInterface|null $o365_connector, bool $asArray = FALSE)

Get the auth scopes string.

string
getTsFromDate(string $date, string $timezone = 'UTC')

Generate a unix timestamp from a date.

bool
strContains(string $haystack, string $needle)

Checks if a string contains a given substring.

Details

at line 36
__construct(DateFormatterInterface $date_formatter, ModuleHandlerInterface $moduleHandler)

Constructs a new HelperService object.

Parameters

DateFormatterInterface $date_formatter

The DateFormatterInterface definition.

ModuleHandlerInterface $moduleHandler

The module handler.

at line 50
string createIsoDate(int $timestamp)

Create a ISO8601 timestamp that Microsoft Graph API can use.

Parameters

int $timestamp

The unix timestamp we want to use to create the date.

Return Value

string

The ISO8601 formatted date.

at line 69
string formatDate(string $date, string $timezone = 'UTC', string $format = 'd-m-Y H:i')

Format a ISO8601 date into something more readable.

Parameters

string $date

The ISO8601 date.

string $timezone

The timezone.

string $format

The format we want to convert to.

Return Value

string

The formatted date.

Exceptions

Exception

at line 83
false|array getApiConfig(string|null $config_id = 'default')

Retrieve the API settings from the config.

Parameters

string|null $config_id

Return Value

false|array

The array with the settings, or FALSE.

at line 99
string|array getAuthScopes(O365ConnectorInterface|null $o365_connector, bool $asArray = FALSE)

Get the auth scopes string.

Parameters

O365ConnectorInterface|null $o365_connector

The o365 connector.

bool $asArray

If the returned value needs to be a array, defaults to FALSE.

Return Value

string|array

The space seperated list of auth scopes or a raw array of scopes.

at line 143
string getTsFromDate(string $date, string $timezone = 'UTC')

Generate a unix timestamp from a date.

Parameters

string $date

The date.

string $timezone

The timezone.

Return Value

string

The unix timestamp.

at line 163
bool strContains(string $haystack, string $needle)

Checks if a string contains a given substring.

PHP 8 has str_contains(), but we keep this compatible with < 8.

Parameters

string $haystack

The string to search in.

string $needle

The substring to search for in the haystack.

Return Value

bool

TRUE if $needle is found anywhere in $haystack, FALSE otherwise.