Pimcore\Placeholder::replacePlaceholdersFromStack PHP Method

replacePlaceholdersFromStack() protected method

Creates the Placeholder objects and replaces the placeholder string with the rendered content of the placeholder object
protected replacePlaceholdersFromStack ( array $placeholderStack = [] ) : string
$placeholderStack array
return string
    protected function replacePlaceholdersFromStack($placeholderStack = [])
    {
        $stringReplaced = null;
        if (!empty($placeholderStack)) {
            foreach ($placeholderStack as $placeholder) {
                $placeholderObject = null;
                $placeholderClassPrefixes = self::getPlaceholderClassPrefixes();
                $placeholderObject = null;
                foreach ($placeholderClassPrefixes as $classPrefix) {
                    $className = $classPrefix . $placeholder['placeholderClass'];
                    if (Tool::classExists($className)) {
                        $placeholderObject = new $className();
                        break;
                    }
                }
                if (is_null($stringReplaced)) {
                    $stringReplaced = $placeholder['contentString'];
                }
                if ($placeholderObject instanceof Placeholder\AbstractPlaceholder) {
                    //setting values from placeholder stack to placeholder objects
                    foreach (array_keys($placeholder) as $key) {
                        if ($key == 'placeholderClass') {
                            continue;
                        }
                        $placeholderObject->{'set' . ucfirst($key)}($placeholder[$key]);
                    }
                    $placeholderObject->setLocale();
                    $replaceWith = $placeholderObject->getReplacement();
                    if (!isset($replaceWith)) {
                        $replaceWith = $placeholderObject->getEmptyValue();
                    }
                    $stringReplaced = str_replace($placeholderObject->getPlaceholderString(), $replaceWith, $stringReplaced);
                } else {
                    Logger::warn('Ignoring Placeholder "' . $placeholder['placeholderClass'] . '" -> Class not Found or not an instance of Pimcore_Placeholder_Abstract!');
                }
            }
        }
        return $stringReplaced;
    }