<p dir="auto"><strong>Description</strong><br>
For structuring Yaml files we want to use a custom include tag (in our case <code class="notranslate">!inc/file 'my_file.yml'</code>). This is working just fine by having a custom <code class="notranslate">YamlFileLoader</code> that recursively parses any <code class="notranslate">TaggedValue</code> and having it make a <code class="notranslate">new Parser()</code> to handle the sub-document (or <code class="notranslate">self::load()</code> on the sub-document).</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$loaderResolver = new LoaderResolver([new YamlFileLoader()]);
$delegatingLoader = new DelegatingLoader($loaderResolver);
$config = $delegatingLoader-&gt;load('my-base.yml');"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>loaderResolver</span> = <span class="pl-k">new</span> <span class="pl-v">LoaderResolver</span>([<span class="pl-k">new</span> <span class="pl-v">YamlFileLoader</span>()]);
<span class="pl-s1"><span class="pl-c1">$</span>delegatingLoader</span> = <span class="pl-k">new</span> <span class="pl-v">DelegatingLoader</span>(<span class="pl-s1"><span class="pl-c1">$</span>loaderResolver</span>);
<span class="pl-s1"><span class="pl-c1">$</span>config</span> = <span class="pl-s1"><span class="pl-c1">$</span>delegatingLoader</span>-&gt;<span class="pl-en">load</span>(<span class="pl-s">'my-base.yml'</span>);</pre></div>
<p dir="auto">But if your parent document has references, e.g.: <code class="notranslate">&amp;foo</code> and you want to reference that within an included file with <code class="notranslate">*foo</code>, the sub-parser has no access to the refs from the main document.</p>
<p dir="auto">At least two ways to solve it:</p>
<ol dir="auto">
<li>a way to pass refs to a parser</li>
<li>don't make a new parser, but calling <code class="notranslate">parse()</code> on the same instance as the parent document</li>
</ol>
<p dir="auto">Here option 2 seems a nice solution, but: <code class="notranslate">parse()</code> sets <code class="notranslate">$this-&gt;refs = []</code> before and after every call to <code class="notranslate">doParse()</code>.</p>
<p dir="auto">The feature request is to either support option 1, or a flag (e.g.: <code class="notranslate">Yaml::PARSE_KEEP_REFS</code>) that disables setting <code class="notranslate">$this-&gt;refs = []</code> before and after every call to <code class="notranslate">doParse()</code>.</p>
<p dir="auto"><strong>Example</strong></p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const PARSE_KEEP_REFS = 2048;

/**
 * Parses a YAML string to a PHP value.
 *
 * @param string $value A YAML string
 * @param int    $flags A bit field of PARSE_* constants to customize the YAML parser behavior
 *
 * @return mixed A PHP value
 *
 * @throws ParseException If the YAML is not valid
 */
public function parse(string $value, int $flags = 0)
{
    if (false === preg_match('//u', $value)) {
        throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this-&gt;filename);
    }

    if (!(Yaml::PARSE_KEEP_REFS &amp; $flags)) {
        $this-&gt;refs = [];
    }

    $mbEncoding = null;
    $data = null;

    if (2 /* MB_OVERLOAD_STRING */ &amp; (int) ini_get('mbstring.func_overload')) {
        $mbEncoding = mb_internal_encoding();
        mb_internal_encoding('UTF-8');
    }

    try {
        $data = $this-&gt;doParse($value, $flags);
    } finally {
        if (null !== $mbEncoding) {
            mb_internal_encoding($mbEncoding);
        }
        $this-&gt;lines = [];
        $this-&gt;currentLine = '';
        if (!(Yaml::PARSE_KEEP_REFS &amp; $flags)) {
            $this-&gt;refs = [];
        }
        $this-&gt;skippedLineNumbers = [];
        $this-&gt;locallySkippedLineNumbers = [];
    }

    return $data;
}"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-c1">PARSE_KEEP_REFS</span> = <span class="pl-c1">2048</span>;

