Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AttributeHelper.php

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\Template

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal