Skip to content

Drupal\helper\Utility

Provides various utility helpers.

Methods

Name Description
callPlugin Call a plugin callback and return its result.
camelCase Convert a string to CamelCase.
execCommand Runs a composer command.
registerUniqueShutdownFunction Registers a unique function call for execution on shutdown.
runBatch Runs a batch even if another batch is currently running.

Utility::callPlugin

Description

public static callPlugin (string $plugin_type, string $plugin_id, array $configuration, string $callback, mixed $args)

Call a plugin callback and return its result.

Parameters

  • (string) $plugin_type : The plugin type.
  • (string) $plugin_id : The plugin ID.
  • (array) $configuration : The plugin configuration.
  • (string) $callback : The method to call on the plugin class.
  • (mixed) $args : The arguments to pass to the plugin callback.

Return Values

mixed

The return value from the plugin method.


Utility::camelCase

Description

public static camelCase (string $string, bool $lower)

Convert a string to CamelCase.

Parameters

  • (string) $string : The string.
  • (bool) $lower : If the first character should be lower case (i.e. lowerCamelCase).

Return Values

string

The string.


Utility::execCommand

Description

public static execCommand (string $command, string $additional, mixed $result_code)

Runs a composer command.

Note: USE THIS AT YOUR OWN RISK. YOU ARE RESPONSIBLE FOR ESCAPING THE
INPUT TO THE $command PARAMETER.

Parameters

  • (string) $command : The composer command to run, without the "composer" part.
  • (string) $additional : The additional command parameters and arguments.
  • (mixed) $result_code : The result code from running the command, modified by reference.

Return Values

void

Throws Exceptions

\RuntimeException


Utility::registerUniqueShutdownFunction

Description

public static registerUniqueShutdownFunction (callable $callback, mixed $args)

Registers a unique function call for execution on shutdown.

Wrapper for drupal_register_shutdown_function() that does not add the
function call if it already exists in the shutdown function stack.

Parameters

  • (callable) $callback : The shutdown function to register.
  • (mixed) $args : Additional arguments to pass to the shutdown function.

Return Values

bool

TRUE if the function was added, or FALSE if it was already in the stack.


Utility::runBatch

Description

public static runBatch (array $batch)

Runs a batch even if another batch is currently running.

This is useful for running a batch inside another batch process.

Parameters

  • (array) $batch : A batch array that would normally get passed to batch_set().

Return Values

void