You are here

public static function Bootstrap::addCallback in Express 8

Adds a callback to an array.

Parameters

array $callbacks: An array of callbacks to add the callback to, passed by reference.

array|string $callback: The callback to add.

array|string $replace: If specified, the callback will instead replace the specified value instead of being appended to the $callbacks array.

int $action: Flag that determines how to add the callback to the array.

Return value

bool TRUE if the callback was added, FALSE if $replace was specified but its callback could be found in the list of callbacks.

2 calls to Bootstrap::addCallback()
ElementInfo::alter in themes/contrib/bootstrap/src/Plugin/Alter/ElementInfo.php
Alters data for a specific hook_TYPE_alter() implementation.
ThemeRegistry::alter in themes/contrib/bootstrap/src/Plugin/Alter/ThemeRegistry.php
Alters data for a specific hook_TYPE_alter() implementation.

File

themes/contrib/bootstrap/src/Bootstrap.php, line 122
Contains \Drupal\bootstrap\Bootstrap.

Class

Bootstrap
The primary class for the Drupal Bootstrap base theme.

Namespace

Drupal\bootstrap

Code

public static function addCallback(array &$callbacks, $callback, $replace = NULL, $action = Bootstrap::CALLBACK_APPEND) {

  // Replace a callback.
  if ($replace) {

    // Iterate through the callbacks.
    foreach ($callbacks as $key => $value) {

      // Convert each callback and match the string values.
      if (Unicode::convertCallback($value) === Unicode::convertCallback($replace)) {
        $callbacks[$key] = $callback;
        return TRUE;
      }
    }

    // No match found and action shouldn't append or prepend.
    if ($action !== self::CALLBACK_REPLACE_APPEND || $action !== self::CALLBACK_REPLACE_PREPEND) {
      return FALSE;
    }
  }

  // Append or prepend the callback.
  switch ($action) {
    case self::CALLBACK_APPEND:
    case self::CALLBACK_REPLACE_APPEND:
      $callbacks[] = $callback;
      return TRUE;
    case self::CALLBACK_PREPEND:
    case self::CALLBACK_REPLACE_PREPEND:
      array_unshift($callbacks, $callback);
      return TRUE;
    default:
      return FALSE;
  }
}