The 'link element' causes a lot of confusion. As far as I can tell, it's not really documented anywhere. Many people assume it is an element of the Form API and should be documented in the FAPI reference.
The 'link element' is part of the Render API and can be used outside forms as well as inside. So it is fundamentally different from the elements documented in the FAPI reference. But it functions a lot like those and takes many of the same properties.
The two most obvious places to document the 'link element' are:
FAPI reference: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Render API doc: http://drupal.org/node/930760
A good case can be made for either. The Render API doc lists many of the render element properties, and 'link' is part of the Render API. It already mentions this element in passing already.
The 'link element' is often used in forms, and many render element properties are already documented in the FAPI reference. It's also the place many if not most people go to find documentation for it. Putting it here gives the opportunity to explain the difference to those people and refer them to the Render API for further information. Whichever place 'link' finally ends up should include a reference to the other.
At the end of Franz Heinzmann's session on the Render API in Drupal 7 at Drupalcon Chicago, he projected a shared library of reusable interface elements. I'm thinking 'link' is the first of these. If that's true, then this is a larger question than just where to document the 'link element.'
I lean toward putting it in the FAPI reference. Even if render elements are different, they will be often used in forms. I would create a separate area for them, a list under the second table (Special Elements) called Render Elements. With only one element, a full table seems overkill, but could be added later as more elements are created. The full description of the 'link element' would be added to the main element list, linked to the item in the Render Element list (like the form element headers in the table). This list would probably only grow in the D8 version, of course. (I'd be surprised if more render elements are created in D7, but I could be wrong.)
If/when the plans in #100680: [meta] Make API module generate Form API documentation come to fruition, whatever format is developed could take on Render elements as well. But for now, we need a place to put this.
I also need some input on the exact documentation for the 'link element' and its properties. But this is already getting long, so I'll open a second issue for that.
Comments
Comment #1
jn2 commentedHere's intro text for a Render Elements section in the FAPI reference:
"The Form API is a very developed subset of the Render API. Drupal 7 has elements that are properly classified as part of the Render API and that can exist outside the form context. They do not function exactly same as form elements, although there are many similarities and shared properties."
(Of course, in the D8 version, substitute 8 above.)
Comment #2
jn2 commentedThe issue for the specifics of the 'link element' documentation is at #1190720: Documentation for link element.
Comment #3
jhodgdonQuestion: Are there other render-not-form API elements currently in the Form API reference for D7/8?
Comment #4
jn2 commented@jhodgdon
Not that I know of. But that's an excellent question, and one that can hopefully be answered in this issue. I didn't find any others while researching this.
Comment #5
jn2 commented@jhodgdon
Continuing my research into the 'container' element, it's possible it might also be part of the Render API. I didn't think so at first, because form_process_container (http://api.drupal.org/api/drupal/includes--form.inc/function/form_proces...) takes $form_state as an argument.
But theme_container specifically says: "Can also be used as a #theme_wrapper for any renderable element, to surround it with a
Edited:
So this element is an implementation just for forms, since form_process_container takes $form_state.
Comment #6
jhodgdonSo, I'm not really clear on where the boundary is between the Render API and the Form API at all. It seems to me that they are somewhat interchangeable, and we don't have a reference anywhere else for render elements (and if we did, why not put the form elements there too?).... Why again are we trying to separate them, and/or what is the distinction really?
Comment #7
jn2 commentedFrom what I understand, render elements can be used outside forms, form elements must be inside forms only. It would be nice if one of the render experts would stop by and explain further.
Comment #8
jhodgdonI guess that anything that HTML recognizes as a form input element is pretty clear (those ones collect information entered by users who view the form and then submit it), and I you do need the form processing functions to be run on those elements in order to get the data displayed and collected correctly.
But with that definition, #markup is not an FAPI element, right? There are probably others in the FAPI doc that aren't... but I don't think we would want to remove #markup from the doc, because people should know how to include non-form-element markup? It's all a bit murky what should be there and what shouldn't...
Comment #9
sunIndeed, there's no easy differentiation currently.
You can identify most (but not all) Form API elements by whether the element defines
#input. Only form elements get #input.The other notable difference is
#processand#after_build, because only Form API invokes those callbacks.#markuphistorically was just simply#valuebefore (without specifying a#type) in order to allow forms to output arbitrary HTML somewhere. But since#valuehas a mission-critical meaning for all regular/other form elements, we changed the edge-case usage to the explicit#markup.Comment #10
sutharsan commentedThis discussion does not only apply to 'link'. I made a list of all render array types not yet documented in the Form API reference: #2220415: Document new D8 Form API elements
Comment #11
jhodgdonComment #12
jhodgdonFor Drupal 8, we are now documenting form/render elements and their specific properties on the element classes. See #2486967: [meta] Move/Create Form Element Documentation
and child issues. The link element is on one of those child issues.
We could leave this open for Drupal 7; however, for Drupal 7 I don't think we really want to make the Form API reference be the Form and Render API reference. It would be a huge amount of work and I don't think it's going to happen.
So marking this as a duplicate of the Drupal 8 documentation effort that is already underway.