function LinkResolvableUriComputed::setValue
Same name and namespace in other branches
- main core/modules/link/src/Plugin/DataType/LinkResolvableUriComputed.php \Drupal\link\Plugin\DataType\LinkResolvableUriComputed::setValue()
Overrides PrimitiveBase::setValue
File
-
core/
modules/ link/ src/ Plugin/ DataType/ LinkResolvableUriComputed.php, line 45
Class
- LinkResolvableUriComputed
- Defines a data type for a Link Resolvable URI.
Namespace
Drupal\link\Plugin\DataTypeCode
public function setValue($value, $notify = TRUE) : void {
if (!empty($value)) {
$parsed = UrlHelper::parse($value);
// If the path is not an external URL then add 'internal:' prefix to make
// it a valid uri.
if (strpos($parsed['path'], ':') === FALSE) {
$parsed['path'] = 'internal:' . $parsed['path'];
}
$url = Url::fromUri($parsed['path'], [
'query' => $parsed['query'],
'fragment' => $parsed['fragment'],
]);
$this->processed = $url->toString(TRUE);
}
else {
$this->processed = NULL;
}
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.