function ConfigBase::castSafeStrings

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::castSafeStrings()
  2. 8.9.x core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::castSafeStrings()
  3. 11.x core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::castSafeStrings()

Casts any objects that implement MarkupInterface to string.

Parameters

mixed $data: The configuration data.

Return value

mixed The data with any safe strings cast to string.

2 calls to ConfigBase::castSafeStrings()
ConfigBase::set in core/lib/Drupal/Core/Config/ConfigBase.php
Sets a value in this configuration object.
ConfigBase::setData in core/lib/Drupal/Core/Config/ConfigBase.php
Replaces the data of this configuration object.

File

core/lib/Drupal/Core/Config/ConfigBase.php, line 282

Class

ConfigBase
Provides a base class for configuration objects with get/set support.

Namespace

Drupal\Core\Config

Code

protected function castSafeStrings($data) {
    if ($data instanceof MarkupInterface) {
        $data = (string) $data;
    }
    elseif (is_array($data)) {
        array_walk_recursive($data, function (&$value) {
            if ($value instanceof MarkupInterface) {
                $value = (string) $value;
            }
        });
    }
    return $data;
}

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