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;
        }
    }