function LinkItem::onChange
Same name and namespace in other branches
- 11.x core/modules/link/src/Plugin/Field/FieldType/LinkItem.php \Drupal\link\Plugin\Field\FieldType\LinkItem::onChange()
Parameters
string $property_name: The name of the property.
bool $notify: (optional) Whether to forward the notification to the parent. Defaults to TRUE. By passing FALSE, overrides of this method can re-use the logic of parent classes without triggering notification.
Overrides Map::onChange
1 call to LinkItem::onChange()
- LinkItem::setValue in core/
modules/ link/ src/ Plugin/ Field/ FieldType/ LinkItem.php
File
-
core/
modules/ link/ src/ Plugin/ Field/ FieldType/ LinkItem.php, line 186
Class
- LinkItem
- Plugin implementation of the 'link' field type.
Namespace
Drupal\link\Plugin\Field\FieldTypeCode
public function onChange($property_name, $notify = TRUE) : void {
// Make sure that the link item values can be kept in sync with computed
// property url.
if ($property_name === 'resolvable_uri') {
$property = $this->get('resolvable_uri');
if ($url = $property->getValue()) {
$parsed = UrlHelper::parse($url);
// 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'];
}
$this->writePropertyValue('uri', $parsed['path']);
// Only set the options if we have query parameters or a fragment.
if (!empty($parsed['query']) || !empty($parsed['fragment'])) {
$this->writePropertyValue('options', [
'query' => $parsed['query'],
'fragment' => $parsed['fragment'],
]);
}
}
}
parent::onChange($property_name, $notify);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.