/** * Wraps two elements, each in a containing element, the wraps the pair in * a third, containing element. The optional attributes are MERGED with the * default attributes, but the default attributes can be set on construct. * @param html $val * @param html $lbl * @param array $args - optional attributes for each of the 3 elements, keyed: 'labelAttributes' => [] 'valueAttributes' => [] 'wrapperAttributes' => [] * */ public function pair($val, $lbl = null, $args = []) { $defaults = ['labelAttributes' => $this->labelAttributes, 'valueAttributes' => $this->valueAttributes, 'wrapperAttributes' => $this->wrapperAttributes]; if (ne_string($args)) { #If just a string, it's the wrapper class $args = ['wrapperAttributes' => ['class' => $args]]; } $labelAttributes = merge_att_arrs('labelAttributes', $defaults, $args); $valueAttributes = merge_att_arrs('valueAttributes', $defaults, $args); $wrapperAttributes = merge_att_arrs('wrapperAttributes', $defaults, $args); $labelTag = keyVal('tag', $labelAttributes, 'div'); unset($labelAttributes['tag']); $wrapTag = keyVal('tag', $wrapperAttributes, 'div'); unset($wrapperAttributes['tag']); $valueTag = keyVal('tag', $valueAttributes, 'div'); unset($valueAttributes['tag']); $pkt = new self(); $pkt->{$labelTag}($lbl, $labelAttributes); $pkt->{$valueTag}($val, $valueAttributes); return $this->fresh()->{$wrapTag}($pkt, $wrapperAttributes); }
/** The BS Column Class (if any) should is a separate param, 'wrapperColClass' * Default is 'col-xs-2', but any 'wrapperColClass' will replace it, including * if the key exists but is empty. * * @param type $inp * @param type $lbl * @param array|string $args - if string, the BS Col Class * @return type */ public function pair($inp, $lbl = null, $args = []) { $defaults = ['labelAttributes' => $this->labelAttributes, 'valueAttributes' => $this->valueAttributes, 'wrapperAttributes' => $this->wrapperAttributes]; if (is_array($args) && array_key_exists('wrapperColClass', $args)) { $wrapperColClass = $args['wrapperColClass']; } else { if (!is_array($args)) { #Default is [], so explicitly set, also to null. $wrapperColClass = $args; } else { $wrapperColClass = $this->defaultColClass; } } return PkRenderer::rawwrap(['value' => $inp, 'label' => $lbl, 'labelAttributes' => merge_att_arrs('labelAttributes', $defaults, $args), 'valueAttributes' => merge_att_arrs('valueAttributes', $defaults, $args), 'wrapperAttributes' => merge_attributes(merge_att_arrs('wrapperAttributes', $defaults, $args), $wrapperColClass)]); }