How can I place an entity content field value in header markup?
The essence of the problem is how to move a value from the field template preprocess to the html theme preprocess. I did this by using a one-off static variable function, provided by a helper module:

/*
 * Generates a static variable in the scope of the page request
 * to set instantiate like
 *  $var = &amp;p2p_helpers_ogimage_function(); $var = 'my value';
 *    to read the var,
 *   instantiate without.
 */
function &amp;p2p_helpers_ogimage_function() {
  $var = &amp;drupal_static(__FUNCTION__);
 if (!isset($var)) {
    // generate contents of static variable
    $var = NULL;
  }
  return $var;
}


Then I can do the rest in the THEME.theme file. 

In the field template preprocess hook I can do this:

/**
 * Prepares variables for blazy.html.twig templates.
 */
function p2p_bootstrap_preprocess_blazy(&amp;$variables) {
  $url = p2p_helpers_ogimage_function();
  if (!$url) {
    $url = &amp;p2p_helpers_ogimage_function();
    $url = $variables['url'];
  }
  ...


This will fill check if the variable is already set, so it only sets it once for the first image in the field. 

Then in hook_preprocess_html: 

$url = p2p_helpers_ogimage_function();
if ($url) {
  $ogimage = [
    '#tag' =&gt; 'meta',
    '#attributes' =&gt; [
      'property' =&gt; 'og:image:secure_url',
      'content' =&gt; $url,
    ],
  ];

  $variables['page']['#attached']['html_head'][] = [$ogimage, 'og:image'];
}


Does anyone see any better way to do this?