Retrieve URL info in Smart Link field

We want to be able to enter a URL and get retrieve info from the page to use elsewhere in the Drupal site.

Massage Form Values

WidgetInterface has massageFormValues() to get values from the form. It may be more appropriate to use a form submit handler, but this will do for now.

  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach ($values as &$value) {
      if (!empty($value['url'])) {
        $smart_link_info = smart_link_get_info($value['url']);
        $value['domain'] = $smart_link_info['domain'];
        $value['path'] = $smart_link_info['path'];
        $value['title'] = $smart_link_info['title'];
        $value['description'] = $smart_link_info['description'];
        $value['h1'] = $smart_link_info['h1'];
      }
    }
    return $values;
  }

Here is the formatter showing values for Drupal.org modules.

Drupal Smart Link field formatter