public static function addAttribute($view, $name, $value, $key = 'attr')
    {
        if ($view instanceof BlockView || $view instanceof FormView) {
            $attr = isset($view->vars[$key]) ? $view->vars[$key] : [];

            if (static::isEmpty($value)) {
                unset($attr[$name]);
            } else {
                $attr[$name] = \is_array($value) ? json_encode($value) : $value;
            }

            $view->vars[$key] = $attr;
        }
    }
public static function addAttribute($view, $name, $value, $key = 'attr')
    {
        if ($view instanceof BlockView || $view instanceof FormView) {
            $attr = isset($view->vars[$key]) ? $view->vars[$key] : [];

            if (static::isEmpty($value)) {
                unset($attr[$name]);
            } else {
                $attr[$name] = \is_array($value) ? json_encode($value) : $value;
            }

            $view->vars[$key] = $attr;
        }
    }
public static function addAttribute ( $ view , $ name , $ value , $ key = 'attr' ) { if ( $ view instanceof BlockView || $ view instanceof FormView ) { $ attr = isset ( $ view -> vars [ $ key ] ) ? $ view -> vars [ $ key ] : [ ] ; if ( static :: isEmpty ( $ value ) ) { unset ( $ attr [ $ name ] ) ; } else { $ attr [ $ name ] = \ is_array ( $ value ) ? json_encode ( $ value ) : $ value ; } $ view -> vars [ $ key ] = $ attr ; } }
Add attribute of view.

@param BlockView|FormView $view  The block or form view
@param string             $name  The attribute name
@param string|int|array   $value The attribute value
@param string             $key   The array key of attribute in view vars
Add attribute of view .