<span class="pl-c">/**</span>
<span class="pl-c"> * Parses a YAML string to a PHP value.</span>
<span class="pl-c"> *</span>
<span class="pl-c"> * @param string $value A YAML string</span>
<span class="pl-c"> * @param int    $flags A bit field of PARSE_* constants to customize the YAML parser behavior</span>
<span class="pl-c"> *</span>
<span class="pl-c"> * @return mixed A PHP value</span>
<span class="pl-c"> *</span>
<span class="pl-c"> * @throws ParseException If the YAML is not valid</span>
<span class="pl-c"> */</span>
<span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">parse</span>(<span class="pl-smi">string</span> <span class="pl-s1"><span class="pl-c1">$</span>value</span>, <span class="pl-smi">int</span> <span class="pl-s1"><span class="pl-c1">$</span>flags</span> = <span class="pl-c1">0</span>)
{
    <span class="pl-k">if</span> (<span class="pl-c1">false</span> === preg_match(<span class="pl-s">'//u'</span>, <span class="pl-s1"><span class="pl-c1">$</span>value</span>)) {
        <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">ParseException</span>(<span class="pl-s">'The YAML value does not appear to be valid UTF-8.'</span>, -<span class="pl-c1">1</span>, <span class="pl-c1">null</span>, <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">filename</span>);
    }

    <span class="pl-k">if</span> (!(<span class="pl-v">Yaml</span>::<span class="pl-c1">PARSE_KEEP_REFS</span> &amp; <span class="pl-s1"><span class="pl-c1">$</span>flags</span>)) {
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">refs</span> = [];
    }

    <span class="pl-s1"><span class="pl-c1">$</span>mbEncoding</span> = <span class="pl-c1">null</span>;
    <span class="pl-s1"><span class="pl-c1">$</span>data</span> = <span class="pl-c1">null</span>;

    <span class="pl-k">if</span> (<span class="pl-c1">2</span> <span class="pl-c">/* MB_OVERLOAD_STRING */</span> &amp; (<span class="pl-smi">int</span>) ini_get(<span class="pl-s">'mbstring.func_overload'</span>)) {
        <span class="pl-s1"><span class="pl-c1">$</span>mbEncoding</span> = mb_internal_encoding();
        mb_internal_encoding(<span class="pl-s">'UTF-8'</span>);
    }

    <span class="pl-k">try</span> {
        <span class="pl-s1"><span class="pl-c1">$</span>data</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">doParse</span>(<span class="pl-s1"><span class="pl-c1">$</span>value</span>, <span class="pl-s1"><span class="pl-c1">$</span>flags</span>);
    } <span class="pl-k">finally</span> {
        <span class="pl-k">if</span> (<span class="pl-c1">null</span> !== <span class="pl-s1"><span class="pl-c1">$</span>mbEncoding</span>) {
            mb_internal_encoding(<span class="pl-s1"><span class="pl-c1">$</span>mbEncoding</span>);
        }
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">lines</span> = [];
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">currentLine</span> = <span class="pl-s">''</span>;
        <span class="pl-k">if</span> (!(<span class="pl-v">Yaml</span>::<span class="pl-c1">PARSE_KEEP_REFS</span> &amp; <span class="pl-s1"><span class="pl-c1">$</span>flags</span>)) {
            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">refs</span> = [];
        }
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">skippedLineNumbers</span> = [];
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">locallySkippedLineNumbers</span> = [];
    }

    <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span>data</span>;
}</pre></div>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$configValues = $parser-&gt;parseFile($resource, Yaml::PARSE_CUSTOM_TAGS|Yaml::PARSE_KEEP_REFS);"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>configValues</span> = <span class="pl-s1"><span class="pl-c1">$</span>parser</span>-&gt;<span class="pl-en">parseFile</span>(<span class="pl-s1"><span class="pl-c1">$</span>resource</span>, <span class="pl-v">Yaml</span>::<span class="pl-c1">PARSE_CUSTOM_TAGS</span>|<span class="pl-v">Yaml</span>::<span class="pl-c1">PARSE_KEEP_REFS</span>);</pre></div>
<p dir="auto">Of course it's very possible there is a completely other solution that I missed. Since pretty much everything is private, extending the class with your own parser brings too much to the table.</p>
<p dir="auto">PS: using Symfony config import (<a href="https://symfony.com/doc/current/configuration/configuration_organization.html#mix-and-match-configuration-formats" rel="nofollow">https://symfony.com/doc/current/configuration/configuration_organization.html#mix-and-match-configuration-formats</a>) is not applicable for our use case. We need something more in the line of the <code class="notranslate">$ref</code> method of json-schema.</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>4.1</td>
</tr>
</tbody>
</table>
<p dir="auto">This is a <a href="https://www.google.sk/search?client=ubuntu&amp;channel=fs&amp;q=symfony+form+render+multiple+times&amp;ie=utf-8&amp;oe=utf-8&amp;gfe_rd=cr&amp;dcr=0&amp;ei=szCpWvGNEuvf8geps6z4CA" rel="nofollow">common problem</a>. Only workarounds exists is not using form_* functions for subsequent fields.</p>
<p dir="auto">Wanted to solve this by doing</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{{ form_row(form.save) }}
{% do form.save.setRendered(false) %}
{{ form_row(form.save) }}"><pre class="notranslate">{{ form_row(<span class="pl-smi">form</span>.<span class="pl-smi">save</span>) }}
{% <span class="pl-k">do</span> <span class="pl-smi">form</span>.<span class="pl-smi">save</span>.<span class="pl-smi">setRendered</span>(<span class="pl-c1">false</span>) %}
{{ form_row(<span class="pl-smi">form</span>.<span class="pl-smi">save</span>) }}</pre></div>
<p dir="auto">quickly found <a href="https://github.com/ostrolucky/symfony/blob/3c0693de23ea30c1a54ff7179ebf3168e1328793/src/Symfony/Component/Form/FormView.php#L86">setRendered does not accept arguments</a> and PRs for multiple different use cases has been <a href="https://github.com/symfony/symfony/issues/10898" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/10898/hovercard">rejected<sup>1</sup></a> <a href="https://github.com/symfony/symfony/pull/8128" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/8128/hovercard">in<sup>2</sup></a> <a href="https://github.com/symfony/symfony/pull/8676" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/8676/hovercard">past<sup>3</sup></a>. Is this use case good enough for this change now?</p>
<p dir="auto">This is specifically very useful to split form visually to two, where one block is just for RepeatedType and SubmitType. Here was the requirement from our designer</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/496233/37410483-0ade9ef2-27a1-11e8-8574-3726d147a32c.jpg"><img src="https://user-images.githubusercontent.com/496233/37410483-0ade9ef2-27a1-11e8-8574-3726d147a32c.jpg" alt="37027104-b990ff70-2130-11e8-9f2b-469c0a1c2b03" style="max-width: 100%;"></a></p>
<p dir="auto">If I could render same field twice, I could reuse same button field and be done with it.</p>