base.html.php
3 years ago
checkbox.html.php
4 years ago
file.html.php
4 years ago
hidden.html.php
4 years ago
html.html.php
4 years ago
label-content.html.php
4 years ago
label.html.php
4 years ago
radio.html.php
4 years ago
select.html.php
4 years ago
textarea.html.php
4 years ago
select.html.php
50 lines
| 1 | <?php |
| 2 | /** @var Give\Framework\FieldsAPI\Select $field */ ?> |
| 3 | <?php |
| 4 | /** @var string $fieldIdAttribute */ ?> |
| 5 | |
| 6 | <select |
| 7 | name="<?php |
| 8 | echo $field->getName(); ?><?php |
| 9 | echo $field->getAllowMultiple() ? '[]' : ''; ?>" |
| 10 | id="<?php |
| 11 | echo $fieldIdAttribute; ?>" |
| 12 | <?php |
| 13 | echo $field->getAllowMultiple() ? 'multiple' : ''; ?> |
| 14 | <?php |
| 15 | echo $field->isRequired() ? 'required' : ''; ?> |
| 16 | <?php |
| 17 | echo $field->isReadOnly() ? 'readonly' : ''; ?> |
| 18 | > |
| 19 | <?php |
| 20 | if ($placeholder = $field->getPlaceholder()) { |
| 21 | printf( |
| 22 | '<option value="" %2$s %3$s>%1$s</option>', |
| 23 | $placeholder, |
| 24 | $field->isRequired() ? 'disabled' : '', |
| 25 | $field->getDefaultValue() ? '' : 'selected' |
| 26 | ); |
| 27 | } |
| 28 | ?> |
| 29 | <?php |
| 30 | foreach ($field->getOptions() as $option) : ?> |
| 31 | <?php |
| 32 | $value = esc_attr($option->getValue()); |
| 33 | $label = $option->getLabel(); |
| 34 | $default = $field->getAllowMultiple() ? |
| 35 | in_array($option->getValue(), $field->getDefaultValue()) : |
| 36 | $field->getDefaultValue() === $option->getValue(); |
| 37 | ?> |
| 38 | <option |
| 39 | <?php |
| 40 | echo $label ? "value=\"$value\"" : ''; ?> |
| 41 | <?php |
| 42 | echo $default ? 'selected' : ''; ?> |
| 43 | > |
| 44 | <?php |
| 45 | echo $label ?: $value; ?> |
| 46 | </option> |
| 47 | <?php |
| 48 | endforeach; ?> |
| 49 | </select> |
| 50 |