Collective\Html\HtmlBuilder::attributes PHP Method

attributes() public method

Build an HTML attribute string from an array.
public attributes ( array $attributes ) : string
$attributes array
return string
    public function attributes($attributes)
    {
        $html = [];
        foreach ((array) $attributes as $key => $value) {
            $element = $this->attributeElement($key, $value);
            if (!is_null($element)) {
                $html[] = $element;
            }
        }
        return count($html) > 0 ? ' ' . implode(' ', $html) : '';
    }

Usage Example

 /**
  * Create <div> tag for a reCAPTCHA widget
  *
  * @param  array $options
  *
  * @return string
  */
 public function widget(array $options = [])
 {
     $options['sitekey'] = $this->siteKey;
     if (isset($options['class'])) {
         $options['class'] .= ' ' . $this->recaptchaClass;
     } else {
         $options['class'] = $this->recaptchaClass;
     }
     $this->renameOptions($options);
     return '<div' . $this->html->attributes($options) . '></div>' . PHP_EOL;
 }
All Usage Examples Of Collective\Html\HtmlBuilder::attributes