function AttributeHelper::attributeExists
Checks if the given attribute collection has an attribute.
Parameters
string $name: The name of the attribute to check for.
\Drupal\Core\Template\Attribute|array $collection: An Attribute object or an array of attributes.
Return value
bool TRUE if the attribute exists, FALSE otherwise.
Throws
\InvalidArgumentException When the input $collection is neither an Attribute object nor an array.
1 call to AttributeHelper::attributeExists()
- template_preprocess_image in core/
includes/ theme.inc - Prepares variables for image templates.
File
-
core/
lib/ Drupal/ Core/ Template/ AttributeHelper.php, line 34
Class
- AttributeHelper
- Helper class to deal with mixed array and Attribute operations.
Namespace
Drupal\Core\TemplateCode
public static function attributeExists($name, $collection) {
if ($collection instanceof Attribute) {
return $collection->hasAttribute($name);
}
elseif (is_array($collection)) {
return array_key_exists($name, $collection);
}
throw new \InvalidArgumentException('Invalid collection argument');
}