public static function AttributeHelper::attributeExists in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Template/AttributeHelper.php \Drupal\Core\Template\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.
2 calls to AttributeHelper::attributeExists()
- AttributeHelperTest::testAttributeExists in core/
tests/ Drupal/ Tests/ Core/ Template/ AttributeHelperTest.php - @covers ::attributeExists @dataProvider providerTestAttributeExists
- 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');
}