public function testGetSelectOptions() { $select = $this->former->select('foo')->options($this->options); foreach ($this->options as $key => $option) { $options[$key] = Element::create('option', $option, array('value' => $key)); } $this->assertEquals($select->getOptions(), $options); }
/** * Create a label element from a string * * @param string $label * @param string $field * * @return Element */ protected function createLabel($label, $field = null) { if ($label instanceof Element) { $label = $label->getValue(); } $label = Helpers::translate($label); $label = Element::create('label', $label)->for($field ?: strtolower($label)); $label->addClass($this->app['former.framework']->getLabelClasses()); return $label; }
/** * @return string */ public function render() { $label = Element::label($this->label)->for($this->id); if ($this->inputCheckable) { $p = Element::create($this->container)->nest(['field' => parent::render(), 'label' => $label, 'close' => '<br>']); } else { $p = Element::create($this->container)->nest(['label' => $label, 'field' => parent::render()]); } return $p->render(); }
/** * @param string|array $_choice * @param string $_value * * @return $this */ public function addChoice($_choice, $_value = null) { if (is_array($_choice)) { $text = array_get($_choice, 'label'); $value = array_get($_choice, 'value'); $atts = array_except($_choice, ['label']); } else { $text = $_choice; $value = is_null($_value) ? $_choice : $_value; $atts = ['value' => $value]; } $choice = Element::create('option', $text); $choice->setAttributes($atts); if ($this->isSelected($value)) { $choice->setAttribute('selected', 'selected'); } $this->choices->push($choice); return $this; }
/** * Add an option to the Select's options * * @param array|string $text It's value or an array of values * @param string $value It's text * @param array $attributes The option's attributes */ public function addOption($text = null, $value = null, $attributes = array()) { // Get the option's value $childrenKey = !is_null($value) ? $value : sizeof($this->children); // If we passed an options group if (is_array($text)) { $this->children[$childrenKey] = Element::create('optgroup')->label($value); foreach ($text as $key => $value) { $option = Element::create('option', $value)->setAttribute('value', $key); $this->children[$childrenKey]->nest($option); } // Else if it's a simple option } else { if (!isset($attributes['value'])) { $attributes['value'] = $value; } $this->children[$attributes['value']] = Element::create('option', $text)->setAttributes($attributes); } return $this; }
/** * Wrap an item to be prepended or appended to the current field * * @param string $item * * @return Element A wrapped item */ public function placeAround($item) { return Element::create('span', $item); }
/** * Creates a form legend * * @param string $legend The text * @param array $attributes Its attributes * * @return Element A <legend> tag */ public function legend($legend, $attributes = array()) { $legend = Helpers::translate($legend); return Element::create('legend', $legend, $attributes); }
/** * Wrap the value in a tag. * * @param string $tag The tag * * @return $this */ public function wrapValue($tag) { $this->value = Element::create($tag, $this->value); return $this; }
/** * Wraps all field contents with potential additional tags. * * @param Field $field * * @return Element A wrapped field */ public function wrapField($field) { if ($this->app['form.form']->isOfType('horizontal')) { return Element::create('div', $field)->addClass($this->fieldWidth); } else { return $field; } }
<?php defined('C5_EXECUTE') or die("Access Denied."); $tag = \HtmlObject\Element::create('amp-youtube'); $tag->setAttribute('data-videoid', h($videoID)); $tag->setAttribute('layout', 'responsive'); $width = $vWidth ? $vWidth : '480'; $height = $vHeight ? $vHeight : '270'; $tag->setAttribute('width', h($width)); $tag->setAttribute('height', h($height)); echo $tag;
public function testCanCreateDefaultElement() { $this->assertHTML($this->getMatcher(), Element::create()->setValue('foo')); }
/** * Render an icon * * @param array $attributes Its general attributes * * @return string */ public function createIcon($iconType, $attributes = array(), $iconSettings = array()) { // Check for empty icons if (!$iconType) { return false; } // icon settings can be overridden for a specific icon $tag = array_get($iconSettings, 'tag', $this->iconTag); $set = array_get($iconSettings, 'set', $this->iconSet); $prefix = array_get($iconSettings, 'prefix', $this->iconPrefix); return Element::create($tag, null, $attributes)->addClass("{$set} {$prefix}-{$iconType}"); }
/** * Adds a label to the group * * @param string $label A label */ public function setLabel($label) { if (!$label instanceof Element) { $label = Helpers::translate($label); $label = Element::create('label', $label)->for($label); } $this->label = $label; }
/** * Get the evaluated string content of the ItemList. * * @param integer $depth The depth at which the ItemList should be rendered * * @return string */ public function render($depth = 0) { if (!is_int($depth)) { throw new Exception("The render method doesn't take any arguments anymore, you can now configure your menu via the config file."); } // Check for maximal depth $maxDepth = $this->getOption('max_depth'); if ($maxDepth !== -1 and $depth > $maxDepth) { return false; } // Render contained items $contents = null; if (count($this->children) == 0) { return ""; } foreach ($this->children as $item) { $contents .= $item->render($depth + 1); } $element = $this->getElement(); if ($element) { $contents = Element::create($element, $contents, $this->attributes)->render(); } return $contents; }
/** * Wrap actions block with potential additional tags * * @param Actions $actions * * @return string A wrapped actions block */ public function wrapActions($actions) { // For horizontal forms, we wrap the actions in a div if ($this->app['former.form']->isOfType('horizontal')) { return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); } return $actions; }
public function testCanCheckIfElementHasChild() { $element = Element::create('div', 'foo'); $this->object->nest($element, 'body'); $this->assertTrue($this->object->hasChild('body')); $this->assertFalse($this->object->hasChild('title')); }
/** * Add a plain image * * @param string $image */ protected function addPlainImage($image) { $image = $this->present($image); // Else just assume we were given an image path if (!String::contains($image, '<img')) { $image = HtmlImage::create($image); } return $this->nest(Element::create('li', $image)->addClass('thumbnail')); }
/** * @return string */ public function render() { $value = $this->choices->all(); if (!empty($this->label)) { $label = Element::create('label', $this->label); $this->nest($label, 'label'); $this->nest('<br>'); } $this->nest($value, 'choices'); return parent::render(); }
/** * Create a button * * @param string $type * * @return Element */ protected function createButton($type) { extract($this->buttons[$type]); return Element::create('button', $text)->class($class); }
/** * Appends a label to the checkbox * * @param string $label * * @return self */ public function text($text) { $this->text = Element::create('label', $text); return $this; }
/** * Render the item * * @param array * * @return string */ public function render($depth = 0) { // Add the active classes $value = is_null($this->beforeContent) ? '' : $this->beforeContent; $value .= $this->value->render(); $value .= is_null($this->afterContent) ? '' : $this->afterContent; $this->addActiveClasses(); // Render children if any if ($this->hasChildren()) { $value .= $this->children->render($depth); } // Facultatively render an element around the item $element = $this->getElement(); if ($element) { $value = Element::create($element, $value, $this->attributes)->render(); } return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); }
/** * Renders a checkable * * @param string|array $item A checkable item * @param integer $fallbackValue A fallback value if none is set * * @return string */ protected function createCheckable($item, $fallbackValue = 1) { // Extract informations extract($item); // Set default values if (!isset($attributes)) { $attributes = array(); } if (isset($attributes['value'])) { $value = $attributes['value']; } if (!isset($value) or $value === $this->app['former']->getOption('unchecked_value')) { $value = $fallbackValue; } // If inline items, add class $isInline = $this->inline ? ' ' . $this->app['former.framework']->getInlineLabelClass($this) : null; // In Bootsrap 3, don't append the the checkable type (radio/checkbox) as a class if // rendering inline. $class = $this->app['former']->framework() == 'TwitterBootstrap3' ? trim($isInline) : $this->checkable . $isInline; // Merge custom attributes with global attributes $attributes = array_merge($this->attributes, $attributes); if (!isset($attributes['id'])) { $attributes['id'] = $name . $this->unique($name); } // Create field $field = Input::create($this->checkable, $name, $value, $attributes); if ($this->isChecked($item, $value)) { $field->checked('checked'); } // Add hidden checkbox if requested if ($this->isOfType('checkbox', 'checkboxes')) { if ($this->isPushed or $this->app['former']->getOption('push_checkboxes') and $this->isPushed !== false) { $field = $this->app['former']->hidden($name)->forceValue($this->app['former']->getOption('unchecked_value')) . $field->render(); // app['former.field'] was overwritten by Former::hidden() call in the line above, so here // we reset it to $this to enable $this->app['former']->getErrors() to retrieve the correct object $this->app->instance('former.field', $this); } } // If no label to wrap, return plain checkable if (!$label) { $element = is_object($field) ? $field->render() : $field; } else { $element = Element::create('label', $field . $label)->for($attributes['id'])->class($class)->render(); } // If BS3, if checkables are stacked, wrap them in a div with the checkable type if (!$isInline && $this->app['former']->framework() == 'TwitterBootstrap3') { $wrapper = Element::create('div', $element)->class($this->checkable); if ($this->getAttribute('disabled')) { $wrapper->addClass('disabled'); } $element = $wrapper->render(); } // Return the field return $element; }
/** * Wrap actions block with potential additional tags * * @param Actions $actions * * @return string A wrapped actions block */ public function wrapActions($actions) { if ($this->app['former.form']->isOfType('horizontal')) { return Element::create('div', $actions)->addClass(array($this->fieldOffset, $this->fieldWidth)); } else { return $actions; } }
/** * Renders a checkable * * @param string|array $item A checkable item * @param integer $fallbackValue A fallback value if none is set * * @return string */ protected function createCheckable($item, $fallbackValue = 1) { // Extract informations extract($item); // Set default values if (!isset($attributes)) { $attributes = array(); } if (isset($attributes['value'])) { $value = $attributes['value']; } if (!isset($value) or $value === $this->app['former']->getOption('unchecked_value')) { $value = $fallbackValue; } // If inline items, add class $isInline = $this->inline ? ' ' . $this->app['former.framework']->getInlineLabelClass($this) : null; // Merge custom attributes with global attributes $attributes = array_merge($this->attributes, $attributes); if (!isset($attributes['id'])) { $attributes['id'] = $name . $this->unique($name); } // Create field $field = Input::create($this->checkable, $name, $value, $attributes); if ($this->isChecked($item, $value)) { $field->checked('checked'); } // Add hidden checkbox if requested if ($this->isOfType('checkbox', 'checkboxes')) { if ($this->isPushed or $this->app['former']->getOption('push_checkboxes') and $this->isPushed !== false) { $field = $this->app['former']->hidden($name)->forceValue($this->app['former']->getOption('unchecked_value')) . $field->render(); } } // If no label to wrap, return plain checkable if (!$label) { return is_object($field) ? $field->render() : $field; } return Element::create('label', $field . $label)->for($attributes['id'])->class($this->checkable . $isInline); }
/** * Wrap a field with potential additional tags * * @param Field $field * * @return Element A wrapped field */ public function wrapField($field) { return Element::create('div', $field)->addClass('controls'); }
/** * Render the input * * @return string */ public function render() { $input = parent::render(); $image = $this->getAttribute('data-thumbnail') == 'true'; $thumbnail = ''; if ($image) { $thumbnail = '<div class="wkm-file-preview"></div>'; } // Browse button $browse = Element::create('div')->addClass('js-browse')->nest('<span class="btn-txt">Browse</span>')->nest($input); // Progress $progress = Element::create('div')->class('js-upload')->style('display: none')->nest('<div class="progress progress-primary">' . '<div class="js-progress bar"></div>' . '</div>' . '<span class="btn-txt">Uploading (<span class="js-size"></span>)</span>'); // Wrapper $wrapper = Element::create('div')->addClass('btn btn-info wkm-file-wrapper')->nest($thumbnail)->nest($browse)->nest($progress); if ($image) { $wrapper = Element::create('div')->class('wkm-file-wrapper--preview')->nest($wrapper); } return $wrapper->render(); }