/** * Returns element options as HTML elements * * @return array List of options as HTML elements */ public function getOptionsAsElements() { $elements = []; $value = $this->getValue(); $options = $this->config->get('options') ?: []; foreach ($options as $key => $option) { $config = ['text' => $option['label'], 'attrs.name' => $this->getName(), 'attrs.value' => $option['value']]; $option_is_current = is_array($value) && in_array($option['value'], $value) || $option['value'] === $value ? true : false; if ($option_is_current || $option['selected']) { $config['attrs']['selected'] = true; } $elements[] = Html::Option($config); } return $elements; }
public function __construct() { $this->el = Html::form(); $this->children = new Collection(); $this->data = new Collection(); }
/** * Renders content list * * @return object This class instance */ public function render() { // Set custom attributes $this->el->setAttrs($this->config->get('attrs')); // Remove custom attributes from config $this->config->remove('attrs'); // Set container attributes $this->el->setAttr('bebop-media--el', 'container'); $this->el->setAttr('bebop-media--config', htmlentities(json_encode($this->config->getAll()))); // Append input element $input = Html::Input(); $input->setAttr('type', 'hidden'); $input->setAttr('name', $this->config->get('field_name')); $input->setAttr('value', $this->config->get('data')); $this->el->prepend($input); // Render $this->el->render(); return $this; }