I'm attempting to set a label in a macro(?) I created with a new command. I'm passing several values to the command in the first argument via pgfkeys, but the \label macro is just using the literal string I've put in to expand the pgfkey instead of the actual expanded value.
I've tried both of the solutions presented in these answers, together and separately, but not luck.
https://tex.stackexchange.com/a/308164
https://tex.stackexchange.com/a/125099
I've an inkling that what's happening is related to the timing of the expansion for the pgfkey value, but I'll be honest I don't have a firm understanding of how the underlying tex engine does it's magic. I'm also just learning pgfkeys so my understanding of what's happening there is still at a beginner level.
Here's my mwe of what I'm trying to do:
\documentclass[twocolumn]{book}
\usepackage[framemethod=TikZ]{mdframed}%boxes
\usepackage{pgfkeys}
\newcounter{myCounter}
\newmdenv[%
frametitlebackgroundcolor=blue,
frametitlefontcolor=white,
backgroundcolor=blue!25,
linecolor=blue,
outerlinewidth=1pt,
roundcorner=1mm,
skipabove=\baselineskip,
skipbelow=\baselineskip,
font=\small,
nobreak=true,
settings={\global\refstepcounter{myCounter}},
]{myTextBox}
%Define Macros
\makeatletter
\pgfkeys{/mykeys/textbox/.cd,
title/.initial=,
body/.initial=,
label/.initial=,
}
\def\mykeys@set@textbox@keys#1{%%
\pgfkeys{/mykeys/textbox/.cd,#1}}
\def\mykeys@get@textbox#1{%%
\pgfkeysvalueof{/mykeys/textbox/#1}}
\newcommand\myBox[1]{%%
\bgroup
\mykeys@set@textbox@keys{#1}%%
\begin{myTextBox}[frametitle=\textbf{\mykeys@get@textbox{title}\hfill NOTE}]
\mykeys@get@textbox{body}
\label{box:\mykeys@get@textbox{label}}
\end{myTextBox}
\egroup
}
\makeatother
\begin{document}
\section{A Section}
\myBox{
title=Box Title,
body=A not so long string of text to go in the box,
label=firstbox
}
\ref{firstbox}
\end{document}
Here's my current result:
I'm not tied to a particular solution (I would prefer a solution that works with pgfkeys) as long as I can get labels and references working properly.

box:firstbox?\ref{box:firstbox}gives 1. But\ref{firstbox}is undefined because you've never created such a label. – David Purton Mar 14 '19 at 02:59