I want to write the contents of an environment to the document and the toc. Here's a MWE hacked to look (almost) like what I need.
\documentclass[pdftex,12pt]{book}
\usepackage{hyperref}
\newenvironment{g}
{}
{\newline}
\begin{document}
\tableofcontents{}
\chapter{First}
\begin{g}
first goal first chapter
\addcontentsline{toc}{section}{first goal first chapter}
%\addtocontents{toc}{first goal first chapter} %% yields error message
\end{g}
\begin{g}
second goal first chapter
\addcontentsline{toc}{section}{second goal first chapter}
\end{g}
Chapter contents here \ldots
\chapter{Second}
\begin{g}
first goal second chapter
\addcontentsline{toc}{section}{first goal second chapter}
\end{g}
Chapter contents here \ldots
\end{document}
That produces this toc:

What I'd like is this (with no hyperref links for the extra lines):

Problems I don't know how to solve:
Most important: how can I capture the write twice behavior in the environment definition so that I don't have to specify the extra toc line with cut and paste each time?
Secondary: Why does
\addtocontentsproduce an error when commented in? (An answer to this might solve the entry formatting and link problem.)
I can use the xparse package to define the environment if that makes for an easier solution.
environpackage gives you access to the body of the environment using a macro\BODY. You could use that to write the TOC line in the start or end code of the environment. – Scott H. Jun 21 '12 at 18:59addtocontentserror continues. You can post this as an answer I'd vote up, but not accept quite yet. – Ethan Bolker Jun 21 '12 at 19:37