Comments

steveoliver’s picture

Status: Active » Needs work
StatusFileSize
new1.89 KB

I tried {% autoescape false %} around {{ options }} in select.twig, but that didn't help the options HTML string to be printed. The variable is being set in template_preprocess_select, but for some reason, they are not being rendered in the .twig template.

I started a twig_forms module on github. Test path: '/twig-forms'.

Patch attached.

steveoliver’s picture

Title: select.twig » Convert theme_select to select.twig

Changing issue title.

KrisBulman’s picture

Your preprocess function should read:

function template_preprocess_select(&$variables) {
...
}

Variables have to be passed by reference, as indicated by the ampersand. This is why the variables being set in your preprocess function are not being rendered in your twig template.

steveoliver’s picture

Ah! I forgot to add & when copying from the theme function. Thanks!

steveoliver’s picture

Status: Needs work » Needs review
StatusFileSize
new1.89 KB

Sho 'nuff! RTBC?

steveoliver’s picture

I added a note to the conversion docs with this point:

Remember to pass the variables by reference. i.e. theme_select($variables) becomes template_preprocess_select(&$variables).

;)

steveoliver’s picture

StatusFileSize
new1.82 KB

Removed test attribute and unnecessary comments in preprocess.

fabianx’s picture

+++ b/core/includes/form.incundefined
@@ -2672,6 +2672,25 @@ function theme_select($variables) {
+  if (isset($element['#attributes'])) {
+    $variables['attributes'] = new Attribute($element['#attributes']);
+  }

$variables['attributes'] should _always_ be set.

So start with:

$variables['attributes'] = new Attribute(array());
if (isset(..

steveoliver’s picture

StatusFileSize
new1.63 KB

$variables['attributes'] is now always set. Also removed irrelevant comment from select.twig docblock.

jwilson3’s picture

Documentation feedback:

+ * Returns HTML for a select form element.
+ *
+ * Variables
+ *   - attributes: an array of attributes including 'class', 'id', and 'width'.
+ *   - options: the HTML for the list of select options.
+ *

Replace "Returns HTML" with "Default theme implementation". (I've just clarified this in the conversion instructions doc).

Replace "Variables" with "Available variables:"

Outdent the variables themselves (eg "- attributes") so the dash lines up one space away from the asterisk (*).

podarok’s picture

Status: Needs review » Needs work

due to #10 need work

steveoliver’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB

There we go. I can commit it when it's RTBC.

jwilson3’s picture

diff --git a/core/themes/stark/templates/form.inc/select.twig b/core/themes/stark/templates/form.inc/select.twig
new file mode 100644
index 0000000..15b0246
--- /dev/null
+++ b/core/themes/stark/templates/form.inc/select.twig

This is more for my own understanding than a critique of the work, but assuming this is going to be committed to the front-end branch, shouldn't this be select.html.twig per the current instructions? I know the theme engine branch is using something else, but I'm not clear on what the current plan/process is for when these two things will be merged to work together.

steveoliver’s picture

jwilson3, you're right -- it now does need to be select.html.twig.

steveoliver’s picture

jwilson3’s picture

steve, youre going to hate me, for not getting all this feedback in a single post. Sorry :(

<code>
+ * Preprocess select form element variables.
+ *
+ * @param $variables
+ *   An associative array containing:
+ *   - element: An associative array containing the properties of the element.
+ *     Properties used: #title, #value, #options, #description, #extra,
+ *     #multiple, #required, #name, #attributes, #size.
+ */

Are we supposed to include @see twig-template.html.twig in the preprocess functions we add? Not sure if this is in the conversion doc or not, but seems to make sense.

podarok’s picture

#15 looks good
#16 as for me - it is good practice for documentation here

#1806066-15: Convert theme_select to select.twig commited/push to front-end

Thanks!

podarok’s picture

Status: Needs review » Fixed

status

steveoliver’s picture

Cool. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 1750250)