Exemplo n.º 1
0
 /**
  * Render an individual option.
  *
  * Should be of the form:
  * <code>
  * array(
  *	 'atts'			=> $atts,
  *	 'value'		=> $value,
  *	 'label'		=> $label,
  *	 'disabled'		=> $boolean,
  *	 'checked'		=> $boolean,
  * )
  * </code>
  *
  * @return string
  * @since 1.0
  */
 public function render_option(array $option, Element $e)
 {
     // The default option arguments.
     $option = array_merge(array('disabled' => false, 'checked' => false, 'value' => NULL, 'atts' => NULL, 'label' => ''), $option);
     /** CheckBox Input ****************************************************/
     // Set the 'checked' attribute.
     if (empty($option['selected']) && !empty($option['value'])) {
         if (in_array($option['value'], (array) $e->get_value())) {
             $option['selected'] = true;
         }
     }
     // Get the Attributes object.
     $option['atts'] = \Nmwdhj\create_atts_obj($option['atts'])->set_atts(array('selected' => (bool) $option['selected'], 'disabled' => (bool) $option['disabled'], 'value' => $option['value']))->set_atts($e->get_atts(), false);
     // Fix the 'name' attribute.
     if ($option['atts']->has_attr('name')) {
         $name = $option['atts']->get_attr('name');
         if (substr($name, -2) !== '[]') {
             $option['atts']->set_attr('name', $name . '[]');
         }
     }
     // The checkbox input output.
     $content = '<input' . strval($option['atts']) . ' />';
     /** CheckBox Label ****************************************************/
     if (!empty($option['label'])) {
         $label_atts = \Nmwdhj\create_atts_obj($e->get_option('label_atts'));
         if (!$label_atts->has_attr('for') && $option['atts']->has_attr('id')) {
             $label_atts->set_attr('for', $option['atts']->get_attr('id'));
         }
         $content = $this->render_label(array('position' => $e->get_option('label_position'), 'label' => $option['label'], 'atts' => $label_atts), $content);
     }
     return $content;
 }
Exemplo n.º 2
0
 /**
  * A helper method to render a custom HTML tag.
  *
  * @return string
  * @since 1.3
  */
 protected function render_tag($tag, $atts, $content)
 {
     if (empty($tag)) {
         return $content;
     }
     $atts = \Nmwdhj\create_atts_obj($atts);
     $content = '<' . $tag . strval($atts) . '>' . $content . '</' . $tag . '>';
     return $content;
 }
Exemplo n.º 3
0
 /**
  * Render an individual option.
  *
  * Should be of the form:
  * <code>
  * array(
  *	 'value'	=> 'value',
  *	 'label'	=> 'label',
  *	 'disabled' => $boolean,
  *	  selected  => $boolean,
  * )
  * </code>
  *
  * @return string
  * @since 1.0
  */
 public function render_option(array $option)
 {
     $option = array_merge(array('value' => '', 'label' => '', 'atts' => array(), 'disabled' => false, 'selected' => false), $option);
     $option['atts'] = \Nmwdhj\create_atts_obj($option['atts'])->set_atts(array('selected' => (bool) $option['selected'], 'disabled' => (bool) $option['disabled'], 'value' => $option['value']));
     return '<option' . strval($option['atts']) . '>' . esc_html($option['label']) . '</option>';
 }