Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass options to generateAttribute() to allow for raw options instead of <ul> #1558

Closed
Toflar opened this issue Oct 21, 2015 · 4 comments
Closed
Milestone

Comments

@Toflar
Copy link
Member

Toflar commented Oct 21, 2015

The template helper generateAttribute() should allow to pass an optional noHtml or so param for option attributes.

Right now when you have a multiple select and you go for echo $this->generateAttribute('select_field') it will output a <ul> formatted list. However, what if I want to display something else than the <ul> list with it?
Of course you can get the raw values using $this->select_field but you would need to call deserialize() in combination with haste utilities. So in the easiest case you have to write something like this:

$options = deserialize($this->select_field, true);

foreach ($options as &$v) {
    $v = \Haste\Util\Format::dcaValue('tl_iso_product', 'select_field', $v);
}

// Output every value with it's label here now.

I'd prefer to have something like this;

foreach ($this->generateAttribute('select_field', ['noHtml' => true]) {
     // Output every value with it's label here now.
}

This would make the template a whole lot more consistent.
Why noHtml and not raw or something else? Well, prepared labels are not raw either, right? The equivalent of raw would be $this->select_field but what I want is everything except for the automated html markup. So, noHtml but I'm open for input :-)

@Toflar Toflar added this to the 2.3.2 milestone Oct 21, 2015
@aschempp
Copy link
Member

Here are a few suggestions, what should we use?

  • noHtml
  • raw
  • noList

@Toflar
Copy link
Member Author

Toflar commented Oct 25, 2015

I'd go for noHtml but would accept noList as well. Just not raw.

@Toflar
Copy link
Member Author

Toflar commented Nov 10, 2015

Please reopen, the options should get their values, not just the labels.

If you use the options wizard and enter something like

Key Label
key_1 Label 1
key_2 Label 2

The following code

var_dump($this->generateAttribute('select_field', ['noHtml' => true]));

now produces this

array(2) { [0]=> string(7) "Label 1" [1]=> string(7) "Label 2" }

You only get the labels now, not the values anymore and you need to manually assign the label to the keys again.
To be more convenient, it should produce either this:

array(2) { ["key_1"]=> string(7) "Label 1" ["key_2"]=> string(7) "Label 2" }

or even this (to support more attributes and not only regular key->value):

array(2) { [0]=> array(2) { ["key"]=> string(5) "key_1" ["label"]=> string(7) "Label 1" } [1]=> array(2) { ["key"]=> string(5) "key_2" ["label"]=> string(7) "Label 2" } }

@aschempp
Copy link
Member

I have updated the code to correctly return key-value pairs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants