function Variable::callableToString

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/Variable.php \Drupal\Component\Utility\Variable::callableToString()
  2. 11.x core/lib/Drupal/Component/Utility/Variable.php \Drupal\Component\Utility\Variable::callableToString()

Generates a human-readable name for a callable.

Parameters

callable $callable: A callable.

Return value

string A human-readable name for the callable.

6 calls to Variable::callableToString()
Datelist::processDatelist in core/lib/Drupal/Core/Datetime/Element/Datelist.php
Expands a date element into an array of individual elements.
DatelistElementFormTest::testDatelistElementUntrustedCallbacks in core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php
Tests that exceptions are raised if untrusted callbacks are used.
Datetime::processDatetime in core/lib/Drupal/Core/Datetime/Element/Datetime.php
Expands a datetime element type into date and/or time elements.
DatetimeElementFormTest::providerUntrusted in core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php
Data provider for ::testDatetimeElementUntrustedCallbacks().
Renderer::doRender in core/lib/Drupal/Core/Render/Renderer.php
See the docs for ::render().

... See full list

File

core/lib/Drupal/Component/Utility/Variable.php, line 21

Class

Variable
Provides helpers for dealing with variables.

Namespace

Drupal\Component\Utility

Code

public static function callableToString($callable) : string {
    if ($callable instanceof \Closure) {
        return '[closure]';
    }
    elseif (is_array($callable) && $callable) {
        if (is_object($callable[0])) {
            $callable[0] = get_class($callable[0]);
        }
        return implode('::', $callable);
    }
    elseif (is_string($callable)) {
        return $callable;
    }
    else {
        return '[unknown]';
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.