class NameListFormattableMarkup in Name Field 8
Formats a string for HTML display by replacing variable placeholders.
Adds special handling of @names, @last.
Hierarchy
- class \Drupal\name\Render\NameListFormattableMarkup implements MarkupInterface
Expanded class hierarchy of NameListFormattableMarkup
1 file declares its use of NameListFormattableMarkup
File
- src/
Render/ NameListFormattableMarkup.php, line 13
Namespace
Drupal\name\RenderView source
class NameListFormattableMarkup implements MarkupInterface {
/**
* The names.
*
* @var array
*/
protected $names = [];
/**
* The name separator.
*
* @var string
*/
protected $separator = ', ';
/**
* Constructor for NameListFormattableMarkup.
*/
public function __construct(array $names = [], $separator = ', ') {
$this->names = $names;
$this->separator = $this
->escapeValues($separator);
}
/**
* {@inheritdoc}
*/
public function __toString() {
return $this
->escapeValues($this->names);
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() {
return $this
->__toString();
}
/**
* Escapes values if needed.
*
* @param array|string|\Drupal\Component\Render\MarkupInterface $value
* A placeholder replacement value. Will recursively escape array values
* using the specified separator.
*
* @return string
* The properly escaped replacement value.
*/
protected function escapeValues($value) {
if (is_array($value)) {
$escaped = [];
foreach ($value as $child_value) {
$escaped[] = $this
->escapeValues($child_value);
}
return implode($this->separator, $escaped);
}
return $value instanceof MarkupInterface ? (string) $value : Html::escape($value);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NameListFormattableMarkup:: |
protected | property | The names. | |
NameListFormattableMarkup:: |
protected | property | The name separator. | |
NameListFormattableMarkup:: |
protected | function | Escapes values if needed. | |
NameListFormattableMarkup:: |
public | function | ||
NameListFormattableMarkup:: |
public | function | Constructor for NameListFormattableMarkup. | |
NameListFormattableMarkup:: |
public | function |
Returns markup. Overrides MarkupInterface:: |