8 - How to Get Values From $variables hook_preprocess_commerce_order_receipt? So thankful for all the help on here, but still so baffled as to how Im not able to just quickly determine how to pull these values out of certain arrays and objects.

Trying to get the order id (and other values) from the frickin $variables array in hook_preprocess_hook

Code
afc.theme

function afc_preprocess_commerce_order_receipt(&amp;$variables) {
  dpm($variables['order_entity']);
  \Drupal::logger('afc_theme')-&gt;notice('running');
}


Some of the Output

stdClass Object
(
    [__CLASS__] =&gt; Drupal\commerce_order\Entity\Order
    [values:protected] =&gt; Array
        (
            [order_id] =&gt; Array
                (
                    [x-default] =&gt; 182
                )

            [type] =&gt; Array
                (
                    [x-default] =&gt; default
                )

            [uuid] =&gt; Array
                (
                    [x-default] =&gt; c8b1c210-0e6e-4efb-a59d-84b28d4dadfe
                )

            [order_number] =&gt; Array
                (
                    [x-default] =&gt; 
                )

            [store_id] =&gt; Array
                (
                    [x-default] =&gt; 1
                )

            [uid] =&gt; Array
                (
                    [x-default] =&gt; Array
                        (
                            [0] =&gt; Array
                                (
                                    [target_id] =&gt; 1
                                )

                        )

                )


Ive tried various wrong things like:

$variables['order_entity'] = $order;
dpm($order-&gt;get("order_id")-&gt;getValue());
dpm($variables-&gt;get("order_id")-&gt;getValue());
dpm($variables['order_entity']['order_id'];


1. How do I get the order_id from this $variables object?

2. How/where did you find this information telling you how to get this value out?
How do I get the order_id from this $variables object?


All entities have an id method, inherited (or perhaps overridden) from Entity::id. From your debug output $variables['order_entity'] appears to be one such entity, so:

$order_id = $variables['order_entity']-&gt;id();



  How/where did you find this information telling you how to get this value out?


Short answer, in the source and the docs (following/finding isn't always straightforward though). For example if you've read the Introduction to Entity API in Drupal 8, you'll intuitively know that a Drupal\commerce_order\Entity\Order is an entity type, both by the folder structure and its annotation, and you can start thinking about how to address an object of that type in more generic terms. 

That leads to searches like "Drupal 8 get entity id" or "Drupal 8 get entity field value programatically", and Google will dutifully tell you everything you need to know.

If you can spare a bit of time to follow the class hierarchy up the chain, and get at least a broad idea of what each class does and how it works, that will probably take some pain out of future encounters with the entity API too.