Get domain from a URL field I have a link field in a content type, field_source. I created a computed field (field_source_domain) in the same content type, which should contain the domain for the link in field_source.

I tried with $value = parse_url('https://subdomain.example.com/foo/bar', PHP_URL_HOST); and it works, but when I tried $value = parse_url('$entity-&gt;field_source-&gt;value', PHP_URL_HOST); or $value = parse_url('$fields['field_source']', PHP_URL_HOST);, I didn't get anything.

How do I get the domain name using a computed field?
I found the solution to my problem: 

$field_source = $entity-&gt;get('field_source')-&gt;getValue();
$url_link = $field_source[0]['uri'];
$parse = parse_url($url_link);
$value = $parse['host'];