PodsForm::merge_attributes PHP Method

merge_attributes() public static method

Merge attributes and handle classes
Since: 2.0
public static merge_attributes ( $attributes, $name = null, $type = null, $options = null, $classes = '' )
    public static function merge_attributes($attributes, $name = null, $type = null, $options = null, $classes = '')
    {
        $options = (array) $options;
        if (!in_array($type, array('label', 'comment'))) {
            $name_clean = self::clean($name);
            $name_more_clean = self::clean($name, true);
            $_attributes = array();
            $_attributes['name'] = $name;
            $_attributes['data-name-clean'] = $name_more_clean;
            if (0 < strlen(pods_v('label', $options, ''))) {
                $_attributes['data-label'] = strip_tags(pods_v('label', $options));
            }
            $_attributes['id'] = 'pods-form-ui-' . $name_clean . (self::$form_counter > 1 ? '-' . self::$form_counter : '');
            $_attributes['class'] = 'pods-form-ui-field-type-' . $type . ' pods-form-ui-field-name-' . $name_more_clean;
            if (isset($options['dependency']) && false !== $options['dependency']) {
                $_attributes['class'] .= ' pods-dependent-toggle';
            }
            $attributes = array_merge($_attributes, (array) $attributes);
            if (isset($options['attributes']) && is_array($options['attributes']) && !empty($options['attributes'])) {
                $attributes = array_merge($attributes, $options['attributes']);
            }
        } elseif (isset($options[$type . '_attributes']) && is_array($options[$type . '_attributes']) && !empty($options[$type . '_attributes'])) {
            $attributes = array_merge($attributes, $options[$type . '_attributes']);
        }
        if (isset($options['class']) && !empty($options['class'])) {
            if (is_array($options['class'])) {
                $options['class'] = implode(' ', $options['class']);
            }
            $options['class'] = (string) $options['class'];
            if (isset($attributes['class'])) {
                $attributes['class'] = $attributes['class'] . ' ' . $options['class'];
            } else {
                $attributes['class'] = $options['class'];
            }
            $attributes['class'] = trim($attributes['class']);
        }
        if (!empty($classes)) {
            if (isset($attributes['class'])) {
                $attributes['class'] = $attributes['class'] . ' ' . $classes;
            } else {
                $attributes['class'] = $classes;
            }
        }
        if (isset($options['placeholder']) && !empty($options['placeholder'])) {
            if (is_array($options['placeholder'])) {
                $options['placeholder'] = implode(' ', $options['placeholder']);
            }
            $options['placeholder'] = (string) $options['placeholder'];
            $attributes['placeholder'] = trim($options['placeholder']);
        }
        if (1 == pods_v('required', $options, 0)) {
            $attributes['class'] .= ' pods-validate pods-validate-required';
        }
        $max_length = (int) pods_var('maxlength', $options, pods_v($type . '_max_length', $options, 0), null, true);
        if (0 < $max_length) {
            $attributes['maxlength'] = $max_length;
        }
        $attributes = (array) apply_filters('pods_form_ui_field_' . $type . '_merge_attributes', $attributes, $name, $options);
        return $attributes;
    }

Usage Example

<?php

wp_enqueue_script('pods-codemirror');
wp_enqueue_style('pods-codemirror');
wp_enqueue_script('pods-codemirror-loadmode');
$type = 'textarea';
$attributes = array();
$attributes['tabindex'] = 2;
$attributes = PodsForm::merge_attributes($attributes, $name, $form_field_type, $options, 'pods-ui-field-codemirror');
?>
<div class="code-toolbar"><!-- Placeholder --></div>
<textarea<?php 
PodsForm::attributes($attributes, $name, $form_field_type, $options);
?>
><?php 
echo esc_textarea($value);
?>
</textarea>
<div class="code-footer"><!-- Placeholder --></div>

<script>
    var $textarea_<?php 
echo esc_js(pods_js_name($attributes['id']));
?>
, codemirror_<?php 
echo esc_js(pods_js_name($attributes['id']));
?>
;

    jQuery( function ( $ ) {
        $textarea_<?php 
All Usage Examples Of PodsForm::merge_attributes