8 – How to add Open Graph Tags in Custom Module detail page?

For Node I already used https://www.drupal.org/project/metatag

For my custom module’s detail page would like to add Open Graph tags for FB share.

So in my_test.module

function template_preprocess_my_detail_page(&$variables) {

  $items = $variables('item');

  $title =  $items->title;

  $og_title = (
        '#tag' => 'meta',
        '#attributes' => (
          'property' => 'og:title',
          'content' => $title,
        ),
      );

  $variables('page')('#attached')('html_head')() = ($og_title, 'og_title');
}

Above one suppose to work but NOT WORKING.

function MY_MODULE_page_attachments_alter(array &$page) {

  $og_title = (
        '#tag' => 'meta',
        '#attributes' => (
          'property' => 'og:title',
          'content' => '',
        ),
      );


  $page('#attached')('html_head')() = ($og_title, 'og_title');
}

Above one is working, But I’m not able to get Page Variables. How will I get $variables in above function?

This one called in all pages of module, but I want to call only on detail page as mentioned in proprocess function