/** * Here are non standard Form macros */ use Collective\Html\FormFacade as Form; /** * Creates a radio button input fields from given array of values. * * @param string $name * @param mixed $values Array [value => label] or null for default * @param mixed $checked Value from $values to be checked as default * @param array $options Options passed to every radio button * @return string */ Form::macro('radioSwitch', function ($name, $values = null, $checked = null, $options = array()) { if (is_null($values)) { $values = [1 => transpine('helpers.yes'), 0 => transpine('helpers.no')]; $checked = is_null($checked) ? null : (int) $checked; } if (is_null($checked)) { $checked = array_keys($values)[0]; } $html = '<p class="field switch">'; foreach ($values as $value => $label) { $options['id'] = $name . $value . microtime(); $html .= Form::radio($name, $value, $checked === $value, $options); $labelClass = $value == 0 ? 'cb-disable' : 'cb-enable'; $labelClass .= $checked === $value ? ' selected' : ''; $html .= Form::label($options['id'], $label, ['class' => $labelClass]); } $html .= '</p>'; return $html;
}); /** * Generate menu element with localized label * * @param string $elementName * @param array $parameters * @param array $attributes* * @return string */ Html::macro('link_menu_translated', function ($elementName, array $parameters = array(), array $attributes = array()) { $label = trans(spine_config('spine.link_menu.lang_filename', 'menu') . '.' . $elementName); return Html::link_menu($elementName, $label, $parameters, $attributes); }); /** * Get yes|no localized string based on boolean representation of given value * * @param bool $value * @return string */ Html::macro('print_bool', function ($value) { return (bool) $value ? transpine('helpers.yes') : transpine('helpers.no'); }); /** * Get html for iconic (visual) version of boolean value * * @param bool $value * @return string */ Html::macro('visual_bool', function ($value) { return '<i class="fa ' . ((bool) $value ? 'fa-check-square-o done' : 'fa-square-o') . '"></i>'; });